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

Go to the SVN repository for this file.

1 #ifndef BDB___BV_PROPERTY_STORE__HPP
2 #define BDB___BV_PROPERTY_STORE__HPP
3 
4 /* $Id: bdb_bv_property_store.hpp 42205 2009-06-15 15:40:12Z ivanovp $
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: Mike DiCuccio
30  *
31  * File Description:
32  *
33  */
34 
35 
37 #include <db/bdb/bdb_types.hpp>
38 
39 
41 
42 
43 //////////////////////////////////////////////////////////////////////////////
44 
45 template <class PropKey, class PropValue>
47 {
48 public:
49  typedef pair<PropKey, PropValue> TKey;
50  typedef Uint4 TKeyId;
51 
53 
54  /// @name Interface required for split dictionary store
55  /// @{
56 
57  Uint4 GetKey(const TKey& key);
58  Uint4 PutKey(const TKey& key);
59 
60  /// @}
61 
62  TKey GetCurrentKey() const;
63  TKeyId GetCurrentUid() const;
64  TKeyId GetMaxUid() const;
65 
66  EBDB_ErrCode Read(TKeyId* key_idx);
67  EBDB_ErrCode Read(const TKey& key, TKeyId* key_idx);
68  EBDB_ErrCode Read(const PropKey& prop, const PropValue& value,
69  TKeyId* key_idx);
70  EBDB_ErrCode Write(const TKey& key, TKeyId key_idx);
71  EBDB_ErrCode Write(const PropKey& prop,
72  const PropValue& value,
73  TKeyId key_idx);
74 
75 protected:
77 
78 private:
82 
83 private:
84  /// forbidden
87 };
88 
89 
90 
91 //////////////////////////////////////////////////////////////////////////////
92 
93 template <typename PropKey, typename PropValue,
95  typename BvStore = CBDB_PersistentSplitStore< bm::bvector<> >,
96  typename BV = bm::bvector<>
97  >
99  : public CBDB_BvSplitDictStore< pair<PropKey, PropValue>,
100  Dictionary, BvStore, BV >
101 {
102 public:
104  Dictionary, BvStore, BV > TParent;
105  typedef pair<PropKey, PropValue> TKey;
107  typedef BvStore TStore;
108  typedef BV TBitVector;
109  typedef Uint4 TKeyId;
110 
111  CBDB_BvPropertyStore(const string& demux_path = kEmptyStr);
113  EOwnership own = eTakeOwnership);
114 
115 private:
116  /// forbidden
119 };
120 
121 
122 /////////////////////////////////////////////////////////////////////////////
123 
124 
125 template <class PropKey, class PropValue>
126 inline
128  : m_MaxUid(0)
129 {
130  BindKey ("key", &m_PropKey);
131  BindKey ("val", &m_PropVal);
132  BindData("uid", &m_Uid);
133 }
134 
135 
136 template <class PropKey, class PropValue>
137 inline
140 {
141  TKey key((PropKey)m_PropKey, (PropValue)m_PropVal);
142  return key;
143 }
144 
145 
146 template <class PropKey, class PropValue>
147 inline
150 {
151  return (TKeyId)m_Uid;
152 }
153 
154 
155 template <class PropKey, class PropValue>
156 inline
159 {
160  return m_MaxUid;
161 }
162 
163 
164 template <class PropKey, class PropValue>
165 inline
167 {
168  TKeyId uid = 0;
169  Read(key.first, key.second, &uid);
170  return uid;
171 }
172 
173 
174 template <class PropKey, class PropValue>
175 inline
177 {
178  Uint4 uid = GetKey(key);
179  if (uid) {
180  _ASSERT(uid <= m_MaxUid);
181  return uid;
182  }
183 
184  ++m_MaxUid;
185  uid = m_MaxUid;
186  if (uid) {
187  if (Write(key, uid) != eBDB_Ok) {
188  uid = 0;
189  }
190  }
191  return uid;
192 }
193 
194 
195 template <class PropKey, class PropValue>
196 inline EBDB_ErrCode
198 {
199  EBDB_ErrCode err = Fetch();
200  if (err == eBDB_Ok && key_idx) {
201  *key_idx = m_Uid;
202  m_MaxUid = max(m_MaxUid, *key_idx);
203  }
204  return err;
205 }
206 
207 
208 template <class PropKey, class PropValue>
209 inline EBDB_ErrCode
211  TKeyId* key_idx)
212 {
213  m_PropKey = key.first;
214  m_PropVal = key.second;
215  return Read(key_idx);
216 }
217 
218 
219 template <class PropKey, class PropValue>
220 inline EBDB_ErrCode
222  const PropValue& value,
223  TKeyId* key_idx)
224 {
225  m_PropKey = prop;
226  m_PropVal = value;
227  return Read(key_idx);
228 }
229 
230 
231 template <class PropKey, class PropValue>
232 inline EBDB_ErrCode
234  TKeyId key_idx)
235 {
236  m_PropKey = key.first;
237  m_PropVal = key.second;
238  m_Uid = key_idx;
239  m_MaxUid = max(m_MaxUid, key_idx);
240  return UpdateInsert();
241 }
242 
243 
244 template <class PropKey, class PropValue>
245 inline EBDB_ErrCode
247  const PropValue& value,
248  TKeyId key_idx)
249 {
250  m_PropKey = prop;
251  m_PropVal = value;
252  m_Uid = key_idx;
253  m_MaxUid = max(m_MaxUid, key_idx);
254  return UpdateInsert();
255 }
256 
257 
258 /////////////////////////////////////////////////////////////////////////////
259 
260 template <typename PropKey, typename PropValue,
261  typename Dictionary, typename BvStore, typename BV>
263 ::CBDB_BvPropertyStore(const string& demux_path)
264 : TParent(demux_path)
265 {
266 }
267 
268 
269 template <typename PropKey, typename PropValue,
270  typename Dictionary, typename BvStore, typename BV>
273  TStore& store,
274  EOwnership own)
275 : TParent(dict, store, own)
276 {
277 }
278 
279 
281 
282 #endif // BDB___BV_PROPERTY_STORE__HPP
CBDB_BvPropertyStore(const string &demux_path=kEmptyStr)
CBDB_BvPropertyStore(const CBDB_BvPropertyStore< PropKey, PropValue, Dictionary, BvStore, BV > &)
forbidden
CBDB_BvPropertyStore & operator=(const CBDB_BvPropertyStore< PropKey, PropValue, Dictionary, BvStore, BV > &)
CBDB_BvSplitDictStore< pair< PropKey, PropValue >, Dictionary, BvStore, BV > TParent
pair< PropKey, PropValue > TKey
Berkeley DB file class.
Definition: bdb_file.hpp:445
EBDB_ErrCode Write(const TKey &key, TKeyId key_idx)
EBDB_ErrCode Read(TKeyId *key_idx)
SBDB_TypeTraits< TKeyId >::TFieldType m_Uid
Uint4 GetKey(const TKey &key)
CBDB_PropertyDictionary & operator=(const CBDB_PropertyDictionary< PropKey, PropValue > &)
SBDB_TypeTraits< PropKey >::TFieldType m_PropKey
pair< PropKey, PropValue > TKey
CBDB_PropertyDictionary(const CBDB_PropertyDictionary< PropKey, PropValue > &)
forbidden
Uint4 PutKey(const TKey &key)
SBDB_TypeTraits< PropValue >::TFieldType m_PropVal
@ eTakeOwnership
An object can take ownership of another.
Definition: ncbi_types.h:136
void BindKey(const char *field_name, CBDB_Field *key_field, size_t buf_size=0)
Definition: bdb_file.cpp:1281
void BindData(const char *field_name, CBDB_Field *data_field, size_t buf_size=0, ENullable is_null=eNullable)
Definition: bdb_file.cpp:1296
EBDB_ErrCode
BDB Return codes.
Definition: bdb_file.hpp:57
@ eBDB_Ok
Definition: bdb_file.hpp:58
void Read(CObjectIStream &in, TObjectPtr object, const CTypeRef &type)
Definition: serial.cpp:60
void Write(CObjectOStream &out, TConstObjectPtr object, const CTypeRef &type)
Definition: serial.cpp:55
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
enum ENcbiOwnership EOwnership
Ownership relations between objects.
const struct ncbi::grid::netcache::search::fields::KEY key
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
T max(T x_, T y_)
static CSafeStatic< map< string, string > > Dictionary
Definition: spell_check.cpp:84
Type trait classes for finding the correct BDB field type automagically.
Definition: bdb_types.hpp:2009
#define _ASSERT
Modified on Mon Jun 24 05:25:39 2024 by modify_doxy.py rev. 669887