NCBI C++ ToolKit
PluginArg.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: PluginArg.cpp 30280 2014-04-23 20:28:26Z katargir $
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  * 'plugin.asn'.
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
40 
41 // generated includes
47 
48 #include <objects/seq/Bioseq.hpp>
57 
58 #include <serial/iterator.hpp>
59 
60 // generated classes
61 
63 
64 BEGIN_objects_SCOPE // namespace ncbi::objects::
65 
66 // destructor
68 {
69 }
70 
71 
72 // access the type for this argument
74 {
76  if (GetData().IsSingle()) {
77  choice = GetData().GetSingle().Which();
78  } else if (GetData().IsArray() &&
79  GetData().GetArray().size() != 0) {
80  choice = GetData().GetArray().front()->Which();
81  }
82 
83  switch (choice) {
85  return eInteger;
87  return eDouble;
89  return eBoolean;
91  return eString;
93  return eSecretString;
95  return eProject;
97  return eObject;
99  return eInputFile;
101  return eOutputFile;
102 
103  default:
104  return eNotSet;
105  }
106 }
107 
108 // accessors for specific sub-components
110 {
111  if (GetData().IsSingle()) {
112  return GetData().GetSingle().GetProject();
113  } else {
114  return GetData().GetArray().front()->GetProject();
115  }
116 }
117 
118 const CObject* CPluginArg::GetObject(void) const
119 {
120  if (GetData().IsSingle()) {
121  return GetData().GetSingle().GetObject();
122  } else {
123  return GetData().GetArray().front()->GetObject();
124  }
125 }
126 
127 
128 const string& CPluginArg::GetObjectSubtype(void) const
129 {
130  if (GetData().IsSingle()) {
131  return GetData().GetSingle().GetObjectSubtype();
132  } else {
133  return GetData().GetArray().front()->GetObjectSubtype();
134  }
135 }
136 
137 
138 bool CPluginArg::IsEmpty(void) const
139 {
141  for ( ; iter; ++iter) {
142  if ( !iter->IsEmpty() ) {
143  return false;
144  }
145  }
146 
147  return true;
148 }
149 
150 
152 {
153  switch (GetType()) {
154  default:
155  break;
156 
157  case eProject:
158  if (GetData().IsSingle()) {
159  ResetData();
160  SetProject();
161  } else {
162  ResetData();
163  SetProject();
164  SetList();
165  }
166  break;
167 
168  case eObject:
169  {{
170  string subtype = GetObjectSubtype();
171 
172  if (GetData().IsSingle()) {
173  ResetData();
174  SetObject(subtype);
175  } else {
176  ResetData();
177  SetObject(subtype);
178  SetList();
179  }
180  }}
181  break;
182  }
183 }
184 
185 
186 //
187 // integer handlers
188 //
189 
191 {
192  SetData().Reset();
194 }
195 
196 
197 void CPluginArg::SetInteger(const string& arg)
198 {
199  SetData().Reset();
200  SetData().SetSingle().SetInteger(arg);
201 }
202 
203 
205 {
206  SetData().Reset();
207  SetData().SetSingle().SetInteger(arg);
208 }
209 
210 
211 void CPluginArg::SetInteger(const list<int>& int_list)
212 {
213  SetData().Reset();
214  ITERATE (list<int>, iter, int_list) {
216  value->SetInteger(*iter);
217  SetData().SetArray().push_back(value);
218  }
219 }
220 
221 
222 int CPluginArg::AsInteger(void) const
223 {
224  if ( !GetData().IsSingle() ) {
225  NCBI_THROW(CPluginException, eInvalidArg,
226  "Attempt to cast array argument to single object");
227  }
228 
229  return GetData().GetSingle().AsInteger();
230 }
231 
232 
233 //
234 // double handlers
235 //
236 
238 {
239  SetData().Reset();
241 }
242 
243 
244 void CPluginArg::SetDouble(const string& arg)
245 {
246  SetData().Reset();
247  SetData().SetSingle().SetDouble(arg);
248 }
249 
250 
251 void CPluginArg::SetDouble(double arg)
252 {
253  SetData().Reset();
254  SetData().SetSingle().SetDouble(arg);
255 }
256 
257 
258 void CPluginArg::SetDouble(const list<double>& double_list)
259 {
260  SetData().Reset();
261  ITERATE (list<double>, iter, double_list) {
263  value->SetDouble(*iter);
264  SetData().SetArray().push_back(value);
265  }
266 }
267 
268 
269 double CPluginArg::AsDouble(void) const
270 {
271  if ( !GetData().IsSingle() ) {
272  NCBI_THROW(CPluginException, eInvalidArg,
273  "Attempt to cast array argument to single object");
274  }
275 
276  return GetData().GetSingle().AsDouble();
277 }
278 
279 
280 //
281 // boolean handlers
282 //
283 
285 {
286  SetData().Reset();
288 }
289 
290 
292 {
293  SetData().Reset();
294  SetData().SetSingle().SetBoolean(arg);
295 }
296 
297 
298 void CPluginArg::SetBoolean(const list<bool>& bool_list)
299 {
300  SetData().Reset();
301  ITERATE (list<bool>, iter, bool_list) {
303  value->SetBoolean(*iter);
304  SetData().SetArray().push_back(value);
305  }
306 }
307 
308 
309 bool CPluginArg::AsBoolean(void) const
310 {
311  if ( !GetData().IsSingle() ) {
312  NCBI_THROW(CPluginException, eInvalidArg,
313  "Attempt to cast array argument to single object");
314  }
315 
316  return GetData().GetSingle().AsBoolean();
317 }
318 
319 
320 //
321 // string handlers
322 //
323 
325 {
326  SetData().Reset();
328 }
329 
330 
331 void CPluginArg::SetString(const string& arg)
332 {
333  SetData().Reset();
334  SetData().SetSingle().SetString(arg);
335 }
336 
337 
338 void CPluginArg::SetString(const list<string>& string_list)
339 {
340  SetData().Reset();
341  ITERATE (list<string>, iter, string_list) {
343  value->SetString(*iter);
344  SetData().SetArray().push_back(value);
345  }
346 }
347 
348 
349 const string& CPluginArg::AsString(void) const
350 {
351  if ( !GetData().IsSingle() ) {
352  NCBI_THROW(CPluginException, eInvalidArg,
353  "Attempt to cast array argument to single object");
354  }
355 
356  return GetData().GetSingle().AsString();
357 }
358 
359 
360 //
361 // secret string handlers
362 //
363 
365 {
366  SetData().Reset();
368 }
369 
370 
371 void CPluginArg::SetSecretString(const string& arg)
372 {
373  SetData().Reset();
375 }
376 
377 
378 void CPluginArg::SetSecretString(const list<string>& string_list)
379 {
380  SetData().Reset();
381  ITERATE (list<string>, iter, string_list) {
383  value->SetSecret_string(*iter);
384  SetData().SetArray().push_back(value);
385  }
386 }
387 
388 
389 const string& CPluginArg::AsSecretString(void) const
390 {
391  if ( !GetData().IsSingle() ) {
392  NCBI_THROW(CPluginException, eInvalidArg,
393  "Attempt to cast array argument to single object");
394  }
395 
396  return GetData().GetSingle().AsSecretString();
397 }
398 
399 
400 //
401 // file handlers
402 //
403 
405 {
406  SetData().Reset();
408 }
409 
410 
411 void CPluginArg::SetInputFile(const string& arg)
412 {
413  SetData().Reset();
415 }
416 
417 
418 void CPluginArg::SetInputFile(const list<string>& file_list)
419 {
420  SetData().Reset();
421  ITERATE (list<string>, iter, file_list) {
423  value->SetInput_file(*iter);
424  SetData().SetArray().push_back(value);
425  }
426 }
427 
428 
429 const string& CPluginArg::AsInputFile(void) const
430 {
431  if ( !GetData().IsSingle() ) {
432  NCBI_THROW(CPluginException, eInvalidArg,
433  "Attempt to cast array argument to single object");
434  }
435 
436  return GetData().GetSingle().AsInputFile();
437 }
438 
439 
441 {
442  SetData().Reset();
444 }
445 
446 
447 void CPluginArg::SetOutputFile(const string& arg)
448 {
449  SetData().Reset();
451 }
452 
453 
454 void CPluginArg::SetOutputFile(const list<string>& file_list)
455 {
456  SetData().Reset();
457  ITERATE (list<string>, iter, file_list) {
459  value->SetOutput_file(*iter);
460  SetData().SetArray().push_back(value);
461  }
462 }
463 
464 
465 const string& CPluginArg::AsOutputFile(void) const
466 {
467  if ( !GetData().IsSingle() ) {
468  NCBI_THROW(CPluginException, eInvalidArg,
469  "Attempt to cast array argument to single object");
470  }
471 
472  return GetData().GetSingle().AsOutputFile();
473 }
474 
475 
476 //
477 // document handlers
478 //
479 
481 {
482  SetData().Reset();
484  value.SetProject();
485 }
486 
487 
489 {
490  SetData().Reset();
491  SetData().SetSingle().SetProject(arg);
492 }
493 
494 
495 void CPluginArg::SetProject(const TValues& Project_list)
496 {
497  SetData().Reset();
498  ITERATE (TValues, iter, Project_list) {
500  value->SetProject((*iter)->AsProject());
501  SetData().SetArray().push_back(value);
502  }
503 }
504 
505 
507 {
508  if ( !GetData().IsSingle() ) {
509  NCBI_THROW(CPluginException, eInvalidArg,
510  "Attempt to cast array argument to single object");
511  }
512 
513  return GetData().GetSingle().AsProject();
514 }
515 
516 
517 //
518 // object handlers
519 //
520 
521 void CPluginArg::SetObject(const string& type)
522 {
523  SetData().Reset();
525 }
526 
527 
529 {
530  SetData().Reset();
532 }
533 
534 
535 void CPluginArg::SetObject(const CObject& obj, const CGBProjectHandle* doc, const CDataHandle * dh)
536 {
537  SetData().Reset();
538  SetData().SetSingle().SetObject(obj, doc, dh);
539 }
540 
541 
542 void CPluginArg::SetObject(const TValues& obj_list)
543 {
544  SetData().Reset();
545  ITERATE (TValues, iter, obj_list) {
546  SetData().SetArray().push_back
547  (CRef<CPluginValue> (const_cast<CPluginValue*>(iter->GetPointer())));
548  }
549 }
550 
551 
552 const CObject& CPluginArg::AsObject(void) const
553 {
554  if ( !GetData().IsSingle() ) {
555  NCBI_THROW(CPluginException, eInvalidArg,
556  "Attempt to cast array argument to single object");
557  }
558 
559  return GetData().GetSingle().AsObject();
560 }
561 
562 
563 //
564 // generic list accessors
565 //
566 
568 {
569  if (GetData().IsSingle()) {
570  CRef<CPluginValue> value(&SetData().SetSingle());
571  SetData().Reset();
572  SetData().SetArray().push_back(value);
573  }
574 }
575 
576 
577 void CPluginArg::SetList(const TValues& args)
578 {
579  SetData().Reset();
580  SetData().SetArray();
581  ITERATE (TValues, iter, args) {
582  CPluginValue* value = const_cast<CPluginValue*> (iter->GetPointer());
583  SetData().SetArray().push_back( CRef<CPluginValue>(value));
584  }
585 }
586 
587 
588 void CPluginArg::AsList(TValues& arg) const
589 {
590  if ( !GetData().IsArray() ) {
591  NCBI_THROW(CPluginException, eInvalidArg,
592  "Attempt to cast single argument to array");
593  }
594 
595  arg.clear();
596  ITERATE (TData::TArray, iter, GetData().GetArray()) {
597  arg.push_back(*iter);
598  }
599 }
600 
601 
602 END_objects_SCOPE // namespace ncbi::objects::
603 
605 
606 /* Original file checksum: lines: 64, chars: 1879, CRC32: 6874a1e4 */
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CObject –.
Definition: ncbiobj.hpp:180
const string & AsOutputFile(void) const
Definition: PluginArg.cpp:465
void ClearObjects()
clear any objects from object-based arguments
Definition: PluginArg.cpp:151
bool IsEmpty(void) const
determine if this argument is empty (i.e., has all type information but no values)
Definition: PluginArg.cpp:138
EType
enumerated list of types we support
Definition: PluginArg.hpp:69
const CObject & AsObject(void) const
Definition: PluginArg.cpp:552
list< CConstRef< CPluginValue > > TValues
typedefs for collections of argument types CPluginValue supports type-specific data retrieval of sing...
Definition: PluginArg.hpp:92
void SetInputFile(void)
set this argument as an input file
Definition: PluginArg.cpp:404
const string & AsSecretString(void) const
Definition: PluginArg.cpp:389
const string & AsString(void) const
Definition: PluginArg.cpp:349
void AsList(TValues &values) const
Definition: PluginArg.cpp:588
void SetList(void)
insure that this argument can accept a list of its current type
Definition: PluginArg.cpp:567
EType GetType(void) const
access the type for this argument
Definition: PluginArg.cpp:73
const string & GetObjectSubtype(void) const
accessor for the object-specific type info in the event the data type is list, the type info for the ...
Definition: PluginArg.cpp:128
void SetBoolean(void)
set this argument as an integer
Definition: PluginArg.cpp:284
void SetDouble(void)
set this argument as a double
Definition: PluginArg.cpp:237
const string & AsInputFile(void) const
Definition: PluginArg.cpp:429
void SetProject(void)
set this argument as a CGBProjectHandle
Definition: PluginArg.cpp:480
void SetString(void)
set this argument as a string
Definition: PluginArg.cpp:324
const CObject * GetObject(void) const
Definition: PluginArg.cpp:118
void SetInteger(void)
set this argument as an integer
Definition: PluginArg.cpp:190
void SetOutputFile(void)
set this argument as an output file
Definition: PluginArg.cpp:440
void SetSecretString(void)
set this argument as a secret string
Definition: PluginArg.cpp:364
bool AsBoolean(void) const
Definition: PluginArg.cpp:309
const CGBProjectHandle * GetProject(void) const
accessors for specific sub-components in the event that the data type is list, NULL is returned
Definition: PluginArg.cpp:109
void SetObject(const string &type)
set this argument as a CObject.
Definition: PluginArg.cpp:521
double AsDouble(void) const
Definition: PluginArg.cpp:269
int AsInteger(void) const
Definition: PluginArg.cpp:222
~CPluginArg(void)
destructor
Definition: PluginArg.cpp:67
const CGBProjectHandle & AsProject(void) const
Definition: PluginArg.cpp:506
int AsInteger(void) const
void SetProject(void)
setters for object arguments
double AsDouble(void) const
const string & AsString(void) const
const CObject & AsObject(void) const
bool AsBoolean(void) const
const CGBProjectHandle & AsProject(void) const
const string & AsOutputFile(void) const
const CObject * GetObject(void) const
Special accessor for the stored object.
const string & AsInputFile(void) const
const string & SetInteger()
type-specific setters
const string & SetBoolean()
const CGBProjectHandle * GetProject(void) const
Special accessor for the implied or actual document.
const string & SetDouble()
void SetObject(const CObject &obj, const CGBProjectHandle *doc=NULL, const CDataHandle *dh=NULL)
const string & AsSecretString(void) const
const string & GetObjectSubtype(void) const
Special accessor for any named object subtype.
CRef –.
Definition: ncbiobj.hpp:618
Template class for iteration on objects of class C (non-medifiable version)
Definition: iterator.hpp:767
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
TOutput_file & SetOutput_file(void)
Select the variant.
const TArray & GetArray(void) const
Get the variant data.
Definition: PluginArg_.hpp:644
E_Choice Which(void) const
Which variant is currently selected.
TSecret_string & SetSecret_string(void)
Select the variant.
void ResetData(void)
Reset Data data member.
Definition: PluginArg_.cpp:171
TData & SetData(void)
Assign a value to Data data member.
Definition: PluginArg_.hpp:970
TString & SetString(void)
Select the variant.
TArray & SetArray(void)
Select the variant.
Definition: PluginArg_.hpp:651
TInput_file & SetInput_file(void)
Select the variant.
void Reset(void)
Reset the whole object.
Definition: PluginArg_.cpp:52
E_Choice
Choice variants.
TSingle & SetSingle(void)
Select the variant.
Definition: PluginArg_.cpp:110
const TSingle & GetSingle(void) const
Get the variant data.
Definition: PluginArg_.cpp:104
const TData & GetData(void) const
Get the Data member data.
Definition: PluginArg_.hpp:961
list< CRef< CPluginValue > > TArray
Definition: PluginArg_.hpp:174
@ e_not_set
No variant selected.
static MDB_envinfo info
Definition: mdb_load.c:37
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Definition: type.c:6
Modified on Fri Sep 20 14:57:42 2024 by modify_doxy.py rev. 669887