Skip to content

Add ReferenceCounter::GetRefCount() method - #1512

Merged
kmdewaal merged 3 commits into
MythTV:masterfrom
SteveErl:erlMerge52
Nov 7, 2026
Merged

kmdewaal merged 3 commits into
MythTV:masterfrom
SteveErl:erlMerge52

Conversation

@SteveErl

@SteveErl SteveErl commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

This adds a new GetRefCount() method to the ReferenceCounter class which will allow the integer count value to be retrieved. Use of this new method in LoadImage() provides simpler, more efficient code.

Resolves #1511

Checklist

This adds a new method to the ReferenceCounter class
which will allow the integer count value to be
retrieved. Use of this new method in LoadImage()
provides simpler, more efficient code.

Resolves MythTV#1511
@BobEntwhistle

Copy link
Copy Markdown
Contributor

@SteveErl Two small things on the new method:

int GetRefCount(void) { return static_cast<int>(m_referenceCount); };

The coding standards ask that a Get method be const, and this one can be:
QAtomicInt::operator int() is const. There is also a stray ; after the closing brace.

@SteveErl

Copy link
Copy Markdown
Contributor Author

@BobEntwhistle I tried adding in const, but the compiler tells me that it will be ignored.
referencecounter.h:41:5: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
My return type is an int derived from the QAtomicInt class member, not the QAtomicInt itself. I could do ...
const QAtomicInt GetRefCount(void) { return m_referenceCount; }
but I really just want the integer value of the reference count to be easily accessible. I wouldn't want callers to GetRefCount() to have to apply static_cast<int> to the return value. It's better to do that work once in this new method.

An unnecessary ';' was left at the end of the
new methode. This has been stripped.

Resolves: MythTV#1511
@kmdewaal kmdewaal self-assigned this Nov 6, 2026
@kmdewaal

kmdewaal commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@BobEntwhistle as I understand it, the static_cast does trigger the internal QAtomicInt::operator int() const which means that the code as proposed does already do exactly what you want, i.e. be const. However, it is not explicit.
@SteveErl the function can be made more explicit const by adding const like this:
int GetRefCount(void) const { return static_cast<int>(m_referenceCount); }
This has no effect at all, but now you cannot modify the code anymore so that it changes m_referenceCount.

@SteveErl

SteveErl commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

@kmdewaal Your suggestion sounds good to me. I'll make it more explicitly const.

This update adds a 'const' keyword to make it
more clear that no changes to m_referenceCount
will be made by calling this new routine.

Resolves MythTV#1511
@kmdewaal
kmdewaal merged commit c3b5eac into MythTV:master Nov 7, 2026
6 of 10 checks passed
@SteveErl
SteveErl deleted the erlMerge52 branch November 7, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReferenceCounter lacks method to retrieve count

3 participants