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

Go to the SVN repository for this file.

1 /* $Id: Auth_list.cpp 95805 2021-12-28 18:41:52Z stakhovv $
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 the following specifications:
34  * 'biblio.asn'.
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
42 
43 // generated includes
45 
46 // generated classes
47 
49 
50 BEGIN_objects_SCOPE // namespace ncbi::objects::
51 
52 // destructor
54 {
55 }
56 
57 
59 {
60  switch (GetNames().Which()) {
61  case TNames::e_not_set:
62  return 0;
63  case TNames::e_Std:
64  return GetNames().GetStd().size();
65  case TNames::e_Ml:
66  return GetNames().GetMl().size();
67  case TNames::e_Str:
68  return GetNames().GetStr().size();
69  }
70  return 0;
71 }
72 
73 
75 {
76  const C_Names& names = GetNames();
77  switch (names.Which()) {
78  case C_Names::e_not_set:
79  break;
80  case C_Names::e_Std:
81  if (!names.GetStd().empty()) {
82  return names.GetStd().front()->GetLabel(label, flags, eLabel_V1);
83  }
84  break;
85  case C_Names::e_Ml:
86  if (!names.GetMl().empty()) {
87  *label += names.GetMl().front();
88  return true;
89  }
90  break;
91  case C_Names::e_Str:
92  if (!names.GetStr().empty()) {
93  *label += names.GetStr().front();
94  return true;
95  }
96  break;
97  }
98 
99  return false;
100 }
101 
102 
104 {
105  const C_Names& names = GetNames();
106  string prefix;
107  unsigned int count = 0;
108 
109  switch (names.Which()) {
110  case C_Names::e_not_set:
111  return false;
112 
113  case C_Names::e_Std:
114  {
115  C_Names::TStd individuals;
116  for (const CRef<CAuthor>& it : names.GetStd()) {
117  switch (it->GetName().Which()) {
118  case CPerson_id::e_Name:
119  case CPerson_id::e_Ml:
120  case CPerson_id::e_Str:
121  if ((flags & fLabel_Consortia) == 0) {
122  individuals.push_back(it);
123  }
124  break;
126  if ((flags & fLabel_Consortia) != 0) {
127  if (it->GetLabel(label, flags, eLabel_V2)) {
128  ++count;
129  }
130  prefix = "; ";
131  }
132  break;
133  default:
134  break;
135  }
136  }
137 
138  if ((flags & fLabel_Consortia) == 0) {
139  ITERATE (C_Names::TStd, it, individuals) {
140  if (count > 0) {
141  if (&*it == &individuals.back()
142  && (flags & fLabel_FlatNCBI) != 0) {
143  prefix = " and ";
144  } else {
145  prefix = ", ";
146  }
147  }
148  *label += prefix;
149  if ((*it)->GetLabel(label, flags, eLabel_V2)) {
150  ++count;
151  } else if (NStr::EndsWith(*label, prefix)) { // It should!
152  label->resize(label->size() - prefix.size());
153  }
154  }
155  }
156 
157  break;
158  }
159 
160  case C_Names::e_Ml:
161  case C_Names::e_Str:
162  if ((flags & fLabel_Consortia) == 0) {
163  C_Names::TMl nl = names.IsMl() ? names.GetMl() : names.GetStr();
164  ITERATE (C_Names::TMl, it, nl) {
165  if (count > 0) {
166  if (&*it == &nl.back() && (flags & fLabel_FlatNCBI) != 0) {
167  prefix = " and ";
168  } else {
169  prefix = ", ";
170  }
171  }
172  *label += prefix;
173  if (CAuthor::x_GetLabelV2(label, flags, *it)) {
174  ++count;
175  } else if (NStr::EndsWith(*label, prefix)) { // It should!
176  label->resize(label->size() - prefix.size());
177  }
178  }
179  }
180  break;
181  }
182 
183  return count > 0;
184 }
185 
186 
187 void CAuth_list::ConvertMlToStandard(bool normalize_suffix)
188 {
189  if (!IsSetNames() || !GetNames().IsMl()) {
190  return;
191  }
192 
193  list<CRef<CAuthor>> standard_names;
194  for (const string& author_ml_str : GetNames().GetMl()) {
195  if (!NStr::IsBlank(author_ml_str)) {
196  CRef<CAuthor> new_auth = CAuthor::ConvertMlToStandard(author_ml_str, normalize_suffix);
197  standard_names.push_back(new_auth);
198  }
199  }
200  SetNames().Reset();
201  SetNames().SetStd().insert(SetNames().SetStd().begin(), standard_names.cbegin(), standard_names.cend());
202 }
203 
204 void CAuth_list::ConvertMlToStd(bool normalize_suffix)
205 {
206  if (IsSetNames()) {
207  if (GetNames().IsMl()) {
208  ConvertMlToStandard(normalize_suffix);
209  } else if (GetNames().IsStd()) {
210  for (CRef<CAuthor>& auth : SetNames().SetStd()) {
211  if (auth->IsSetName() && auth->GetName().IsMl()) {
212  auth = CAuthor::ConvertMlToStandard(*auth, normalize_suffix);
213  }
214  }
215  }
216  }
217 }
218 
219 string s_GetAuthorMatchString(const CAuthor& auth)
220 {
221  string comp;
222  if (!auth.IsSetName()) {
223  return comp;
224  }
225 
226  if (auth.GetName().IsName()) {
227  if (auth.GetName().GetName().IsSetLast()) {
228  comp = auth.GetName().GetName().GetLast();
229  }
230  } else if (auth.GetName().IsConsortium()) {
231  comp = auth.GetName().GetConsortium();
232  } else if (auth.GetName().IsStr()) {
233  comp = auth.GetName().GetStr();
234  }
235  return comp;
236 }
237 
238 
239 bool s_AuthorMatch(const CAuthor& auth1, const CAuthor& auth2)
240 {
241  string comp1 = s_GetAuthorMatchString(auth1);
242  string comp2 = s_GetAuthorMatchString(auth2);
243  return NStr::EqualNocase(comp1, comp2);
244 }
245 
246 
248 {
249  vector<string> list;
250 
251  if (names.IsStd()) {
252  for (const CRef<CAuthor>& it : names.GetStd()) {
253  list.push_back(s_GetAuthorMatchString(*it));
254  }
255  } else if (names.IsStr()) {
256  for (const string& it : names.GetStr()) {
257  list.push_back(it);
258  }
259  }
260  return list;
261 }
262 
263 
264 bool CAuth_list::SameCitation(const CAuth_list& other) const
265 {
266  if (!IsSetNames() && !other.IsSetNames()) {
267  return true;
268  } else if (!IsSetNames() || !other.IsSetNames()) {
269  return false;
270  } else if (GetNames().Which() == TNames::e_not_set &&
271  other.GetNames().Which() == TNames::e_not_set) {
272  return true;
273  } else if (GetNames().Which() != TNames::e_Std &&
274  GetNames().Which() != TNames::e_Str) {
275  return false;
276  } else if (other.GetNames().Which() != TNames::e_Std &&
277  other.GetNames().Which() != TNames::e_Str) {
278  return false;
279  }
280 
281  bool match = true;
282  const vector<string> match_str1 = GetAuthorMatchStrings(GetNames());
283  const vector<string> match_str2 = GetAuthorMatchStrings(other.GetNames());
284 
285  vector<string>::const_iterator it1 = match_str1.begin();
286  vector<string>::const_iterator it2 = match_str2.begin();
287  while (it1 != match_str1.end() && it2 != match_str2.end()) {
288  if (!NStr::EqualNocase(*it1, *it2)) {
289  match = false;
290  }
291  it1++;
292  it2++;
293  }
294  if (it1 != match_str1.end() || it2 != match_str2.end()) {
295  match = false;
296  }
297 
298  return match;
299 }
300 
301 
302 END_objects_SCOPE // namespace ncbi::objects::
303 
305 
306 /* Original file checksum: lines: 65, chars: 1889, CRC32: d99a2868 */
vector< string > GetAuthorMatchStrings(const CAuth_list::TNames &names)
Definition: Auth_list.cpp:247
string s_GetAuthorMatchString(const CAuthor &auth)
Definition: Auth_list.cpp:219
bool s_AuthorMatch(const CAuthor &auth1, const CAuthor &auth2)
Definition: Auth_list.cpp:239
@Auth_list.hpp User-defined methods of the data storage class.
Definition: Auth_list.hpp:57
void ConvertMlToStd(bool normalize_suffix)
Definition: Auth_list.cpp:204
void ConvertMlToStandard(bool normalize_suffix=false)
Definition: Auth_list.cpp:187
bool GetLabelV2(string *label, TLabelFlags flags) const override
Definition: Auth_list.cpp:103
bool GetLabelV1(string *label, TLabelFlags flags) const override
Definition: Auth_list.cpp:74
bool SameCitation(const CAuth_list &other) const
Definition: Auth_list.cpp:264
size_t GetNameCount() const
Definition: Auth_list.cpp:58
CAuthor –.
Definition: Author.hpp:59
static bool x_GetLabelV2(string *label, TLabelFlags flags, CTempString name, CTempString initials=kEmptyStr, CTempString suffix=kEmptyStr)
Definition: Author.cpp:94
static CRef< CAuthor > ConvertMlToStandard(const CAuthor &author, bool normalize_suffix=false)
Definition: Author.cpp:269
@ eLabel_V1
Traditional GetLabel semantics, modeled on the C Toolkit's PubLabelUnique.
@ eLabel_V2
New implementation, in line with GenBank/GenPept REFERENCE JOURNAL fields and the like.
int TLabelFlags
binary OR of ELabelFlags
@ fLabel_Consortia
Consortia, not authors [internal].
@ fLabel_FlatNCBI
For GenBank or GenPept [V2].
static uch flags
static const struct name_t names[]
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#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 EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
Definition: ncbistr.hpp:5430
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5353
static const char label[]
TStd & SetStd(void)
Select the variant.
Definition: Auth_list_.hpp:417
TNames & SetNames(void)
Assign a value to Names data member.
Definition: Auth_list_.hpp:488
const TName & GetName(void) const
Get the Name member data.
Definition: Author_.hpp:352
list< CRef< CAuthor > > TStd
Definition: Auth_list_.hpp:170
bool IsSetNames(void) const
Check if a value has been assigned to Names data member.
Definition: Auth_list_.hpp:464
void Reset(void)
Reset the whole object.
Definition: Auth_list_.cpp:52
bool IsSetName(void) const
Author, Primary or Secondary Check if a value has been assigned to Name data member.
Definition: Author_.hpp:340
const TStr & GetStr(void) const
Get the variant data.
Definition: Auth_list_.hpp:450
const TNames & GetNames(void) const
Get the Names member data.
Definition: Auth_list_.hpp:478
const TStd & GetStd(void) const
Get the variant data.
Definition: Auth_list_.hpp:410
const TMl & GetMl(void) const
Get the variant data.
Definition: Auth_list_.hpp:430
E_Choice Which(void) const
Which variant is currently selected.
Definition: Auth_list_.hpp:375
@ e_Ml
MEDLINE, semi-structured.
Definition: Auth_list_.hpp:114
@ e_Std
full citations
Definition: Auth_list_.hpp:113
@ e_not_set
No variant selected.
Definition: Auth_list_.hpp:112
const TStr & GetStr(void) const
Get the variant data.
Definition: Person_id_.hpp:391
bool IsConsortium(void) const
Check if variant Consortium is selected.
Definition: Person_id_.hpp:405
bool IsName(void) const
Check if variant Name is selected.
Definition: Person_id_.hpp:359
bool IsSetLast(void) const
Check if a value has been assigned to Last data member.
Definition: Name_std_.hpp:410
const TConsortium & GetConsortium(void) const
Get the variant data.
Definition: Person_id_.hpp:411
bool IsStr(void) const
Check if variant Str is selected.
Definition: Person_id_.hpp:385
const TLast & GetLast(void) const
Get the Last member data.
Definition: Name_std_.hpp:422
const TName & GetName(void) const
Get the variant data.
Definition: Person_id_.cpp:137
@ e_Ml
MEDLINE name (semi-structured) eg. "Jones RM".
Definition: Person_id_.hpp:97
@ e_Consortium
consortium name
Definition: Person_id_.hpp:99
@ e_Name
structured name
Definition: Person_id_.hpp:96
@ e_Str
unstructured name
Definition: Person_id_.hpp:98
static int match(register const pcre_uchar *eptr, register const pcre_uchar *ecode, const pcre_uchar *mstart, int offset_top, match_data *md, eptrblock *eptrb, unsigned int rdepth)
Definition: pcre_exec.c:513
static const char * prefix[]
Definition: pcregrep.c:405
Modified on Wed May 29 18:41:07 2024 by modify_doxy.py rev. 669887