NCBI C++ ToolKit
Object_id_.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 Object_id_.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_OBJECT_ID_BASE_HPP
42 #define OBJECTS_GENERAL_OBJECT_ID_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 // generated classes
60 
61 
62 /** @addtogroup dataspec_NCBI_General
63  *
64  * @{
65  */
66 
67 /////////////////////////////////////////////////////////////////////////////
68 /// Object-id can tag or name anything
69 ///
70 ///
71 /// CObject_id_Base --
72 ///
73 
75 {
77 public:
78  // constructor
79  CObject_id_Base(void);
80  // destructor
81  virtual ~CObject_id_Base(void);
82 
83  // type info
85 
86 
87  /// Choice variants.
88  enum E_Choice {
89  e_not_set = 0, ///< No variant selected
91  e_Str
92  };
93  /// Maximum+1 value of the choice variant enumerator.
95  e_MaxChoice = 3 ///< == e_Str+1
96  };
97 
98  /// Reset the whole object
99  virtual void Reset(void);
100 
101  /// Reset the selection (set it to e_not_set).
102  virtual void ResetSelection(void);
103 
104  /// Which variant is currently selected.
105  ///
106  /// @return
107  /// Choice state enumerator.
108  E_Choice Which(void) const;
109 
110  /// Verify selection, throw exception if it differs from the expected.
111  ///
112  /// @param index
113  /// Expected selection.
114  void CheckSelected(E_Choice index) const;
115 
116  /// Throw 'InvalidSelection' exception.
117  ///
118  /// @param index
119  /// Expected selection.
120  NCBI_NORETURN void ThrowInvalidSelection(E_Choice index) const;
121 
122  /// Retrieve selection name (for diagnostic purposes).
123  ///
124  /// @param index
125  /// One of possible selection states.
126  /// @return
127  /// Name string.
128  static string SelectionName(E_Choice index);
129 
130  /// Select the requested variant if needed.
131  ///
132  /// @param index
133  /// New selection state.
134  /// @param reset
135  /// Flag that defines the resetting of the variant data. The data will
136  /// be reset if either the current selection differs from the new one,
137  /// or the flag is set to eDoResetVariant.
139  /// Select the requested variant if needed,
140  /// allocating CObject variants from memory pool.
141  void Select(E_Choice index,
142  EResetVariant reset,
143  CObjectMemoryPool* pool);
144 
145  // types
146  typedef int TId;
147  typedef string TStr;
148 
149  // getters
150  // setters
151 
152 
153  /// Check if variant Id is selected.
154  ///
155  /// Id type is defined as 'typedef int TId'.
156  /// @return
157  /// - true, if the variant is selected.
158  /// - false, otherwise.
159  bool IsId(void) const;
160 
161  /// Get the variant data.
162  ///
163  /// @return
164  /// Copy of the variant data.
165  TId GetId(void) const;
166 
167  /// Select the variant.
168  ///
169  /// @return
170  /// Reference to the variant data.
171  TId& SetId(void);
172 
173  /// Select the variant and set its data.
174  ///
175  /// @param value
176  /// Variant data.
177  void SetId(TId value);
178 
179 
180  /// Check if variant Str is selected.
181  ///
182  /// Str type is defined as 'typedef string TStr'.
183  /// @return
184  /// - true, if the variant is selected.
185  /// - false, otherwise.
186  bool IsStr(void) const;
187 
188  /// Get the variant data.
189  ///
190  /// @return
191  /// Reference to the data.
192  const TStr& GetStr(void) const;
193 
194  /// Select the variant.
195  ///
196  /// @return
197  /// Reference to the variant data.
198  TStr& SetStr(void);
199 
200  /// Select the variant and set its data.
201  ///
202  /// @param value
203  /// Variant data.
204  void SetStr(const TStr& value);
205 
206 
207 private:
208  // copy constructor and assignment operator
211  // choice state
213  // helper methods
214  void DoSelect(E_Choice index, CObjectMemoryPool* pool = 0);
215 
216  static const char* const sm_SelectionNames[];
217  // data
218  union {
220  NCBI_NS_NCBI::CUnionBuffer<NCBI_NS_STD::string> m_string;
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 CObject_id_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 CObject_id_Base::Select(E_Choice index, NCBI_NS_NCBI::EResetVariant reset)
259 {
260  Select(index, reset, 0);
261 }
262 
263 inline
264 bool CObject_id_Base::IsId(void) const
265 {
266  return m_choice == e_Id;
267 }
268 
269 inline
271 {
273  return m_Id;
274 }
275 
276 inline
278 {
280  return m_Id;
281 }
282 
283 inline
285 {
287  m_Id = value;
288 }
289 
290 inline
291 bool CObject_id_Base::IsStr(void) const
292 {
293  return m_choice == e_Str;
294 }
295 
296 inline
298 {
300  return *m_string;
301 }
302 
303 inline
305 {
307  return *m_string;
308 }
309 
310 ///////////////////////////////////////////////////////////
311 ////////////////// end of inline methods //////////////////
312 ///////////////////////////////////////////////////////////
313 
314 
315 
316 
317 
318 END_objects_SCOPE // namespace ncbi::objects::
319 
321 
322 
323 #endif // OBJECTS_GENERAL_OBJECT_ID_BASE_HPP
Object-id can tag or name anything.
Definition: Object_id_.hpp:75
Base class for all serializable objects.
Definition: serialbase.hpp:150
char value[7]
Definition: config.c:431
EResetVariant
Definition: serialbase.hpp:76
@ eDoResetVariant
Definition: serialbase.hpp:77
@ eDoNotResetVariant
Definition: serialbase.hpp:78
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
#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 &)
NCBI_NS_NCBI::CUnionBuffer< NCBI_NS_STD::string > m_string
Definition: Object_id_.hpp:220
bool IsId(void) const
Check if variant Id is selected.
Definition: Object_id_.hpp:264
E_Choice m_choice
Definition: Object_id_.hpp:212
virtual void ResetSelection(void)
Reset the selection (set it to e_not_set).
Definition: Object_id_.cpp:56
CSerialObject Tparent
Definition: Object_id_.hpp:76
E_Choice Which(void) const
Which variant is currently selected.
Definition: Object_id_.hpp:235
const TStr & GetStr(void) const
Get the variant data.
Definition: Object_id_.hpp:297
TStr & SetStr(void)
Select the variant.
Definition: Object_id_.hpp:304
void * m_dummy_pointer_for_alignment
Definition: Object_id_.hpp:221
CObject_id_Base(const CObject_id_Base &)
void DoSelect(E_Choice index, CObjectMemoryPool *pool=0)
Definition: Object_id_.cpp:68
void Select(E_Choice index, EResetVariant reset=eDoResetVariant)
Select the requested variant if needed.
NCBI_NS_NCBI::CUnionBuffer< NCBI_NS_STD::string > m_string
Definition: Object_id_.hpp:220
void CheckSelected(E_Choice index) const
Verify selection, throw exception if it differs from the expected.
Definition: Object_id_.hpp:241
void ThrowInvalidSelection(E_Choice index) const
Throw 'InvalidSelection' exception.
Definition: Object_id_.cpp:94
TId & SetId(void)
Select the variant.
Definition: Object_id_.hpp:277
E_ChoiceStopper
Maximum+1 value of the choice variant enumerator.
Definition: Object_id_.hpp:94
E_Choice
Choice variants.
Definition: Object_id_.hpp:88
void Select(E_Choice index, EResetVariant reset, CObjectMemoryPool *pool)
Select the requested variant if needed, allocating CObject variants from memory pool.
TId GetId(void) const
Get the variant data.
Definition: Object_id_.hpp:270
@ e_not_set
No variant selected.
Definition: Object_id_.hpp:89
@ e_not_set
Modified on Wed Nov 29 02:22:59 2023 by modify_doxy.py rev. 669887