All Classes Functions Variables Typedefs Friends Pages
Common.h
1 //------------------------------------------------------------------------------
2 //
3 // Copyright (c) 2012 Glympse Inc. All rights reserved.
4 //
5 //------------------------------------------------------------------------------
6 
7 #ifndef COMMON_H__GLYMPSE__
8 #define COMMON_H__GLYMPSE__
9 
10 namespace Glympse
11 {
12 
18 template< class T >
19 class Common
20  : public T
21  , public virtual CommonStorage
22 {
28  protected: Common()
29  : CommonStorage()
30  {
31  }
32 
37  protected: virtual ~Common()
38  {
39  }
40 
44  public: virtual int32 retain()
45  {
46  return Concurrent::increment((int32*)&_ref);
47  }
48 
52  public: virtual int32 release()
53  {
54  int32 result = Concurrent::decrement((int32*)&_ref);
55  if ( 0 == result )
56  {
57  if ( 0 != _holders )
58  {
59  _attachedObject = NULL;
60  }
61  else
62  {
63  delete this;
64  }
65  }
66  return result;
67  }
68 
72  public: virtual int32 hold()
73  {
74  return Concurrent::increment((int32*)&_holders);
75  }
76 
80  public: virtual int32 unhold()
81  {
82  int32 result = Concurrent::decrement((int32*)&_holders);
83  if ( ( 0 == result ) && ( 0 == _ref ) )
84  {
85  delete this;
86  }
87  return result;
88  }
89 
93  public: virtual int32 hashCode()
94  {
95  return hashCode((int64)this);
96  }
97 
101  public: virtual bool equals(const GCommonObj& o)
102  {
103  return ( this == o._object );
104  }
105 
109  public: virtual GString toString();
110 
114  public: static inline int32 hashCode(int64 value)
115  {
116  return ((int32)(value ^ (value >> 32)));
117  }
118 
119  public: virtual void attachObject(const GCommon& obj)
120  {
121  CommonStorage::attachObject(obj);
122  }
123 
124  public: virtual GCommon extractObject()
125  {
126  return CommonStorage::extractObject();
127  }
128 };
129 
130 }
131 
132 #endif // !COMMON_H__GLYMPSE__