Guiliani  Version 2.6 revision 7293 (documentation build 12)
RefCounted.h
1/*
2* Copyright (C) TES Electronic Solutions GmbH,
3* All Rights Reserved.
4* Contact: info@guiliani.de
5*
6* This file is part of the Guiliani HMI framework
7* for the development of graphical user interfaces on embedded systems.
8*/
9
10#ifndef REF_COUNTED_H
11#define REF_COUNTED_H
12
13#include "eC_Types.h"
14#include "GUITrace.h"
15#include "eC_Atomic.h"
16
17
19namespace NSmartPtr
20{
21
32{
33public:
36 : m_iRefCount(0)
37 {
38 }
39
41 virtual ~RefCounted()
42 {
43 if (m_iRefCount != 0)
44 GUILOG(GUI_TRACE_WARNING, "RefCounted::~RefCounted: reference count not 0.");
45 }
46
48 inline void AddRef()
49 {
50 eC_Atomic::increment(&m_iRefCount);
51 }
52
58 inline void Release()
59 {
60 eC_Int newCount = eC_Atomic::decrement(&m_iRefCount);
61 if (newCount == 0)
62 {
63 delete this;
64 }
65 }
66
76 inline bool Unique() const { return (m_iRefCount == 1); }
77
86 inline eC_Int RefCount() const { return static_cast<eC_Int const volatile &>(m_iRefCount); }
87
88private:
89 mutable eC_Int m_iRefCount;
90}; // class RefCounted
91
92} // namespace NSmartPtr
93
94#endif // REF_COUNTED_PTR_H
The reference counted pointer class used with SharedPtr.
Definition: RefCounted.h:32
bool Unique() const
Definition: RefCounted.h:76
void AddRef()
Increase reference count.
Definition: RefCounted.h:48
eC_Int RefCount() const
Definition: RefCounted.h:86
void Release()
Definition: RefCounted.h:58
virtual ~RefCounted()
Destroy reference counted object.
Definition: RefCounted.h:41
RefCounted()
Create RefCounted object. The reference count is initialized to 0.
Definition: RefCounted.h:35
Contains pointer class templates.
Definition: GUIRefCntPtr.h:17