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

Go to the SVN repository for this file.

1 /* $Id: Object_id.hpp 96849 2022-05-18 13:42:36Z ucko $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: .......
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using specifications from the ASN data definition file
34  * 'general.asn'.
35  */
36 
37 #ifndef OBJECTS_GENERAL_OBJECT_ID_HPP
38 #define OBJECTS_GENERAL_OBJECT_ID_HPP
39 
40 
41 // generated includes
43 
44 // generated classes
45 
46 #include <serial/objhook.hpp>
47 #include <map>
48 
50 
51 BEGIN_objects_SCOPE // namespace ncbi::objects::
52 
54 {
56 public:
57  // constructor
58  CObject_id(void);
59  // destructor
60  ~CObject_id(void);
61 
62  // matching id? (int-string)
63  bool Match(const CObject_id& oid2) const;
64  // Set this id to me matching to the argument
65  // return false if there is no matching id
66  // @sa SetStrOrId()
67  // @sa GetIdType()
68  bool SetAsMatchingTo(const CObject_id& oid2);
69 
70  // identical ids?
71  int Compare(const CObject_id& oid2) const;
72  bool operator<(const CObject_id& id2) const;
73 
74  // Try to interpret the Object-id as integer.
75  // Returns:
76  // e_not_set if the Object-id is not set
77  // e_Id if the Object-id is an integer or a string with valid integer in a canonical form
78  // e_Str if the Object-id as a string without valid integer
79  // If the result is e_Id the integer id will be returned by Int8 value,
80  // otherwise the value will be set to 0.
81  // @sa SetStrOrId()
82  // @sa SetAsMatchingTo()
83  typedef Int8 TId8;
84  E_Choice GetIdType(TId8& value) const;
85 
86  bool IsId8(void) const;
87  TId8 GetId8(void) const;
88  NCBI_WARN_UNUSED_RESULT bool GetId8(TId8& value) const;
89  void SetId8(TId8 value);
90 
91  bool IsGi(void) const;
92  TGi GetGi(void) const;
93  NCBI_WARN_UNUSED_RESULT bool GetGi(TGi& value) const;
94  void SetGi(TGi value);
95 #ifdef NCBI_STRICT_GI
96  void SetGi(TIntId value);
97  NCBI_WARN_UNUSED_RESULT bool GetGi(TIntId& value) const;
98 #endif
99 
100  // Set integer id part if the argument is a positive integer without leading zeros
101  // otherwise set str part.
102  // @sa SetAsMatchingTo()
103  // @sa GetIdType()
104  void SetStrOrId(CTempString str);
105 
106  // format contents into a stream
107  ostream& AsString(ostream &s) const;
108 private:
109  // Prohibit copy constructor & assignment operator
112 };
113 
114 
115 
116 /////////////////// CObject_id inline methods
117 
118 // constructor
119 inline
121 {
122 }
123 
124 
125 inline
126 bool CObject_id::operator<(const CObject_id& id2) const
127 {
128  return Compare(id2) < 0;
129 }
130 
131 
133 inline
135 {
136  return GetIdType(value) == e_Id;
137 }
138 
139 
140 inline
141 bool CObject_id::IsId8(void) const
142 {
143  TId8 value;
144  return GetId8(value);
145 }
146 
147 
149 inline
151 {
152 #ifdef NCBI_INT8_GI
153  TId8 id8;
154  bool ret = GetId8(id8);
155  if (ret) value = GI_FROM(TId8, id8);
156  return ret;
157 #else
158  if ( IsId() ) {
159  value = GI_FROM(TId, GetId());
160  return true;
161  }
162  return false;
163 #endif
164 }
165 
166 
167 inline
168 bool CObject_id::IsGi(void) const
169 {
170 #ifdef NCBI_INT8_GI
171  return IsId8();
172 #else
173  return IsId();
174 #endif
175 }
176 
177 
178 inline
180 {
181 #ifdef NCBI_INT8_GI
182  return GI_FROM(TId8, GetId8());
183 #else
184  return GI_FROM(TId, GetId());
185 #endif
186 }
187 
188 
189 inline
191 {
192 #ifdef NCBI_INT8_GI
193  SetId8(GI_TO(TId8, value));
194 #else
195  SetId(GI_TO(TId8, value));
196 #endif
197 }
198 
199 #ifdef NCBI_STRICT_GI
200 inline
202 {
203  SetId8(value);
204 }
205 
207 inline
209 {
210 #ifdef NCBI_INT8_GI
211  return GetId8(value);
212 #else
213  if ( IsId() ) {
214  value = GetId();
215  return true;
216  }
217  return false;
218 #endif
219 }
220 #endif
221 
222 
223 /////////////////// end of CObject_id inline methods
224 
225 /////////////////////////////////////////////////////////////////////////////
226 // CReadSharedObjectIdHookBase
227 // base class for read hooks for shared Object-id objects.
228 /////////////////////////////////////////////////////////////////////////////
229 
231  : public CReadClassMemberHook
232 {
233 public:
234  /// Returns shared version of Object-id with specified 'str' field value.
235  /// Can be stored for later read-only use.
236  CObject_id& GetSharedObject_id(const string& id);
237  /// Returns shared version of Object-id with specified 'id' field value.
238  /// Can be stored for later read-only use.
239  CObject_id& GetSharedObject_id(int id);
240 
241  /// Returns shared version of argument Object-id.
242  /// Can be stored for later read-only use.
244  return oid.IsStr()?
245  GetSharedObject_id(oid.GetStr()):
246  GetSharedObject_id(oid.GetId());
247  }
248 
249  /// Reads Object-id and returns reference to its shared version.
250  /// Can be stored for later read-only use.
251  CObject_id& ReadSharedObject_id(CObjectIStream& in);
252 
253 protected:
255 
256 private:
261 };
262 
263 
264 /////////////////////////////////////////////////////////////////////////////
265 
266 
267 END_objects_SCOPE // namespace ncbi::objects::
268 
270 
271 
272 #endif // OBJECTS_GENERAL_OBJECT_ID_HPP
Data storage class.
CObjectIStream –.
Definition: objistr.hpp:93
Object-id can tag or name anything.
Definition: Object_id_.hpp:75
void SetId8(TId8 value)
Definition: Object_id.cpp:175
bool IsId8(void) const
Definition: Object_id.hpp:141
bool operator<(const CObject_id &id2) const
Definition: Object_id.hpp:126
E_Choice GetIdType(TId8 &value) const
Definition: Object_id.cpp:93
bool IsGi(void) const
Definition: Object_id.hpp:168
CObject_id(void)
Definition: Object_id.hpp:120
int Compare(const CObject_id &oid2) const
Definition: Object_id.cpp:145
CObject_id(const CObject_id &)
TId8 GetId8(void) const
Definition: Object_id.cpp:164
TGi GetGi(void) const
Definition: Object_id.hpp:179
void SetGi(TGi value)
Definition: Object_id.hpp:190
CObject_id_Base Tparent
Definition: Object_id.hpp:55
Read hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:78
map< int, CRef< CObject_id > > TMapByInt
Definition: Object_id.hpp:258
CObject_id & GetSharedObject_id(const CObject_id &oid)
Returns shared version of argument Object-id.
Definition: Object_id.hpp:243
map< string, CRef< CObject_id > > TMapByStr
Definition: Object_id.hpp:257
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
Definition: map.hpp:338
bool operator<(const CEquivRange &A, const CEquivRange &B)
static const char * str(char *buf, int n)
Definition: stats.c:84
#define GI_FROM(T, value)
Definition: ncbimisc.hpp:1086
Int8 TIntId
Definition: ncbimisc.hpp:999
#define GI_TO(T, gi)
Definition: ncbimisc.hpp:1085
sequence::ECompare Compare(const CSeq_loc &loc1, const CSeq_loc &loc2, CScope *scope)
Returns the sequence::ECompare containment relationship between CSeq_locs.
#define NCBI_WARN_UNUSED_RESULT
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
#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 NCBI_GENERAL_EXPORT
Definition: ncbi_export.h:512
bool IsStr(void) const
Check if variant Str is selected.
Definition: Object_id_.hpp:291
CObject_id_Base & operator=(const CObject_id_Base &)
bool IsId(void) const
Check if variant Id is selected.
Definition: Object_id_.hpp:264
const TStr & GetStr(void) const
Get the variant data.
Definition: Object_id_.hpp:297
TId & SetId(void)
Select the variant.
Definition: Object_id_.hpp:277
E_Choice
Choice variants.
Definition: Object_id_.hpp:88
TId GetId(void) const
Get the variant data.
Definition: Object_id_.hpp:270
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
std::istream & in(std::istream &in_, double &x_)
Modified on Tue May 28 05:54:19 2024 by modify_doxy.py rev. 669887