NCBI C++ ToolKit
User_field_.cpp
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  * File Description:
27  * This code was generated by application DATATOOL
28  * using the following specifications:
29  * 'general.asn'.
30  *
31  * ATTENTION:
32  * Don't edit or commit this file into CVS as this file will
33  * be overridden (by DATATOOL) without warning!
34  * ===========================================================================
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
39 #include <serial/serialimpl.hpp>
40 
41 // generated includes
46 
47 BEGIN_objects_SCOPE // namespace ncbi::objects::
48 
49 
50 // generated classes
51 
53 {
54  if ( m_choice != e_not_set )
56 }
57 
59 {
60  switch ( m_choice ) {
61  case e_Os:
62  m_Os.Destruct();
63  break;
64  case e_Strs:
65  m_Strs.Destruct();
66  break;
67  case e_Ints:
68  m_Ints.Destruct();
69  break;
70  case e_Reals:
71  m_Reals.Destruct();
72  break;
73  case e_Oss:
74  {
75  for ( std::vector< std::vector< char >* >::iterator listIter1 = (*m_Oss).begin(); listIter1 != (*m_Oss).end(); ++listIter1 ) {
76  delete (*listIter1);
77  }
78  }
79  m_Oss.Destruct();
80  break;
81  case e_Fields:
82  m_Fields.Destruct();
83  break;
84  case e_Objects:
85  m_Objects.Destruct();
86  break;
87  case e_Str:
88  m_string_utf8.Destruct();
89  break;
90  case e_Object:
91  m_object->RemoveReference();
92  break;
93  default:
94  break;
95  }
96  m_choice = e_not_set;
97 }
98 
99 void CUser_field_Base::C_Data::DoSelect(E_Choice index, NCBI_NS_NCBI::CObjectMemoryPool* pool)
100 {
101  switch ( index ) {
102  case e_Int:
103  m_Int = 0;
104  break;
105  case e_Real:
106  m_Real = 0;
107  break;
108  case e_Bool:
109  m_Bool = 0;
110  break;
111  case e_Os:
112  m_Os.Construct();
113  break;
114  case e_Object:
115  (m_object = new(pool) ncbi::objects::CUser_object())->AddReference();
116  break;
117  case e_Strs:
118  m_Strs.Construct();
119  break;
120  case e_Ints:
121  m_Ints.Construct();
122  break;
123  case e_Reals:
124  m_Reals.Construct();
125  break;
126  case e_Oss:
127  m_Oss.Construct();
128  break;
129  case e_Fields:
130  m_Fields.Construct();
131  break;
132  case e_Objects:
133  m_Objects.Construct();
134  break;
135  case e_Str:
136  m_string_utf8.Construct();
137  break;
138  default:
139  break;
140  }
141  m_choice = index;
142 }
143 
144 const char* const CUser_field_Base::C_Data::sm_SelectionNames[] = {
145  "not set",
146  "str",
147  "int",
148  "real",
149  "bool",
150  "os",
151  "object",
152  "strs",
153  "ints",
154  "reals",
155  "oss",
156  "fields",
157  "objects"
158 };
159 
161 {
162  return NCBI_NS_NCBI::CInvalidChoiceSelection::GetName(index, sm_SelectionNames, sizeof(sm_SelectionNames)/sizeof(sm_SelectionNames[0]));
163 }
164 
166 {
167  throw NCBI_NS_NCBI::CInvalidChoiceSelection(DIAG_COMPILE_INFO, this, m_choice, index, sm_SelectionNames, sizeof(sm_SelectionNames)/sizeof(sm_SelectionNames[0]));
168 }
169 
171 {
172  Select(e_Str, NCBI_NS_NCBI::eDoNotResetVariant);
173  *m_string_utf8 = value;
174 }
175 
177 {
178  CheckSelected(e_Object);
179  return *static_cast<const TObject*>(m_object);
180 }
181 
183 {
184  Select(e_Object, NCBI_NS_NCBI::eDoNotResetVariant);
185  return *static_cast<TObject*>(m_object);
186 }
187 
189 {
190  TObject* ptr = &value;
191  if ( m_choice != e_Object || m_object != ptr ) {
192  ResetSelection();
193  (m_object = ptr)->AddReference();
194  m_choice = e_Object;
195  }
196 }
197 
198 // helper methods
199 
200 // type info
202 {
203  SET_INTERNAL_NAME("User-field", "data");
204  SET_CHOICE_MODULE("NCBI-General");
205  ADD_NAMED_BUF_CHOICE_VARIANT("str", m_string_utf8, CStringUTF8, ());
206  ADD_NAMED_STD_CHOICE_VARIANT("int", m_Int);
207  ADD_NAMED_STD_CHOICE_VARIANT("real", m_Real);
208  ADD_NAMED_STD_CHOICE_VARIANT("bool", m_Bool);
209  ADD_NAMED_BUF_CHOICE_VARIANT("os", m_Os, STL_CHAR_vector, (char));
210  ADD_NAMED_REF_CHOICE_VARIANT("object", m_object, CUser_object);
211  ADD_NAMED_BUF_CHOICE_VARIANT("strs", m_Strs, STL_vector, (CStringUTF8, ()));
212  ADD_NAMED_BUF_CHOICE_VARIANT("ints", m_Ints, STL_vector, (STD, (int)));
213  ADD_NAMED_BUF_CHOICE_VARIANT("reals", m_Reals, STL_vector, (STD, (double)));
214  ADD_NAMED_BUF_CHOICE_VARIANT("oss", m_Oss, STL_vector, (POINTER, (STL_CHAR_vector, (char))));
215  ADD_NAMED_BUF_CHOICE_VARIANT("fields", m_Fields, STL_vector, (STL_CRef, (CLASS, (CUser_field))));
216  ADD_NAMED_BUF_CHOICE_VARIANT("objects", m_Objects, STL_vector, (STL_CRef, (CLASS, (CUser_object))));
217  info->CodeVersion(22400);
218  info->DataSpec(ncbi::EDataSpec::eASN);
219 }
221 
222 // constructor
224  : m_choice(e_not_set)
225 {
226 }
227 
228 // destructor
230 {
231  Reset();
232 }
233 
234 
236 {
237  if ( !m_Label ) {
238  m_Label.Reset(new TLabel());
239  return;
240  }
241  (*m_Label).Reset();
242 }
243 
245 {
246  m_Label.Reset(&value);
247 }
248 
250 {
251  if ( !m_Data ) {
252  m_Data.Reset(new TData());
253  return;
254  }
255  (*m_Data).Reset();
256 }
257 
259 {
260  m_Data.Reset(&value);
261 }
262 
264 {
265  ResetLabel();
266  ResetNum();
267  ResetData();
268 }
269 
271 {
272  SET_CLASS_MODULE("NCBI-General");
274  ADD_NAMED_STD_MEMBER("num", m_Num)->SetSetFlag(MEMBER_PTR(m_set_State[0]))->SetOptional();
275  ADD_NAMED_REF_MEMBER("data", m_Data, C_Data);
276  info->RandomOrder();
277  info->CodeVersion(22400);
278  info->DataSpec(ncbi::EDataSpec::eASN);
279 }
281 
282 // constructor
284  : m_Num(0)
285 {
286  memset(m_set_State,0,sizeof(m_set_State));
287  if ( !IsAllocatedInPool() ) {
288  ResetLabel();
289  ResetData();
290  }
291 }
292 
293 // destructor
295 {
296 }
297 
298 
299 
300 END_objects_SCOPE // namespace ncbi::objects::
301 
303 
BEGIN_NAMED_BASE_CLASS_INFO("User-field", CUser_field)
BEGIN_NAMED_CHOICE_INFO("", CUser_field_Base::C_Data)
string
Definition: cgiapp.hpp:687
#define DIAG_COMPILE_INFO
Make compile time diagnostic information object to use in CNcbiDiag and CException.
Definition: ncbidiag.hpp:170
#define MEMBER_PTR(MemberName)
Definition: serialimpl.hpp:284
#define ADD_NAMED_REF_MEMBER(MemberAlias, MemberName, ClassName)
Definition: serialimpl.hpp:357
#define END_CLASS_INFO
Definition: serialimpl.hpp:456
#define ADD_NAMED_REF_CHOICE_VARIANT(MemberAlias, MemberName, ClassName)
Definition: serialimpl.hpp:400
#define ADD_NAMED_STD_MEMBER(MemberAlias, MemberName)
Definition: serialimpl.hpp:345
#define SET_CLASS_MODULE(ModuleName)
Definition: serialimpl.hpp:444
#define ADD_NAMED_STD_CHOICE_VARIANT(MemberAlias, MemberName)
Definition: serialimpl.hpp:388
#define END_CHOICE_INFO
Definition: serialimpl.hpp:506
#define SET_INTERNAL_NAME(OwnerName, MemberName)
Definition: serialimpl.hpp:447
#define SET_CHOICE_MODULE(ModuleName)
Definition: serialimpl.hpp:500
#define ADD_NAMED_BUF_CHOICE_VARIANT(MemberAlias, MemberName, TypeMacro, TypeMacroArgs)
Definition: serialimpl.hpp:385
@ eDoNotResetVariant
Definition: serialbase.hpp:78
void AddReference(void) const
Add reference to object.
Definition: ncbiobj.hpp:489
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
bool IsAllocatedInPool(void) const THROWS_NONE
Check if object is allocated in memory pool (not system heap)
Definition: ncbiobj.hpp:461
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
std::string CStringUTF8
Definition: ncbistl.hpp:254
void Reset(void)
Reset the whole object.
Definition: User_field_.cpp:52
static string SelectionName(E_Choice index)
Retrieve selection name (for diagnostic purposes).
void DoSelect(E_Choice index, CObjectMemoryPool *pool=0)
Definition: User_field_.cpp:99
TObject & SetObject(void)
Select the variant.
virtual void Reset(void)
Reset the whole object.
E_Choice
Choice variants.
void ResetLabel(void)
Reset Label data member.
Uint4 m_set_State[1]
void ResetSelection(void)
Reset the selection (set it to e_not_set).
Definition: User_field_.cpp:58
void ThrowInvalidSelection(E_Choice index) const
Throw 'InvalidSelection' exception.
CObject_id TLabel
static const char *const sm_SelectionNames[]
CRef< TData > m_Data
virtual ~CUser_field_Base(void)
TData & SetData(void)
Assign a value to Data data member.
TStr & SetStr(void)
Select the variant.
TLabel & SetLabel(void)
Assign a value to Label data member.
CRef< TLabel > m_Label
const TObject & GetObject(void) const
Get the variant data.
void ResetNum(void)
Reset Num data member.
void ResetData(void)
Reset Data data member.
@ e_not_set
No variant selected.
@ e_not_set
static MDB_envinfo info
Definition: mdb_load.c:37
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Modified on Sat May 25 14:17:50 2024 by modify_doxy.py rev. 669887