openATV enigma2
openATV is an open source SetTopBox Graphical user interface.
object.h
Go to the documentation of this file.
1 #ifndef __base_object_h
2 #define __base_object_h
3 
4 #include <ext/atomicity.h>
5 
6 #include <assert.h>
7 #include <lib/base/smartptr.h>
8 #include <lib/base/elock.h>
9 
10 #include <lib/base/eerror.h>
11 
12 typedef int RESULT;
13 
14 class iObject
15 {
16 private:
17  /* we don't allow the default operator here, as it would break the refcount. */
18  void operator=(const iObject &);
19 protected:
20  virtual ~iObject() { }
21 #ifdef SWIG
22  virtual void AddRef()=0;
23  virtual void Release()=0;
24 #endif
25 public:
26  void operator delete(void *p) { ::operator delete(p); }
27 #ifndef SWIG
28  virtual void AddRef()=0;
29  virtual void Release()=0;
30 #endif
31 };
32 
33 #ifndef SWIG
34 
35 class oRefCount
36 {
37  mutable _Atomic_word ref;
38 public:
39  oRefCount(): ref(0) {}
40 
41  int operator++()
42  {
43  return __gnu_cxx::__exchange_and_add(&ref, 1) + 1;
44  }
45 
46  int operator--()
47  {
48  return __gnu_cxx::__exchange_and_add(&ref, -1) - 1;
49  }
50 
51  operator int() const
52  {
53  return __gnu_cxx::__exchange_and_add(&ref, 0);
54  }
55 };
56 
57  #define DECLARE_REF(x) \
58  public: \
59  void AddRef(); \
60  void Release(); \
61  private:\
62  oRefCount ref;
63 
64  #define DEFINE_REF(c) \
65  void c::AddRef() \
66  { \
67  ++ref; \
68  } \
69  void c::Release() \
70  { \
71  if (!(--ref)) \
72  delete this; \
73  }
74 
75 #else // SWIG
76  #define DECLARE_REF(x) \
77  private: \
78  void AddRef(); \
79  void Release();
80 #endif // SWIG
81 
82 #endif // __base_object_h
Definition: object.h:15
virtual void Release()=0
virtual void AddRef()=0
virtual ~iObject()
Definition: object.h:20
Definition: object.h:36
oRefCount()
Definition: object.h:39
int operator++()
Definition: object.h:41
int operator--()
Definition: object.h:46
p
Definition: upgrade.py:63
int RESULT
Definition: object.h:12