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

Go to the SVN repository for this file.

1 /* $Id: Taxon2_data.cpp 71482 2016-03-08 14:31:04Z bollin $
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: Michael Domrachev
27  *
28  * File Description:
29  * Taxon2_data is returned to caller in various taxonomy-related lookups
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using the following specifications:
34  * 'taxon1.asn'.
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
39 
40 // generated includes
42 
43 // generated classes
44 
46 
47 BEGIN_objects_SCOPE // namespace ncbi::objects::
48 
49 // destructor
51 {
52 }
53 
54 CTaxon2_data::TOrgProperties::iterator
55 CTaxon2_data::x_FindProperty( const string& name )
56 {
58  if( NStr::Equal( (*i)->GetDb(), name ) ) {
59  return i;
60  }
61  }
62  return m_props.end();
63 }
64 
65 CTaxon2_data::TOrgProperties::const_iterator
66 CTaxon2_data::x_FindPropertyConst( const string& name ) const
67 {
69  if( NStr::Equal( (*i)->GetDb(), name ) ) {
70  return i;
71  }
72  }
73  return m_props.end();
74 }
75 
76 void
77 CTaxon2_data::SetProperty( const string& name, const string& value )
78 {
79  if( !name.empty() ) {
80  TOrgProperties::iterator i = x_FindProperty( name );
81  if( i != m_props.end() ) {
82  (*i)->SetTag().SetStr( value );
83  } else {
84  CRef< CDbtag > pProp( new CDbtag );
85  pProp->SetDb( name );
86  pProp->SetTag().SetStr( value );
87  m_props.push_back( pProp );
88  }
89  }
90 }
91 
92 void
93 CTaxon2_data::SetProperty( const string& name, int value )
94 {
95  if( !name.empty() ) {
96  TOrgProperties::iterator i = x_FindProperty( name );
97  if( i != m_props.end() ) {
98  (*i)->SetTag().SetId( value );
99  } else {
100  CRef< CDbtag > pProp( new CDbtag );
101  pProp->SetDb( name );
102  pProp->SetTag().SetId( value );
103  m_props.push_back( pProp );
104  }
105  }
106 }
107 
108 void
109 CTaxon2_data::SetProperty( const string& name, bool value )
110 {
111  if( !name.empty() ) {
112  TOrgProperties::iterator i = x_FindProperty( name );
113  if( i != m_props.end() ) {
114  (*i)->SetTag().SetId( value ? 1 : 0 );
115  } else {
116  CRef< CDbtag > pProp( new CDbtag );
117  pProp->SetDb( name );
118  pProp->SetTag().SetId( value ? 1 : 0 );
119  m_props.push_back( pProp );
120  }
121  }
122 }
123 
124 bool
125 CTaxon2_data::GetProperty( const string& name, string& value ) const
126 {
127  if( !name.empty() ) {
128  TOrgProperties::const_iterator i = x_FindPropertyConst( name );
129  if( i != m_props.end() && (*i)->IsSetTag() ) {
130  switch( (*i)->GetTag().Which() ) {
131  case CObject_id::e_Str: value = (*i)->GetTag().GetStr(); return true;
132  case CObject_id::e_Id: value = NStr::IntToString( (*i)->GetTag().GetId() ); return true;
133  default: break; // unknown type
134  }
135  }
136  }
137  return false;
138 }
139 
140 bool
141 CTaxon2_data::GetProperty( const string& name, int& value ) const
142 {
143  if( !name.empty() ) {
144  TOrgProperties::const_iterator i = x_FindPropertyConst( name );
145  if( i != m_props.end() && (*i)->IsSetTag() ) {
146  switch( (*i)->GetTag().Which() ) {
147  case CObject_id::e_Str: value = NStr::StringToInt( (*i)->GetTag().GetStr(), NStr::fConvErr_NoThrow ); return true;
148  case CObject_id::e_Id: value = (*i)->GetTag().GetId(); return true;
149  default: break; // unknown type
150  }
151  }
152  }
153  return false;
154 }
155 
156 bool
157 CTaxon2_data::GetProperty( const string& name, bool& value ) const
158 {
159  if( !name.empty() ) {
160  TOrgProperties::const_iterator i = x_FindPropertyConst( name );
161  if( i != m_props.end() && (*i)->IsSetTag() ) {
162  switch( (*i)->GetTag().Which() ) {
163  case CObject_id::e_Str: value = NStr::StringToBool( (*i)->GetTag().GetStr() ); return true;
164  case CObject_id::e_Id: value = (*i)->GetTag().GetId() != 0; return true;
165  default: break; // unknown type
166  }
167  }
168  }
169  return false;
170 }
171 
172 void
173 CTaxon2_data::ResetProperty( const string& name )
174 {
175  TOrgProperties::iterator i = x_FindProperty( name );
176  while( i != m_props.end() ) {
177  m_props.erase(i);
178  i = x_FindProperty( name );
179  }
180 }
181 
182 END_objects_SCOPE // namespace ncbi::objects::
183 
185 
186 /* Original file checksum: lines: 57, chars: 1728, CRC32: 2b99c14d */
User-defined methods of the data storage class.
Definition: Dbtag.hpp:53
void ResetProperty(const string &name)
~CTaxon2_data(void)
Definition: Taxon2_data.cpp:50
TOrgProperties::const_iterator x_FindPropertyConst(const string &name) const
Definition: Taxon2_data.cpp:66
bool GetProperty(const string &name, string &value) const
void SetProperty(const string &name, const string &value)
Definition: Taxon2_data.cpp:77
TOrgProperties m_props
Definition: Taxon2_data.hpp:79
TOrgProperties::iterator x_FindProperty(const string &name)
Definition: Taxon2_data.cpp:55
list< CRef< CDbtag > > TOrgProperties
Definition: Taxon2_data.hpp:78
char value[7]
Definition: config.c:431
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static bool StringToBool(const CTempString str)
Convert string to bool.
Definition: ncbistr.cpp:2819
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5083
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
Definition: ncbistr.hpp:5383
@ fConvErr_NoThrow
Do not throw an exception on error.
Definition: ncbistr.hpp:285
void SetTag(TTag &value)
Assign a value to Tag data member.
Definition: Dbtag_.cpp:66
void SetDb(const TDb &value)
Assign a value to Db data member.
Definition: Dbtag_.hpp:229
int i
Modified on Tue Dec 05 02:06:11 2023 by modify_doxy.py rev. 669887