NCBI C++ ToolKit
Variant_.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 Variant_.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/varrep/varrep.asn">varrep.asn</a>
34 /// and additional tune-up parameters:
35 /// <a href="/IEB/ToolBox/CPP_DOC/lxr/source/src/objects/varrep/varrep.def">varrep.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_VARREP_VARIANT_BASE_HPP
42 #define OBJECTS_VARREP_VARIANT_BASE_HPP
43 
44 // standard includes
45 #include <serial/serialbase.hpp>
46 
47 // generated includes
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 CSimpleVariant;
61 
62 
63 // generated classes
64 
65 
66 /** @addtogroup dataspec_NCBI_VariationIRep
67  *
68  * @{
69  */
70 
71 /////////////////////////////////////////////////////////////////////////////
72 ///
73 /// CVariant_Base --
74 ///
75 
77 {
79 public:
80  // constructor
81  CVariant_Base(void);
82  // destructor
83  virtual ~CVariant_Base(void);
84 
85  // type info
87 
88 
89  /// Choice variants.
90  enum E_Choice {
91  e_not_set = 0, ///< No variant selected
93  e_Special
94  };
95  /// Maximum+1 value of the choice variant enumerator.
97  e_MaxChoice = 3 ///< == e_Special+1
98  };
99 
100  /// Reset the whole object
101  virtual void Reset(void);
102 
103  /// Reset the selection (set it to e_not_set).
104  virtual void ResetSelection(void);
105 
106  /// Which variant is currently selected.
107  ///
108  /// @return
109  /// Choice state enumerator.
110  E_Choice Which(void) const;
111 
112  /// Verify selection, throw exception if it differs from the expected.
113  ///
114  /// @param index
115  /// Expected selection.
116  void CheckSelected(E_Choice index) const;
117 
118  /// Throw 'InvalidSelection' exception.
119  ///
120  /// @param index
121  /// Expected selection.
122  NCBI_NORETURN void ThrowInvalidSelection(E_Choice index) const;
123 
124  /// Retrieve selection name (for diagnostic purposes).
125  ///
126  /// @param index
127  /// One of possible selection states.
128  /// @return
129  /// Name string.
130  static string SelectionName(E_Choice index);
131 
132  /// Select the requested variant if needed.
133  ///
134  /// @param index
135  /// New selection state.
136  /// @param reset
137  /// Flag that defines the resetting of the variant data. The data will
138  /// be reset if either the current selection differs from the new one,
139  /// or the flag is set to eDoResetVariant.
141  /// Select the requested variant if needed,
142  /// allocating CObject variants from memory pool.
143  void Select(E_Choice index,
144  EResetVariant reset,
145  CObjectMemoryPool* pool);
146 
147  // types
149  typedef int TSpecial;
150 
151  // getters
152  // setters
153 
154 
155  /// Check if variant Simple is selected.
156  ///
157  /// Simple type is defined as 'typedef CSimpleVariant TSimple'.
158  /// @return
159  /// - true, if the variant is selected.
160  /// - false, otherwise.
161  bool IsSimple(void) const;
162 
163  /// Get the variant data.
164  ///
165  /// @return
166  /// Reference to the data.
167  const TSimple& GetSimple(void) const;
168 
169  /// Select the variant.
170  ///
171  /// @return
172  /// Reference to the variant data.
173  TSimple& SetSimple(void);
174  /// Select the variant and set its data.
175  ///
176  /// @param value
177  /// Reference to the data.
178  void SetSimple(TSimple& value);
179 
180 
181  /// Check if variant Special is selected.
182  ///
183  /// Special type is defined as 'typedef int TSpecial'.
184  /// @return
185  /// - true, if the variant is selected.
186  /// - false, otherwise.
187  bool IsSpecial(void) const;
188 
189  /// Get the variant data.
190  ///
191  /// @return
192  /// Copy of the variant data.
193  TSpecial GetSpecial(void) const;
194 
195  /// Select the variant.
196  ///
197  /// @return
198  /// Reference to the variant data.
199  TSpecial& SetSpecial(void);
200 
201  /// Select the variant and set its data.
202  ///
203  /// @param value
204  /// Variant data.
205  void SetSpecial(TSpecial value);
206 
207 
208 private:
209  // copy constructor and assignment operator
212  // choice state
214  // helper methods
215  void DoSelect(E_Choice index, CObjectMemoryPool* pool = 0);
216 
217  static const char* const sm_SelectionNames[];
218  // data
219  union {
221  NCBI_NS_NCBI::CSerialObject *m_object;
222  };
223 };
224 
225 /* @} */
226 
227 
228 
229 
230 
231 ///////////////////////////////////////////////////////////
232 ///////////////////// inline methods //////////////////////
233 ///////////////////////////////////////////////////////////
234 inline
236 {
237  return m_choice;
238 }
239 
240 inline
242 {
243  if ( m_choice != index )
244  ThrowInvalidSelection(index);
245 }
246 
247 inline
248 void CVariant_Base::Select(E_Choice index, NCBI_NS_NCBI::EResetVariant reset, NCBI_NS_NCBI::CObjectMemoryPool* pool)
249 {
250  if ( reset == NCBI_NS_NCBI::eDoResetVariant || m_choice != index ) {
251  if ( m_choice != e_not_set )
252  ResetSelection();
253  DoSelect(index, pool);
254  }
255 }
256 
257 inline
258 void CVariant_Base::Select(E_Choice index, NCBI_NS_NCBI::EResetVariant reset)
259 {
260  Select(index, reset, 0);
261 }
262 
263 inline
264 bool CVariant_Base::IsSimple(void) const
265 {
266  return m_choice == e_Simple;
267 }
268 
269 inline
270 bool CVariant_Base::IsSpecial(void) const
271 {
272  return m_choice == e_Special;
273 }
274 
275 inline
277 {
279  return m_Special;
280 }
281 
282 inline
284 {
286  return m_Special;
287 }
288 
289 inline
291 {
293  m_Special = value;
294 }
295 
296 ///////////////////////////////////////////////////////////
297 ////////////////// end of inline methods //////////////////
298 ///////////////////////////////////////////////////////////
299 
300 
301 
302 
303 
304 END_objects_SCOPE // namespace ncbi::objects::
305 
307 
308 
309 #endif // OBJECTS_VARREP_VARIANT_BASE_HPP
User-defined methods of the data storage class.
Base class for all serializable objects.
Definition: serialbase.hpp:150
CSimpleVariant –.
CVariant_Base –.
Definition: Variant_.hpp:77
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
const TSimple & GetSimple(void) const
Get the variant data.
Definition: Variant_.cpp:100
E_Choice m_choice
Definition: Variant_.hpp:213
E_ChoiceStopper
Maximum+1 value of the choice variant enumerator.
Definition: Variant_.hpp:96
virtual void ResetSelection(void)
Reset the selection (set it to e_not_set).
Definition: Variant_.cpp:57
static string SelectionName(E_Choice index)
Retrieve selection name (for diagnostic purposes).
Definition: Variant_.cpp:90
static const char *const sm_SelectionNames[]
Definition: Variant_.hpp:217
void ThrowInvalidSelection(E_Choice index) const
Throw 'InvalidSelection' exception.
Definition: Variant_.cpp:95
CVariant_Base & operator=(const CVariant_Base &)
CSerialObject Tparent
Definition: Variant_.hpp:78
virtual void Reset(void)
Reset the whole object.
Definition: Variant_.cpp:51
TSpecial & SetSpecial(void)
Select the variant.
Definition: Variant_.hpp:283
TSpecial GetSpecial(void) const
Get the variant data.
Definition: Variant_.hpp:276
void Select(E_Choice index, EResetVariant reset, CObjectMemoryPool *pool)
Select the requested variant if needed, allocating CObject variants from memory pool.
CVariant_Base(void)
Definition: Variant_.cpp:136
virtual ~CVariant_Base(void)
Definition: Variant_.cpp:142
E_Choice Which(void) const
Which variant is currently selected.
Definition: Variant_.hpp:235
void DoSelect(E_Choice index, CObjectMemoryPool *pool=0)
Definition: Variant_.cpp:69
NCBI_NS_NCBI::CSerialObject * m_object
Definition: Variant_.hpp:221
void CheckSelected(E_Choice index) const
Verify selection, throw exception if it differs from the expected.
Definition: Variant_.hpp:241
void Select(E_Choice index, EResetVariant reset=eDoResetVariant)
Select the requested variant if needed.
TSimple & SetSimple(void)
Select the variant.
Definition: Variant_.cpp:106
TSpecial m_Special
Definition: Variant_.hpp:220
E_Choice
Choice variants.
Definition: Variant_.hpp:90
CSimpleVariant TSimple
Definition: Variant_.hpp:148
CVariant_Base(const CVariant_Base &)
bool IsSimple(void) const
Check if variant Simple is selected.
Definition: Variant_.hpp:264
bool IsSpecial(void) const
Check if variant Special is selected.
Definition: Variant_.hpp:270
DECLARE_INTERNAL_TYPE_INFO()
@ e_MaxChoice
== e_Special+1
Definition: Variant_.hpp:97
@ e_not_set
No variant selected.
Definition: Variant_.hpp:91
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Modified on Fri Sep 20 14:58:10 2024 by modify_doxy.py rev. 669887
HHS Vulnerability Disclosure