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

Go to the SVN repository for this file.

1 /* $Id: User_field.hpp 100341 2023-07-20 17:47:12Z vasilche $
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 data definition file
34  * 'general.asn'.
35  */
36 
37 #ifndef OBJECTS_GENERAL_USER_FIELD_HPP
38 #define OBJECTS_GENERAL_USER_FIELD_HPP
39 
40 
41 // generated includes
43 
44 // generated classes
45 
47 
48 BEGIN_objects_SCOPE // namespace ncbi::objects::
49 
51 {
53 public:
54  // constructor
55  CUser_field(void);
56  // destructor
57  ~CUser_field(void);
58 
59  enum EParseField {
60  eParse_String, ///< Add string even if all numbers
61  eParse_Number ///< Parse a real or integer number, otherwise string
62  };
63 
64  /// set value
65  CUser_field& SetInt(int value);
66  CUser_field& SetInt8(Int8 value);
67  CUser_field& SetGi(TGi gi);
68  CUser_field& SetDouble(double value);
69  CUser_field& SetBool(bool value);
70  CUser_field& SetString(const char* value);
71  CUser_field& SetString(const string& value);
72 
73  /// set a data field to a given value
74  /// Int8 and TGi values can be stored into 'str' field if
75  /// the value doesn't fit into 'int' field
76  CUser_field& SetValue(int value);
77  CUser_field& SetValue(Int8 value);
78 #ifdef NCBI_STRICT_GI
79  CUser_field& SetValue(TGi value);
80 #endif
81  CUser_field& SetValue(double value);
82  CUser_field& SetValue(bool value);
83  CUser_field& SetValue(const char* value);
84  CUser_field& SetValue(const string& value);
85  CUser_field& SetValue(const char* value, EParseField parse);
86  CUser_field& SetValue(const string& value, EParseField parse);
87  CUser_field& SetValue(const vector<int>& value);
88  CUser_field& SetValue(const vector<double>& value);
89  CUser_field& SetValue(const vector<string>& value);
90  CUser_field& SetValue(CUser_object& value);
91  CUser_field& SetValue(const vector< CRef<CUser_object> >& value);
92  CUser_field& SetValue(const vector< CRef<CUser_field> >& value);
93 
94  /// get value
95  int GetInt(void) const;
96  Int8 GetInt8(void) const;
97  TGi GetGi(void) const;
98  bool GetBool(void) const;
99  double GetDouble(void) const;
100  const string& GetString(void) const;
101 
102  template<class Type> Type GetValue(void) const;
103 
104  /// add fields to the current user field
105  CUser_field& AddField(const string& label, int value);
106  CUser_field& AddField(const string& label, Int8 value);
107 #ifdef NCBI_STRICT_GI
108  CUser_field& AddField(const string& label, TGi value);
109 #endif
110  CUser_field& AddField(const string& label, double value);
111  CUser_field& AddField(const string& label, bool value);
112 
113  CUser_field& AddField(const string& label, const char* value);
114  CUser_field& AddField(const string& label, const string& value);
115  CUser_field& AddField(const string& label, const char* value,
116  EParseField field);
117  CUser_field& AddField(const string& label, const string& value,
118  EParseField field);
119  CUser_field& AddField(const string& label, const vector<string>& value);
120 
121  CUser_field& AddField(const string& label, const vector<int>& value);
122  CUser_field& AddField(const string& label, const vector<double>& value);
123 
124  CUser_field& AddField(const string& label, CUser_object& value);
125  CUser_field& AddField(const string& label,
126  const vector< CRef<CUser_object> >& value);
127  CUser_field& AddField(const string& label,
128  const vector< CRef<CUser_field> >& value);
129 
130  /// Set num field from a container size
131  /// Check for overflow and throw CSerialException::eOverflow
132  /// if the size doesn't fit into the field
133  void SetNumFromSize(size_t value);
134 
135  /// Access a named field in this user field. This will tokenize the
136  /// string 'str' on the delimiters; if the field doesn't exist, an
137  /// exception will be thrown.
138  const CUser_field& GetField(const string& str,
139  const string& delim = ".",
140  NStr::ECase use_case = NStr::eCase) const;
141 
142  /// Return a field reference representing the tokenized key, or a
143  /// NULL reference if the key doesn't exist.
144  CConstRef<CUser_field> GetFieldRef(const string& str,
145  const string& delim = ".",
146  NStr::ECase use_case = NStr::eCase) const;
147 
148  /// For functions that don't use delims, we instead use a chain of names.
150  /// Convenience func. This can be deprecated if a
151  /// NStr::Join function is created that takes
152  /// the type of TFieldNameChainUnderlying
153  void Join(ostream & out_name_strm, const string & delim = ".") const;
154 
156  m_FieldNameChain.push_back(str);
157  }
158 
159  bool operator < (const SFieldNameChain & rhs) const {
160  return m_FieldNameChain < rhs.m_FieldNameChain;
161  }
162 
163  typedef vector<CTempStringEx> TFieldNameChainUnderlying;
165  };
166 
167  /// Maps field names like the input for GetFieldRef to the user-field.
169 
170  /// Flags that affect behavior of TMapFieldNameToRef functions.
172  fFieldMapFlags_ExcludeThis = (1<<0) ///< = 0x1 (excludes this CUser_field's name and mapping to self from results)
173  };
174  typedef int TFieldMapFlags; ///< holds bitwise OR of "EFieldMapFlags"
175 
176  /// Recursively get the map of field names like the input
177  /// for GetFieldRef to the user-field.
178  ///
179  /// @param out_mapFieldNameToRef
180  /// The results are put into here, but it becomes INVALID if this
181  /// CUser_field or any of its descendents change their label.
182  /// It will NOT be cleared
183  /// before more data is added, and in that case would overwrite any
184  /// item which has the same key.
185  /// @param fFieldMapFlags
186  /// Flags that affect behavior of function.
187  /// @param parent_name
188  /// Outside users probably don't need this. It's really for
189  /// internal recursive calls when building the map.
190  void GetFieldsMap(
191  CUser_field::TMapFieldNameToRef & out_mapFieldNameToRef,
192  TFieldMapFlags fFieldMapFlags = 0,
193  const SFieldNameChain & parent_name = SFieldNameChain() ) const;
194 
195  /// Access a named field in this user field. This will tokenize the
196  /// string 'str' on the delimiters and recursively add fields where needed
197  CUser_field& SetField(const string& str,
198  const string& delim = ".",
199  NStr::ECase use_case = NStr::eCase);
200 
201  /// Return a field reference representing the tokenized key, or a
202  /// NULL reference if the key cannot be created for some reason.
203  CRef<CUser_field> SetFieldRef(const string& str,
204  const string& delim = ".",
205  NStr::ECase use_case = NStr::eCase);
206 
207  /// Verify that a named field exists
208  bool HasField(const string& str,
209  const string& delim = ".",
210  NStr::ECase use_case = NStr::eCase) const;
211 
212  /// Delete the named field.
213  /// return true if successful. false if field doesn't exist.
214  bool DeleteField(const string& str,
215  const string& delim = ".",
216  NStr::ECase use_case = NStr::eCase);
217 
218 
219 private:
220  // Prohibit copy constructor and assignment operator
223 };
224 
225 
226 
227 /////////////////// CUser_field inline methods
228 
229 // constructor
230 inline
232 {
233 }
234 
235 
236 inline
238 {
239  SetData().SetStr(value);
240  return *this;
241 }
242 
243 
244 inline
246 {
247  SetData().SetInt(value);
248  return *this;
249 }
250 
251 
252 inline
254 {
255  SetData().SetBool(value);
256  return *this;
257 }
258 
259 
260 inline
262 {
263  SetData().SetReal(value);
264  return *this;
265 }
266 
267 
268 inline
270 {
271  return SetString(value);
272 }
273 
274 
275 inline
277 {
278  return SetString(value);
279 }
280 
281 
282 inline
284 {
285  return SetInt(value);
286 }
287 
288 
289 inline
291 {
292  return SetBool(value);
293 }
294 
295 
296 inline
298 {
299  return SetDouble(value);
300 }
301 
302 
303 inline
305 {
306  return SetInt8(value);
307 }
308 
309 
310 inline
312 {
313  return SetValue(GI_TO(TIntId, value));
314 }
315 
316 
317 #ifdef NCBI_STRICT_GI
318 inline
320 {
321  return SetGi(value);
322 }
323 #endif
324 
325 
326 inline
327 int CUser_field::GetInt(void) const
328 {
329  return GetData().GetInt();
330 }
331 
332 
333 inline
334 double CUser_field::GetDouble(void) const
335 {
336  return GetData().GetReal();
337 }
338 
339 
340 inline
341 bool CUser_field::GetBool(void) const
342 {
343  return GetData().GetBool();
344 }
345 
346 
347 inline
348 const string& CUser_field::GetString(void) const
349 {
350  return GetData().GetStr();
351 }
352 
353 
354 template<>
355 inline
356 int CUser_field::GetValue<int>(void) const
357 {
358  return GetInt();
359 }
360 
361 
362 template<>
363 inline
364 Int8 CUser_field::GetValue<Int8>(void) const
365 {
366  return GetInt8();
367 }
368 
369 
370 template<>
371 inline
372 double CUser_field::GetValue<double>(void) const
373 {
374  return GetDouble();
375 }
376 
377 
378 template<>
379 inline
380 bool CUser_field::GetValue<bool>(void) const
381 {
382  return GetBool();
383 }
384 
385 
386 template<>
387 inline
388 string CUser_field::GetValue<string>(void) const
389 {
390  return GetString();
391 }
392 
393 
394 inline
396 {
397  return GI_FROM(TIntId, GetValue<TIntId>());
398 }
399 
400 
401 #ifdef NCBI_STRICT_GI
402 template<>
403 inline
404 TGi CUser_field::GetValue<TGi>(void) const
405 {
406  return GetGi();
407 }
408 #endif
409 
410 
411 /////////////////// end of CUser_field inline methods
412 
413 
414 END_objects_SCOPE // namespace ncbi::objects::
415 
417 
418 #endif // OBJECTS_GENERAL_USER_FIELD_HPP
Data storage class.
CUser_field_Base –.
Definition: User_field_.hpp:80
CUser_field(const CUser_field &value)
EFieldMapFlags
Flags that affect behavior of TMapFieldNameToRef functions.
Definition: User_field.hpp:171
map< SFieldNameChain, CConstRef< CUser_field > > TMapFieldNameToRef
Maps field names like the input for GetFieldRef to the user-field.
Definition: User_field.hpp:168
CUser_field & SetString(const char *value)
Definition: User_field.cpp:445
int GetInt(void) const
get value
Definition: User_field.hpp:327
@ eParse_String
Add string even if all numbers.
Definition: User_field.hpp:60
CUser_field & SetGi(TGi gi)
Definition: User_field.hpp:311
CUser_field & operator=(const CUser_field &value)
CUser_field & SetInt8(Int8 value)
Definition: User_field.cpp:481
CUser_field & SetValue(int value)
set a data field to a given value Int8 and TGi values can be stored into 'str' field if the value doe...
Definition: User_field.hpp:283
const string & GetString(void) const
Definition: User_field.hpp:348
Type GetValue(void) const
double GetDouble(void) const
Definition: User_field.hpp:334
bool GetBool(void) const
Definition: User_field.hpp:341
CUser_field & SetBool(bool value)
Definition: User_field.hpp:253
CUser_field & AddField(const string &label, const vector< string > &value)
int TFieldMapFlags
holds bitwise OR of "EFieldMapFlags"
Definition: User_field.hpp:174
CUser_field & SetInt(int value)
set value
Definition: User_field.hpp:245
CUser_field(void)
Definition: User_field.hpp:231
CUser_field & SetDouble(double value)
Definition: User_field.hpp:261
CUser_field_Base Tparent
Definition: User_field.hpp:52
Int8 GetInt8(void) const
Definition: User_field.cpp:549
TGi GetGi(void) const
Definition: User_field.hpp:395
Definition: map.hpp:338
bool operator<(const CEquivRange &A, const CEquivRange &B)
static const char * str(char *buf, int n)
Definition: stats.c:84
void SetField(objects::CUser_object &user, const string &field_name, const string &val)
#define GI_FROM(T, value)
Definition: ncbimisc.hpp:1086
Int8 TIntId
Definition: ncbimisc.hpp:999
#define GI_TO(T, gi)
Definition: ncbimisc.hpp:1085
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
ECase
Which type of string comparison.
Definition: ncbistr.hpp:1204
@ eCase
Case sensitive compare.
Definition: ncbistr.hpp:1205
#define NCBI_GENERAL_EXPORT
Definition: ncbi_export.h:512
static const char label[]
const TStr & GetStr(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
TInt & SetInt(void)
Select the variant.
TBool GetBool(void) const
Get the variant data.
TData & SetData(void)
Assign a value to Data data member.
TStr & SetStr(void)
Select the variant.
TInt GetInt(void) const
Get the variant data.
TReal & SetReal(void)
Select the variant.
TReal GetReal(void) const
Get the variant data.
TBool & SetBool(void)
Select the variant.
CNcbiMatrix< T > & operator+=(CNcbiMatrix< T > &, const CNcbiMatrix< U > &)
global addition: matrix += matrix
Definition: matrix.hpp:570
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
For functions that don't use delims, we instead use a chain of names.
Definition: User_field.hpp:149
TFieldNameChainUnderlying m_FieldNameChain
Definition: User_field.hpp:164
vector< CTempStringEx > TFieldNameChainUnderlying
Definition: User_field.hpp:163
#define Type
Modified on Sun Apr 14 05:28:50 2024 by modify_doxy.py rev. 669887