NCBI C++ ToolKit
compound_id_impl.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef CONNECT_SERVICES__COMPOUND_ID_IMPL__HPP
2 #define CONNECT_SERVICES__COMPOUND_ID_IMPL__HPP
3 
4 /* $Id: compound_id_impl.hpp 59949 2013-09-27 16:05:05Z kazimird $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Dmitry Kazimirov
30  *
31  * File Description:
32  * Compound IDs are Base64-encoded string that contain application-specific
33  * information to identify and/or locate objects.
34  *
35  */
36 
37 /// @file compound_id_impl.hpp
38 /// Internal declarations of the CompoundID classes.
39 
41 
42 #include <util/random_gen.hpp>
43 
44 #include <corelib/ncbimtx.hpp>
45 
47 
49 {
52 };
53 
55 {
56 };
57 
59 {
60 };
61 
62 struct SCompoundIDFieldImpl : public CObject,
64 {
65  virtual void DeleteThis();
66 
68 
70 
71  union {
75  struct {
80 
82  };
83  string m_StringValue;
85 };
86 
87 template <typename Link>
88 struct SFieldList
89 {
90  void Clear()
91  {
92  m_Tail = m_Head = NULL;
93  }
94 
95  bool IsEmpty() const {return m_Head == NULL;}
96 
97  static Link* GetLink(SCompoundIDFieldImpl* entry)
98  {
99  return static_cast<Link*>(entry);
100  }
101 
103  {
104  return GetLink(entry)->m_Prev;
105  }
106 
108  {
109  return GetLink(entry)->m_Next;
110  }
111 
113  {
114  GetLink(entry)->m_Prev = prev;
115  }
116 
118  {
119  GetLink(entry)->m_Next = next;
120  }
121 
122  void Append(SCompoundIDFieldImpl* new_entry)
123  {
124  SetNext(new_entry, NULL);
125  SetPrev(new_entry, m_Tail);
126  if (m_Tail != NULL)
127  SetNext(m_Tail, new_entry);
128  else
129  m_Head = new_entry;
130  m_Tail = new_entry;
131  }
132 
134  {
135  if (GetPrev(entry) == NULL)
136  if ((m_Head = GetNext(entry)) == NULL)
137  m_Tail = NULL;
138  else
139  SetPrev(GetNext(entry), NULL);
140  else if (GetNext(entry) == NULL)
141  SetNext(m_Tail = GetPrev(entry), NULL);
142  else {
143  SetNext(GetPrev(entry), GetNext(entry));
144  SetPrev(GetNext(entry), GetPrev(entry));
145  }
146  }
147 
150 };
151 
154 
155 struct SCompoundIDImpl : public CObject
156 {
158  {
159  m_Class = id_class;
160  m_Pool = pool;
161  m_Length = 0;
162  m_Dirty = true;
163  m_FieldList.Clear();
164  for (unsigned i = 0; i < eCIT_NumberOfTypes; ++i)
165  m_HomogeneousFields[i].Clear();
166  }
167 
168  void Remove(SCompoundIDFieldImpl* field);
169 
170  string PackV0();
171 
173 
174  virtual void DeleteThis();
175 
177 
180 
181  unsigned m_Length;
182 
185 
186  string m_PackedID;
187  bool m_Dirty;
188 };
189 
190 template <typename Poolable, typename FieldTypeOrIDClass>
192 {
194  {
195  }
196 
198  Poolable* m_Head;
199 
200  Poolable* Alloc()
201  {
202  CFastMutexGuard guard(m_Mutex);
203 
204  if (m_Head == NULL)
205  return new Poolable;
206  else {
207  Poolable* element = m_Head;
208  m_Head = element->m_NextObjectInPool;
209  return element;
210  }
211  }
212 
213  void ReturnToPool(Poolable* element)
214  {
215  CFastMutexGuard guard(m_Mutex);
216 
217  element->m_NextObjectInPool = m_Head;
218  m_Head = element;
219  }
220 
222  {
223  Poolable* element = m_Head;
224  while (element != NULL) {
225  Poolable* next_element = element->m_NextObjectInPool;
226  delete element;
227  element = next_element;
228  }
229  }
230 
231 };
232 
234 {
236  {
238  return m_RandomGen.GetRand();
239  }
240 
241  CCompoundID UnpackV0(const string& packed_id);
242 
248 };
249 
251 {
252  m_FieldList.Remove(field);
253  m_HomogeneousFields[field->m_Type].Remove(field);
255  --m_Length;
256  m_Dirty = true;
257 }
258 
259 extern void g_PackID(void* binary_id, size_t binary_id_len, string& packed_id);
260 
261 extern bool g_UnpackID(const string& packed_id, string& binary_id);
262 
264 
265 #endif /* CONNECT_SERVICES__COMPOUND_ID_IMPL__HPP */
Pool of recycled CCompoundID objects.
Base64-encoded ID string that contains extractable typed fields.
CFastMutex –.
Definition: ncbimtx.hpp:667
CObject –.
Definition: ncbiobj.hpp:180
CRandom::
Definition: random_gen.hpp:66
Declarations of CCompoundIDPool, CCompoundID, and CCompoundIDField.
ECompoundIDFieldType
Definition: compound_id.hpp:62
@ eCIT_NumberOfTypes
Definition: compound_id.hpp:83
ECompoundIDClass
Definition: compound_id.hpp:50
void g_PackID(void *binary_id, size_t binary_id_len, string &packed_id)
SFieldList< SSameTypeListLink > THomogeneousFieldList
bool g_UnpackID(const string &packed_id, string &binary_id)
SFieldList< SNeighborListLink > TFieldList
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:61
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:56
#define NULL
Definition: ncbistd.hpp:225
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
uint16_t Uint2
2-byte (16-bit) unsigned integer
Definition: ncbitype.h:101
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
TValue GetRand(void)
Get the next random number in the interval [0..GetMax()] (inclusive)
Definition: random_gen.hpp:238
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
int i
Multi-threading – mutexes; rw-locks; semaphore.
ECompoundIDFieldType m_Type
struct SCompoundIDFieldImpl::@1006::@1008 m_IPv4SockAddr
SCompoundIDFieldImpl * m_NextObjectInPool
virtual void DeleteThis()
Virtual method "deleting" this object.
void Reset(SCompoundIDPoolImpl *pool, ECompoundIDClass id_class)
virtual void DeleteThis()
Virtual method "deleting" this object.
void Remove(SCompoundIDFieldImpl *field)
THomogeneousFieldList m_HomogeneousFields[eCIT_NumberOfTypes]
SCompoundIDFieldImpl * AppendField(ECompoundIDFieldType field_type)
ECompoundIDClass m_Class
CCompoundIDPool m_Pool
SCompoundIDImpl * m_NextObjectInPool
void ReturnToPool(Poolable *element)
SCompoundIDObjectPool< SCompoundIDImpl, ECompoundIDClass > m_CompoundIDPool
CCompoundID UnpackV0(const string &packed_id)
SCompoundIDObjectPool< SCompoundIDFieldImpl, ECompoundIDFieldType > m_FieldPool
void Remove(SCompoundIDFieldImpl *entry)
static void SetPrev(SCompoundIDFieldImpl *entry, SCompoundIDFieldImpl *prev)
static void SetNext(SCompoundIDFieldImpl *entry, SCompoundIDFieldImpl *next)
SCompoundIDFieldImpl * m_Tail
static SCompoundIDFieldImpl * GetPrev(SCompoundIDFieldImpl *entry)
void Append(SCompoundIDFieldImpl *new_entry)
bool IsEmpty() const
SCompoundIDFieldImpl * m_Head
static SCompoundIDFieldImpl * GetNext(SCompoundIDFieldImpl *entry)
static Link * GetLink(SCompoundIDFieldImpl *entry)
Modified on Fri Sep 20 14:58:13 2024 by modify_doxy.py rev. 669887