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

Go to the SVN repository for this file.

1 /* $Id$
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  */
27 
28 /// @file Date_.hpp
29 /// Data storage class.
30 ///
31 /// This file was generated by application DATATOOL
32 /// using the following specifications:
33 /// <a href="/IEB/ToolBox/CPP_DOC/lxr/source/src/objects/general/general.asn">general.asn</a>
34 /// and additional tune-up parameters:
35 /// <a href="/IEB/ToolBox/CPP_DOC/lxr/source/src/objects/general/general.def">general.def</a>
36 ///
37 /// ATTENTION:
38 /// Don't edit or commit this file into CVS as this file will
39 /// be overridden (by DATATOOL) without warning!
40 
41 #ifndef OBJECTS_GENERAL_DATE_BASE_HPP
42 #define OBJECTS_GENERAL_DATE_BASE_HPP
43 
44 // standard includes
45 #include <serial/serialbase.hpp>
46 
47 // generated includes
48 #include <string>
49 
51 
52 #ifndef BEGIN_objects_SCOPE
53 # define BEGIN_objects_SCOPE BEGIN_SCOPE(objects)
54 # define END_objects_SCOPE END_SCOPE(objects)
55 #endif
56 BEGIN_objects_SCOPE // namespace ncbi::objects::
57 
58 
59 // forward declarations
60 class CDate_std;
61 
62 
63 // generated classes
64 
65 
66 /** @addtogroup dataspec_NCBI_General
67  *
68  * @{
69  */
70 
71 /////////////////////////////////////////////////////////////////////////////
72 /// StringStore is really a VisibleString. It is used to define very
73 /// long strings which may need to be stored by the receiving program
74 /// in special structures, such as a ByteStore, but it's just a hint.
75 /// AsnTool stores StringStores in ByteStore structures.
76 /// OCTET STRINGs are also stored in ByteStores by AsnTool
77 ///
78 /// typedef struct bsunit { /* for building multiline strings
79 /// Nlm_Handle str; /* the string piece
80 /// Nlm_Int2 len_avail,
81 /// len;
82 /// struct bsunit PNTR next; } /* the next one
83 /// Nlm_BSUnit, PNTR Nlm_BSUnitPtr;
84 ///
85 /// typedef struct bytestore {
86 /// Nlm_Int4 seekptr, /* current position
87 /// totlen, /* total stored data length in bytes
88 /// chain_offset; /* offset in ByteStore of first byte in curchain
89 /// Nlm_BSUnitPtr chain, /* chain of elements
90 /// curchain; /* the BSUnit containing seekptr
91 /// } Nlm_ByteStore, PNTR Nlm_ByteStorePtr;
92 ///
93 /// AsnTool incorporates this as a primitive type, so the definition
94 /// is here just for completeness
95 ///
96 /// StringStore ::= [APPLICATION 1] IMPLICIT OCTET STRING
97 ///
98 /// BigInt is really an INTEGER. It is used to warn the receiving code to expect
99 /// a value bigger than Int4 (actually Int8). It will be stored in DataVal.bigintvalue
100 ///
101 /// Like StringStore, AsnTool incorporates it as a primitive. The definition would be:
102 /// BigInt ::= [APPLICATION 2] IMPLICIT INTEGER
103 ///
104 /// Date is used to replace the (overly complex) UTCTtime, GeneralizedTime
105 /// of ASN.1
106 /// It stores only a date
107 ///
108 ///
109 /// CDate_Base --
110 ///
111 
113 {
115 public:
116  // constructor
117  CDate_Base(void);
118  // destructor
119  virtual ~CDate_Base(void);
120 
121  // type info
123 
124 
125  /// Choice variants.
126  enum E_Choice {
127  e_not_set = 0, ///< No variant selected
128  e_Str, ///< for those unparsed dates
129  e_Std ///< use this if you can
130  };
131  /// Maximum+1 value of the choice variant enumerator.
133  e_MaxChoice = 3 ///< == e_Std+1
134  };
135 
136  /// Reset the whole object
137  virtual void Reset(void);
138 
139  /// Reset the selection (set it to e_not_set).
140  virtual void ResetSelection(void);
141 
142  /// Which variant is currently selected.
143  ///
144  /// @return
145  /// Choice state enumerator.
146  E_Choice Which(void) const;
147 
148  /// Verify selection, throw exception if it differs from the expected.
149  ///
150  /// @param index
151  /// Expected selection.
152  void CheckSelected(E_Choice index) const;
153 
154  /// Throw 'InvalidSelection' exception.
155  ///
156  /// @param index
157  /// Expected selection.
158  NCBI_NORETURN void ThrowInvalidSelection(E_Choice index) const;
159 
160  /// Retrieve selection name (for diagnostic purposes).
161  ///
162  /// @param index
163  /// One of possible selection states.
164  /// @return
165  /// Name string.
166  static string SelectionName(E_Choice index);
167 
168  /// Select the requested variant if needed.
169  ///
170  /// @param index
171  /// New selection state.
172  /// @param reset
173  /// Flag that defines the resetting of the variant data. The data will
174  /// be reset if either the current selection differs from the new one,
175  /// or the flag is set to eDoResetVariant.
177  /// Select the requested variant if needed,
178  /// allocating CObject variants from memory pool.
179  void Select(E_Choice index,
180  EResetVariant reset,
181  CObjectMemoryPool* pool);
182 
183  // types
184  typedef string TStr;
185  typedef CDate_std TStd;
186 
187  // getters
188  // setters
189 
190 
191  /// Check if variant Str is selected.
192  ///
193  /// Str type is defined as 'typedef string TStr'.
194  /// @return
195  /// - true, if the variant is selected.
196  /// - false, otherwise.
197  bool IsStr(void) const;
198 
199  /// Get the variant data.
200  ///
201  /// @return
202  /// Reference to the data.
203  const TStr& GetStr(void) const;
204 
205  /// Select the variant.
206  ///
207  /// @return
208  /// Reference to the variant data.
209  TStr& SetStr(void);
210 
211  /// Select the variant and set its data.
212  ///
213  /// @param value
214  /// Variant data.
215  void SetStr(const TStr& value);
216 
217 
218  /// Check if variant Std is selected.
219  ///
220  /// Std type is defined as 'typedef CDate_std TStd'.
221  /// @return
222  /// - true, if the variant is selected.
223  /// - false, otherwise.
224  bool IsStd(void) const;
225 
226  /// Get the variant data.
227  ///
228  /// @return
229  /// Reference to the data.
230  const TStd& GetStd(void) const;
231 
232  /// Select the variant.
233  ///
234  /// @return
235  /// Reference to the variant data.
236  TStd& SetStd(void);
237  /// Select the variant and set its data.
238  ///
239  /// @param value
240  /// Reference to the data.
241  void SetStd(TStd& value);
242 
243 
244 private:
245  // copy constructor and assignment operator
248  // choice state
250  // helper methods
251  void DoSelect(E_Choice index, CObjectMemoryPool* pool = 0);
252 
253  static const char* const sm_SelectionNames[];
254  // data
255  union {
256  NCBI_NS_NCBI::CUnionBuffer<NCBI_NS_STD::string> m_string;
257  NCBI_NS_NCBI::CSerialObject *m_object;
258  };
259 };
260 
261 /* @} */
262 
263 
264 
265 
266 
267 ///////////////////////////////////////////////////////////
268 ///////////////////// inline methods //////////////////////
269 ///////////////////////////////////////////////////////////
270 inline
272 {
273  return m_choice;
274 }
275 
276 inline
278 {
279  if ( m_choice != index )
280  ThrowInvalidSelection(index);
281 }
282 
283 inline
284 void CDate_Base::Select(E_Choice index, NCBI_NS_NCBI::EResetVariant reset, NCBI_NS_NCBI::CObjectMemoryPool* pool)
285 {
286  if ( reset == NCBI_NS_NCBI::eDoResetVariant || m_choice != index ) {
287  if ( m_choice != e_not_set )
288  ResetSelection();
289  DoSelect(index, pool);
290  }
291 }
292 
293 inline
294 void CDate_Base::Select(E_Choice index, NCBI_NS_NCBI::EResetVariant reset)
295 {
296  Select(index, reset, 0);
297 }
298 
299 inline
300 bool CDate_Base::IsStr(void) const
301 {
302  return m_choice == e_Str;
303 }
304 
305 inline
307 {
309  return *m_string;
310 }
311 
312 inline
314 {
316  return *m_string;
317 }
318 
319 inline
320 bool CDate_Base::IsStd(void) const
321 {
322  return m_choice == e_Std;
323 }
324 
325 ///////////////////////////////////////////////////////////
326 ////////////////// end of inline methods //////////////////
327 ///////////////////////////////////////////////////////////
328 
329 
330 
331 
332 
333 END_objects_SCOPE // namespace ncbi::objects::
334 
336 
337 
338 #endif // OBJECTS_GENERAL_DATE_BASE_HPP
StringStore is really a VisibleString.
Definition: Date_.hpp:113
Base class for all serializable objects.
Definition: serialbase.hpp:150
EResetVariant
Definition: serialbase.hpp:76
@ eDoResetVariant
Definition: serialbase.hpp:77
@ eDoNotResetVariant
Definition: serialbase.hpp:78
#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
E_ChoiceStopper
Maximum+1 value of the choice variant enumerator.
Definition: Date_.hpp:132
NCBI_NS_NCBI::CUnionBuffer< NCBI_NS_STD::string > m_string
Definition: Date_.hpp:256
virtual void ResetSelection(void)
Reset the selection (set it to e_not_set).
Definition: Date_.cpp:57
bool IsStd(void) const
Check if variant Std is selected.
Definition: Date_.hpp:320
NCBI_NS_NCBI::CUnionBuffer< NCBI_NS_STD::string > m_string
Definition: Date_.hpp:256
void Select(E_Choice index, EResetVariant reset, CObjectMemoryPool *pool)
Select the requested variant if needed, allocating CObject variants from memory pool.
string TStr
Definition: Date_.hpp:184
NCBI_NS_NCBI::CSerialObject * m_object
Definition: Date_.hpp:257
CDate_Base(const CDate_Base &)
const TStr & GetStr(void) const
Get the variant data.
Definition: Date_.hpp:306
E_Choice m_choice
Definition: Date_.hpp:249
CDate_Base & operator=(const CDate_Base &)
void DoSelect(E_Choice index, CObjectMemoryPool *pool=0)
Definition: Date_.cpp:72
E_Choice
Choice variants.
Definition: Date_.hpp:126
CDate_std TStd
Definition: Date_.hpp:185
void ThrowInvalidSelection(E_Choice index) const
Throw 'InvalidSelection' exception.
Definition: Date_.cpp:98
void CheckSelected(E_Choice index) const
Verify selection, throw exception if it differs from the expected.
Definition: Date_.hpp:277
E_Choice Which(void) const
Which variant is currently selected.
Definition: Date_.hpp:271
CSerialObject Tparent
Definition: Date_.hpp:114
DECLARE_INTERNAL_TYPE_INFO()
TStr & SetStr(void)
Select the variant.
Definition: Date_.hpp:313
void Select(E_Choice index, EResetVariant reset=eDoResetVariant)
Select the requested variant if needed.
bool IsStr(void) const
Check if variant Str is selected.
Definition: Date_.hpp:300
@ e_not_set
No variant selected.
Definition: Date_.hpp:127
@ e_Str
for those unparsed dates
Definition: Date_.hpp:128
@ e_Std
use this if you can
Definition: Date_.hpp:129
@ e_not_set
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Modified on Fri Sep 20 14:57:10 2024 by modify_doxy.py rev. 669887