NCBI C++ ToolKit
citation_base.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef OBJECTS_BIBLIO___CITATION_BASE__HPP
2 #define OBJECTS_BIBLIO___CITATION_BASE__HPP
3 
4 /* $Id: citation_base.hpp 95832 2022-01-04 15:26:51Z stakhovv $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Aaron Ucko, Cliff Clausen
30  *
31  */
32 
33 /// @file citation_base.hpp
34 /// "Mix-in" interfaces to implement GetLabel for CCit_* et al.
35 
36 #include <corelib/ncbistd.hpp>
37 
39 
40 #ifndef BEGIN_objects_SCOPE
41 # define BEGIN_objects_SCOPE BEGIN_SCOPE(objects)
42 # define END_objects_SCOPE END_SCOPE(objects)
43 #endif
44 BEGIN_objects_SCOPE // namespace ncbi::objects::
45 
46 class CAuth_list;
47 class CDate;
48 class CImprint;
49 class CTitle;
50 class CCit_book;
51 class CCit_jour;
52 
53 /// Basic citation GetLabel interface, suitable both for actual
54 /// citation objects such as CCit_* and containers such as CPub.
56 {
57 public:
58  virtual ~IAbstractCitation() { }
59 
60  /// Flags for use by GetLabel methods.
61  enum ELabelFlags {
62  fLabel_Unique = 1 << 0, ///< Append a unique tag [V1]
63  fLabel_FlatNCBI = 1 << 1, ///< For GenBank or GenPept [V2]
64  fLabel_FlatEMBL = 1 << 2, ///< For EMBL or EMBLPept [V2]
65  fLabel_ISO_JTA = 1 << 3, ///< Only ISO jnl. title abbrevs. OK [V2]
66  fLabel_NoBadCitGen = 1 << 4, ///< Ignore "bad" Cit-gen data [V2]
67  fLabel_NoUnpubAffil = 1 << 5, ///< No affil on unpublished Cit-gen [V2]
68  fLabel_Consortia = 1 << 30 ///< Consortia, not authors [internal]
69  };
70  typedef int TLabelFlags; ///< binary OR of ELabelFlags
71 
73  /// Traditional GetLabel semantics, modeled on the C Toolkit's
74  /// PubLabelUnique. Version 1 labels typically indicate item
75  /// authorship, and optionally feature abbreviated item titles.
76  eLabel_V1 = 1,
77  /// New implementation, in line with GenBank/GenPept REFERENCE
78  /// JOURNAL fields and the like. One difference (among many!)
79  /// between version 1 and 2 labels is that the latter generally
80  /// leave off item-specific author and title information, which
81  /// would appear in neighboring flat-file fields.
82  eLabel_V2 = 2,
83  eLabel_MinVersion = eLabel_V1, ///< Minimum supported version
84  eLabel_DefaultVersion = eLabel_V1, ///< Current default version
85  eLabel_MaxVersion = eLabel_V2 ///< Maximum supported version
86  };
87 
88  /// Append a label to the specified string per the specified flags.
89  virtual bool GetLabel(string* label, TLabelFlags flags = 0,
90  ELabelVersion version = eLabel_DefaultVersion)
91  const = 0;
92 };
93 
94 
95 /// GetLabel interface for actual citation objects, as opposed to mere
96 /// containers such as CPub.
98 {
99 public:
100  bool GetLabel(string* label, TLabelFlags flags = 0,
101  ELabelVersion version = eLabel_DefaultVersion) const override;
102  // Historic variant
103  bool GetLabel(string* label, bool unique) const
104  { return GetLabel(label, unique ? fLabel_Unique : 0); }
105 
106  // Static utilities of interest to multiple implementations:
107 
108  /// Canonicalize a range of page numbers, expanding Medline-style
109  /// 125-35 -> 125-135, F124-34 -> F124-F134, and 12a-c -> 12a-12c, and
110  /// returning a single number (without a dash) for a single page.
111  /// Return orig_pages as is, modulo whitespace trimming, if unable to
112  /// parse as an ascending range in one of the above formats.
113  /// (In particular, do not attempt to parse Roman numerals.)
114  static string FixPages(const string& orig_pages);
115 
116  static string GetParenthesizedYear(const CDate& date);
117 
118  static bool HasText(const string& s)
119  { return s.find_first_not_of(" \t\n\r") != NPOS; }
120  static bool HasText(const string* s) { return s != NULL && HasText(*s); }
121 
122  static void MaybeAddSpace(string* label);
123 
124  static void NoteSup(string* label, const CImprint& imp);
125 
126  static bool SWNC(const string& str, const string& pfx)
127  { return NStr::StartsWith(str, pfx, NStr::eNocase); }
128 
129 protected:
130  virtual bool GetLabelV1(string* label, TLabelFlags flags) const = 0;
131  virtual bool GetLabelV2(string* label, TLabelFlags flags) const = 0;
132 
133  static bool x_GetLabelV1(string* label,
134  bool unique,
135  const CAuth_list* authors,
136  const CImprint* imprint,
137  const CTitle* title,
138  const CCit_book* book,
139  const CCit_jour* journal,
140  const string* title1 = 0,
141  const string* title2 = 0,
142  const string* titleunique = 0,
143  const string* date = 0,
144  const string* volume = 0,
145  const string* issue = 0,
146  const string* pages = 0,
147  bool unpublished = false);
148 };
149 
150 
151 inline
153 {
154  _ASSERT(label != NULL);
155  if ( !label->empty() && !NStr::EndsWith(*label, ' ') ) {
156  *label += ' ';
157  }
158 }
159 
160 END_objects_SCOPE
161 
163 
164 #endif /* OBJECTS_BIBLIO___CITATION_BASE__HPP */
@Auth_list.hpp User-defined methods of the data storage class.
Definition: Auth_list.hpp:57
Definition: Date.hpp:53
CImprint –.
Definition: Imprint.hpp:66
Definition: Title.hpp:51
Basic citation GetLabel interface, suitable both for actual citation objects such as CCit_* and conta...
virtual ~IAbstractCitation()
virtual bool GetLabel(string *label, TLabelFlags flags=0, ELabelVersion version=eLabel_DefaultVersion) const =0
Append a label to the specified string per the specified flags.
int TLabelFlags
binary OR of ELabelFlags
ELabelFlags
Flags for use by GetLabel methods.
GetLabel interface for actual citation objects, as opposed to mere containers such as CPub.
virtual bool GetLabelV2(string *label, TLabelFlags flags) const =0
virtual bool GetLabelV1(string *label, TLabelFlags flags) const =0
static bool HasText(const string &s)
static bool SWNC(const string &str, const string &pfx)
bool GetLabel(string *label, bool unique) const
static bool HasText(const string *s)
static void MaybeAddSpace(string *label)
Include a standard set of the NCBI C++ Toolkit most basic headers.
static uch flags
static const char * str(char *buf, int n)
Definition: stats.c:84
#define NULL
Definition: ncbistd.hpp:225
string GetLabel(const CSeq_id &id)
#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
#define NPOS
Definition: ncbistr.hpp:133
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5412
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
#define NCBI_BIBLIO_EXPORT
Definition: ncbi_export.h:312
static const char label[]
static int version
Definition: mdb_load.c:29
CRef< CPub > journal(ParserPtr pp, char *bptr, char *eptr, CRef< CAuth_list > &auth_list, CRef< CTitle::C_E > &title, bool has_muid, CRef< CCit_art > &cit_art, Int4 er)
Definition: ref.cpp:1452
#define _ASSERT
Modified on Wed Apr 17 13:09:23 2024 by modify_doxy.py rev. 669887