Gaudi Framework, version v25r2

Home   Generated: Wed Jun 4 2014
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
KeyedObject.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_KEYEDOBJECT_H
2 #define GAUDIKERNEL_KEYEDOBJECT_H
3 
4 namespace GaudiDict {
5  template <class T> struct KeyedObjectDict;
6 }
7 
8 // Framework include files
12 
27 template < class KEY >
29  friend struct GaudiDict::KeyedObjectDict<KEY>;
30 public:
32  typedef KEY key_type;
33 
34 protected:
38 //#ifdef _WIN32
39 // friend traits;
40 //#else
42 //#endif
43 
47  long m_refCount;
49  bool m_hasKey;
51  unsigned long addRef();
53  unsigned long release();
58  void setKey(const key_type& key);
59 public:
61  KeyedObject(): m_key(), m_refCount(0), m_hasKey(false) { }
65  KeyedObject(const key_type& kval):m_key(kval),m_refCount(0),m_hasKey(true) { }
67  virtual ~KeyedObject();
69  const key_type& key() const { return m_key; }
71  bool hasKey() const { return m_hasKey; }
72  virtual long index() const { return traits::identifier(m_key); }
74  virtual StreamBuffer& serialize( StreamBuffer& s ) const;
76  virtual StreamBuffer& serialize( StreamBuffer& s );
77 private:
79  KeyedObject(const KeyedObject& copy) : ContainedObject(copy), m_refCount(0), m_hasKey(true) { }
80 };
81 
82 /*
83  *
84  *
85  * Inline code for keyed KeyedObject class
86  *
87  */
88 
89 // Standard destructor.
90 template<class KEY> inline
92 {
93  ObjectContainerBase* p = const_cast<ObjectContainerBase*>(parent());
94  if ( p ) {
95  setParent(0);
96  p->remove(this);
97  }
98 }
99 
100 // Add reference to object (Increase reference counter).
101 template<class KEY> inline
102 unsigned long KeyedObject<KEY>::addRef() {
103  return ++m_refCount;
104 }
105 
106 // Release reference. If the reference count is ZERO, delete the object.
107 template<class KEY> inline
108 unsigned long KeyedObject<KEY>::release() {
109  long cnt = --m_refCount;
110  if ( cnt <= 0 ) {
111  delete this;
112  }
113  return cnt;
114 }
115 
116 /* Set object key. The key for consistency reasons
117  can be set only once for the object. Any attempt to
118  redefine the key results in an exception.
119 */
120 template<class KEY> inline
122  if ( !m_hasKey ) {
123  m_key = key;
124  m_hasKey = true;
125  return;
126  }
128 }
129 
130 // Serialize the object for writing
131 template<class KEY> inline
134 }
135 
136 // Serialize the object for reading
137 template<class KEY> inline
139  long k;
141  m_key = traits::makeKey(k);
142  m_hasKey = true;
143  return s;
144 }
145 #endif // GAUDIKERNEL_KEYEDOBJECT_H

Generated at Wed Jun 4 2014 14:48:57 for Gaudi Framework, version v25r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004