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

Go to the SVN repository for this file.

1 /* $Id: Blast_def_line.cpp 90544 2020-06-26 12:56:10Z grichenk $
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: Thomas W. Rackers (current versions of SetTaxIds/GetTaxIds)
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using the following specifications:
34  * 'blastdb.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 // DEPRECATED, use SetLeafTaxIds
55 void
57 {
58  // Clear the 'links' field. We may be setting new values there anyway.
59  ResetLinks();
60 
61  // Next step depends on size of input set.
62  if (t.empty()) {
63  // If it's empty, clear the 'taxid' field too.
64  ResetTaxid();
65  } else if (t.size() == 1) {
66  // Or if it has a single value, set 'taxid' to that value.
67  SetTaxid(*t.begin());
68  } else {
69  // Otherwise, set the 'taxid' field to the FIRST value in the set,
70  // UNLESS the following conditions are all met:
71  // (1) 'taxid' has a value;
72  // (2) that value is non-zero;
73  // (3) it's already present in the input set.
74  bool overwrite = true;
75  if (IsSetTaxid()) {
76  const TTaxid taxid = GetTaxid();
77  if (taxid != ZERO_TAX_ID) {
78  TTaxIds::iterator it = t.find(taxid);
79  if (it != t.end()) {
80  overwrite = false;
81  }
82  }
83  }
84  // If the above conditions were not met, overwrite the existing
85  // 'taxid'.
86  if (overwrite) {
87  SetTaxid(*t.begin());
88  }
89  // Save all of the input set to the 'links' field.
90  ITERATE(TTaxIds, itr, t) {
91  SetLinks().push_back(TAX_ID_TO(int, *itr));
92  }
93  }
94 }
95 
96 // DEPRECATED, use GetLeafTaxIds
99 {
100  TTaxIds retval; // set<TTaxId>, initially empty
101 
102  // If there's a 'taxid' value, add it to the result set.
103  if (CanGetTaxid()) {
104  TTaxid taxid = GetTaxid();
105  retval.insert(taxid);
106  }
107  // If there are any 'links' values, add them to the result set.
108  if (IsSetLinks()) {
109  TLinks taxids = GetLinks(); // see ASN.1 spec comment
110 #ifdef NCBI_STRICT_TAX_ID
111  ITERATE(TLinks, it, taxids) retval.insert(TAX_ID_FROM(int, *it));
112 #else
113  retval.insert(taxids.begin(), taxids.end());
114 #endif
115  }
116 
117  if(retval.size() > 1) {
118  retval.erase(ZERO_TAX_ID);
119  }
120 
121  // Remember, set containers guarantee that all members are unique,
122  // so if the 'taxid' and 'links' fields share a value, it will not
123  // be returned twice.
124 
125  // Return result set.
126  return retval;
127 }
128 
129 void
131 {
132  if (t.empty()) {
133  ResetLinks();
134  } else {
135 #ifdef NCBI_STRICT_TAX_ID
136  TLinks& links = SetLinks();
137  links.clear();
138  ITERATE(TTaxIds, it, t) {
139  links.push_back(TAX_ID_TO(int, *it));
140  }
141 #else
142  SetLinks().assign(t.begin(), t.end());
143 #endif
144  }
145 }
146 
149 {
150  TTaxIds retval; // set<int>, initially empty
151 
152  // If there are any 'links' values, add them to the result set.
153  if (IsSetLinks()) {
154  TLinks taxids = GetLinks(); // see ASN.1 spec comment
155 #ifdef NCBI_STRICT_TAX_ID
156  ITERATE(TLinks, it, taxids) retval.insert(TAX_ID_FROM(int, *it));
157 #else
158  retval.insert(taxids.begin(), taxids.end());
159 #endif
160  }
161 
162  // Return result set.
163  return retval;
164 }
165 
166 END_objects_SCOPE // namespace ncbi::objects::
167 
169 
170 /* Original file checksum: lines: 57, chars: 1739, CRC32: eaa77e11 */
User-defined methods of the data storage class.
TTaxIds GetLeafTaxIds() const
TTaxIds GetTaxIds() const
void SetTaxIds(const TTaxIds &t)
void SetLeafTaxIds(const TTaxIds &t)
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
parent_type::iterator iterator
Definition: set.hpp:80
size_type size() const
Definition: set.hpp:132
void erase(iterator pos)
Definition: set.hpp:151
#define ZERO_TAX_ID
Definition: ncbimisc.hpp:1115
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define TAX_ID_TO(T, tax_id)
Definition: ncbimisc.hpp:1110
#define TAX_ID_FROM(T, value)
Definition: ncbimisc.hpp:1111
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
TTaxid & SetTaxid(void)
Assign a value to Taxid data member.
bool IsSetLinks(void) const
Check if a value has been assigned to Links data member.
TTaxid GetTaxid(void) const
Get the Taxid member data.
bool CanGetTaxid(void) const
Check if it is safe to call GetTaxid method.
bool IsSetTaxid(void) const
Check if a value has been assigned to Taxid data member.
const TLinks & GetLinks(void) const
Get the Links member data.
void ResetLinks(void)
Reset Links data member.
NCBI_NS_NCBI::TTaxId TTaxid
TLinks & SetLinks(void)
Assign a value to Links data member.
void ResetTaxid(void)
Reset Taxid data member.
EIPRangeType t
Definition: ncbi_localip.c:101
Modified on Sat May 25 14:20:43 2024 by modify_doxy.py rev. 669887