RefCountedObject.h
1 //##################################################################################################
2 //
3 // Ceetron Desktop Components
4 // Component: Core
5 //
6 // --------------------------------------------------------------------------------------------
7 // Copyright (C) 2011, Ceetron AS
8 // This is UNPUBLISHED PROPRIETARY SOURCE CODE of Ceetron AS. The contents of this file may
9 // not be disclosed to third parties, copied or duplicated in any form, in whole or in part,
10 // without the prior written permission of Ceetron AS.
11 //##################################################################################################
12 
13 #pragma once
14 
15 #include "CeeCore/Base.h"
16 #include "CeeCore/AtomicCounter.h"
17 
18 #if defined(CEE_ATOMIC_COUNTER_CLASS_EXISTS) && defined(CEE_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS)
19 #error Two mutually exclusive defines detected : CEE_ATOMIC_COUNTER_CLASS_EXISTS && CEE_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS
20 #endif
21 
22 #if !defined(CEE_ATOMIC_COUNTER_CLASS_EXISTS) && !defined(CEE_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS)
23 #error No support for atomics. Define CEE_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS to be able to compile
24 #endif
25 
26 namespace cee {
27 
28 
29 //==================================================================================================
30 //
31 // Base class for all reference counted objects
32 //
33 //==================================================================================================
34 class CEE_CORE_EXPORT RefCountedObject
35 {
36 public:
38  virtual ~RefCountedObject();
39 
40  void addRef() const;
41  void release() const;
42  int refCount() const;
43 
44  void setRefCountZero() const;
45 
46 private:
47 #if defined(CEE_ATOMIC_COUNTER_CLASS_EXISTS)
48  mutable AtomicCounter m_refCount;
49 #elif defined(CEE_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS)
50  mutable int m_refCount;
51 #endif
52 
53  CEE_DISALLOW_COPY_AND_ASSIGN(RefCountedObject);
54 };
55 
56 }
Namespace cee contains all functionality and structures under the Core component. ...
Definition: AppAssert.cpp:18
Base class for all reference counted objects with built-in support for intrusive reference counting...
Definition: RefCountedObject.h:34