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

Go to the SVN repository for this file.

1 /* $Id: PluginValue.cpp 17410 2008-07-25 20:59:32Z yazhuk $
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
44 
45 #include <serial/typeinfo.hpp>
46 
47 #include <gui/objutils/label.hpp>
48 
49 // generated classes
50 
52 
53 BEGIN_objects_SCOPE // namespace ncbi::objects::
54 
55 
56 // constructor
58 {
59 }
60 
61 
63 {
64  SetInteger(val);
65 }
66 
67 
69 {
70  SetDouble(val);
71 }
72 
73 
75 {
76  SetBoolean(val);
77 }
78 
79 
81 {
82  SetString(str);
83 }
84 
85 
87 {
88  SetProject(project);
89 }
90 
91 
93  const CGBProjectHandle* project,
94  const CDataHandle * dh)
95 {
96  SetObject(obj, project, dh);
97 }
98 
99 
101 {
102  SetObject(info);
103 }
104 
105 
106 // destructor
108 {
109 }
110 
111 
112 /// Print a copy of the value stored to the output stream
114 {
115  switch (Which()) {
116  case e_Integer: ostr << GetInteger(); break;
117  case e_Double: ostr << GetDouble(); break;
118  case e_String: ostr << GetString(); break;
119  case e_Secret_string: ostr << string(GetSecret_string().size(), '*'); break;
120  case e_Input_file: ostr << GetInput_file(); break;
121  case e_Output_file: ostr << GetOutput_file(); break;
122  case e_Boolean: ostr << GetBoolean(); break;
123 
124  case e_Project:
125  case e_DataHandle:
126  case e_Object:
127  {{
128  const CObject* obj = GetObject();
129  const CGBProjectHandle* handle = GetProject();
130  if (obj && handle) {
131  string s;
132  CLabel::GetLabel(*obj, &s, CLabel::eDefault, handle->GetScope());
133  ostr << s;
134  } else {
135  ostr << "[NULL]";
136  }
137  }}
138  break;
139 
140  default:
141  ostr << "[unhandled]";
142  break;
143  }
144 }
145 
146 
147 
149 {
150  return Tparent::SetInteger();
151 }
152 
153 
154 void CPluginValue::SetInteger(const string& val)
155 {
157 }
158 
159 
161 {
163 }
164 
165 
166 const string& CPluginValue::SetDouble()
167 {
168  return Tparent::SetDouble();
169 }
170 
171 
172 void CPluginValue::SetDouble(const string& val)
173 {
175 }
176 
177 
178 void CPluginValue::SetDouble(double val)
179 {
181 }
182 
183 
185 {
186  return Tparent::SetBoolean();
187 }
188 
189 
190 void CPluginValue::SetBoolean(const string& val)
191 {
193 }
194 
195 
197 {
199 }
200 
201 void CPluginValue::SetObject(const CObject& obj, const CGBProjectHandle* project, const CDataHandle * dh)
202 {
203  CPluginObject* obj_var = NULL;
204  if (dynamic_cast<const CGBProjectHandle*>(&obj)) {
205  obj_var = &Tparent::SetProject();
206  } else {
207  obj_var = &Tparent::SetObject();
208  }
209  if (obj_var) {
210  obj_var->SetObject(obj, project, dh);
211  }
212 }
213 
214 
215 void CPluginValue::SetObject(const string& type)
216 {
217  CPluginObject& obj_var = Tparent::SetObject();
218  obj_var.SetObject(type);
219 }
220 
221 
223 {
224  CPluginObject& obj_var = Tparent::SetObject();
225  obj_var.SetObject(info);
226 }
227 
228 
230 {
231  CPluginObject& obj_var = Tparent::SetProject();
232  obj_var.SetProject(&project);
233 }
234 
235 
237 {
238  CPluginObject& obj_var = Tparent::SetProject();
239  obj_var.SetProject(NULL);
240 }
241 
242 
243 const string& CPluginValue::GetObjectSubtype(void) const
244 {
245  if (IsProject()) {
246  return Tparent::GetProject().GetSubtype();
247  } else if (IsObject()) {
248  return Tparent::GetObject().GetSubtype();
249  }
250 
251  return kEmptyStr;
252 }
253 
254 
255 bool CPluginValue::AsBoolean(void) const
256 {
257  if ( !IsBoolean() ) {
258  NCBI_THROW(CPluginException, eInvalidArg,
259  "Attempt to access non-boolean value as boolean");
260  }
261 
262  const string& str = GetBoolean();
263  if (str.empty()) {
264  return false;
265  } else {
266  return NStr::StringToBool(GetBoolean());
267  }
268 }
269 
270 
271 int CPluginValue::AsInteger(void) const
272 {
273  if ( !IsInteger() ) {
274  NCBI_THROW(CPluginException, eInvalidArg,
275  "Attempt to access non-integer value as integer");
276  }
277 
278  if (GetInteger().empty()) {
279  NCBI_THROW(CPluginException, eInvalidArg,
280  "Attempt to access invalid integer value");
281  }
282 
283  return NStr::StringToInt(GetInteger());
284 }
285 
286 
287 double CPluginValue::AsDouble(void) const
288 {
289  if ( !IsDouble() ) {
290  NCBI_THROW(CPluginException, eInvalidArg,
291  "Attempt to access non-double value as double");
292  }
293 
294  if (GetDouble().empty()) {
295  NCBI_THROW(CPluginException, eInvalidArg,
296  "Attempt to access invalid double value");
297  }
298 
300 }
301 
302 
303 const string& CPluginValue::AsSecretString(void) const
304 {
305  if ( !IsSecret_string() ) {
306  NCBI_THROW(CPluginException, eInvalidArg,
307  "Attempt to access non-secret-string value as secret-string");
308  }
309 
310  if (GetSecret_string().empty()) {
311  NCBI_THROW(CPluginException, eInvalidArg,
312  "Attempt to access invalid secret-string value");
313  }
314 
315  return GetSecret_string();
316 }
317 
318 
319 const string& CPluginValue::AsString(void) const
320 {
321  switch (Which()) {
322  case e_Integer:
323  _TRACE("CPluginValue::AsString(): access to integer value as string");
324  return GetInteger();
325 
326  case e_Double:
327  _TRACE("CPluginValue::AsString(): access to double value as string");
328  return GetDouble();
329 
330  case e_Boolean:
331  _TRACE("CPluginValue::AsString(): access to boolean value as string");
332  return GetBoolean();
333 
334  case e_Input_file:
335  _TRACE("CPluginValue::AsString(): access to input file value as string");
336  return GetInput_file();
337 
338  case e_Output_file:
339  _TRACE("CPluginValue::AsString(): access to output file value as string");
340  return GetOutput_file();
341 
342  case e_String:
343  return GetString();
344 
345  case e_Secret_string:
346  return GetSecret_string();
347 
348  case e_Project:
349  case e_Object:
350  default:
351  NCBI_THROW(CPluginException, eInvalidArg,
352  "Attempt to access non-convertable value as string");
353  }
354 }
355 
356 
357 const string& CPluginValue::AsInputFile(void) const
358 {
359  if ( !IsInput_file() ) {
360  NCBI_THROW(CPluginException, eInvalidArg,
361  "Attempt to access non-file value as input file");
362  }
363 
364  if (GetInput_file().empty()) {
365  NCBI_THROW(CPluginException, eInvalidArg,
366  "Attempt to access invalid input file value");
367  }
368 
369  return GetInput_file();
370 }
371 
372 
373 const string& CPluginValue::AsOutputFile(void) const
374 {
375  if ( !IsOutput_file() ) {
376  NCBI_THROW(CPluginException, eInvalidArg,
377  "Attempt to access non-file value as output file");
378  }
379 
380  if (GetOutput_file().empty()) {
381  NCBI_THROW(CPluginException, eInvalidArg,
382  "Attempt to access invalid output file value");
383  }
384 
385  return GetOutput_file();
386 }
387 
388 
390 {
391  if (IsProject()) {
392  if (GetProject()) {
393  return *GetProject();
394  }
395  NCBI_THROW(CPluginException, eInvalidArg,
396  "Attempt to access NULL document");
397  }
398  NCBI_THROW(CPluginException, eInvalidArg,
399  "Attempt to access non-document value as document");
400 }
401 
402 
403 const CObject& CPluginValue::AsObject(void) const
404 {
405  if (IsObject()) {
406  if (GetObject()) {
407  return *GetObject();
408  }
409  NCBI_THROW(CPluginException, eInvalidArg,
410  "Attempt to access NULL object");
411  }
412  NCBI_THROW(CPluginException, eInvalidArg,
413  "Attempt to access non-object value as object");
414 }
415 
416 
417 //
418 // determine if this URL is empty
419 //
420 bool CPluginValue::IsEmpty(void) const
421 {
422  switch (Which()) {
423  case e_String:
424  return (IsString() && GetString().empty());
425 
426  case e_Secret_string:
427  return (IsSecret_string() && GetSecret_string().empty());
428 
429  case e_Input_file:
430  return (IsInput_file() && GetInput_file().empty());
431 
432  case e_Output_file:
433  return (IsOutput_file() && GetOutput_file().empty());
434 
435  case e_Integer:
436  return (IsInteger() && GetInteger().empty());
437 
438  case e_Double:
439  return (IsDouble() && GetDouble().empty());
440 
441  case e_Boolean:
442  return (IsBoolean() && GetBoolean().empty());
443 
444  case e_Object:
445  return (IsObject() && Tparent::GetObject().IsEmpty());
446 
447  case e_Project:
448  return (IsProject() && Tparent::GetProject().IsEmpty());
449 
450  default:
451  // unhandled = always invalid, always empty
452  return true;
453  }
454 }
455 
456 
457 END_objects_SCOPE // namespace ncbi::objects::
458 
460 
461 /* Original file checksum: lines: 64, chars: 1864, CRC32: 5ef4a2cd */
virtual CScope * GetScope() const
CObject –.
Definition: ncbiobj.hpp:180
namespace ncbi::objects::
void SetObject(const string &type)
void SetProject(const CGBProjectHandle *doc)
int AsInteger(void) const
void SetProject(void)
setters for object arguments
double AsDouble(void) const
CPluginValue(void)
default constructor
Definition: PluginValue.cpp:57
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()
bool IsEmpty(void) const
determine if this argument has an empty value
void Print(CNcbiOstream &ostr) const
Print a copy of the value stored to the output stream.
const CGBProjectHandle * GetProject(void) const
Special accessor for the implied or actual document.
~CPluginValue(void)
destructor
const string & SetDouble()
const string & AsSecretString(void) const
const string & GetObjectSubtype(void) const
Special accessor for any named object subtype.
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
string
Definition: cgiapp.hpp:687
#define NULL
Definition: ncbistd.hpp:225
#define _TRACE(message)
Definition: ncbidbg.hpp:122
#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
static void GetLabel(const CObject &obj, string *label, ELabelType type=eDefault)
Definition: label.cpp:140
@ eDefault
Definition: label.hpp:73
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
static bool StringToBool(const CTempString str)
Convert string to bool.
Definition: ncbistr.cpp:2819
static string DoubleToString(double value, int precision=-1, TNumToStringFlags flags=0)
Convert double to string.
Definition: ncbistr.hpp:5187
#define kEmptyStr
Definition: ncbistr.hpp:123
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static double StringToDouble(const CTempStringEx str, TStringToNumFlags flags=0)
Convert string to double.
Definition: ncbistr.cpp:1387
static const string BoolToString(bool value)
Convert bool to string.
Definition: ncbistr.cpp:2813
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
bool IsBoolean(void) const
Check if variant Boolean is selected.
bool IsDouble(void) const
Check if variant Double is selected.
const TInteger & GetInteger(void) const
Get the variant data.
TObject & SetObject(void)
Select the variant.
const TSubtype & GetSubtype(void) const
Get the Subtype member data.
bool IsSecret_string(void) const
Check if variant Secret_string is selected.
bool IsInput_file(void) const
Check if variant Input_file is selected.
const TDouble & GetDouble(void) const
Get the variant data.
const TProject & GetProject(void) const
Get the variant data.
bool IsObject(void) const
Check if variant Object is selected.
E_Choice Which(void) const
Which variant is currently selected.
const TString & GetString(void) const
Get the variant data.
const TSecret_string & GetSecret_string(void) const
Get the variant data.
bool IsProject(void) const
Check if variant Project is selected.
bool IsString(void) const
Check if variant String is selected.
TBoolean & SetBoolean(void)
Select the variant.
TString & SetString(void)
Select the variant.
const TInput_file & GetInput_file(void) const
Get the variant data.
TDouble & SetDouble(void)
Select the variant.
TProject & SetProject(void)
Select the variant.
const TBoolean & GetBoolean(void) const
Get the variant data.
const TOutput_file & GetOutput_file(void) const
Get the variant data.
bool IsOutput_file(void) const
Check if variant Output_file is selected.
const TObject & GetObject(void) const
Get the variant data.
TInteger & SetInteger(void)
Select the variant.
bool IsInteger(void) const
Check if variant Integer is selected.
static MDB_envinfo info
Definition: mdb_load.c:37
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::SIZE size
static const char * str(char *buf, int n)
Definition: stats.c:84
Definition: type.c:6
Modified on Wed Mar 27 11:18:34 2024 by modify_doxy.py rev. 669887