1 /* $Id: Cit_gen.cpp 498027 2016-04-12 18:56:44Z 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:  .......
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  *   'biblio.asn'.
35  */
36 
37 // standard includes
38 
39 // generated includes
40 #include <ncbi_pch.hpp>
41 #include <objects/biblio/Cit_gen.hpp>
42 #include <objects/general/Date.hpp>
43 
44 // generated classes
45 
46 BEGIN_NCBI_SCOPE
47 
48 BEGIN_objects_SCOPE // namespace ncbi::objects::
49 
50 // destructor
~CCit_gen(void)51 CCit_gen::~CCit_gen(void)
52 {
53 }
54 
55 
GetLabelV1(string * label,TLabelFlags flags) const56 bool CCit_gen::GetLabelV1(string* label, TLabelFlags flags) const
57 {
58     bool unique = (flags & fLabel_Unique) != 0;
59 
60     if (IsSetSerial_number()) {
61         *label += "[" + NStr::IntToString(GetSerial_number()) + "]";
62     }
63     if (IsSetMuid()) {
64         *label += "NLM" + NStr::NumericToString(GetMuid());
65     }
66 
67     string date;
68     string* date_ptr = 0;
69     if ( IsSetDate() ) {
70         date_ptr = &date;
71         GetDate().GetDate(date_ptr, true);
72     }
73 
74     const string* title2 = 0;
75     const string* titleunique = 0;
76     bool unpublished = false;
77     const CTitle* title = IsSetJournal() ? &GetJournal() : 0;
78     const CAuth_list* authors = IsSetAuthors() ? &GetAuthors() : 0;
79     const string* volume = IsSetVolume() ? &GetVolume() : 0;
80     const string* issue = IsSetIssue() ? &GetIssue() : 0;
81     const string* pages = IsSetPages() ? &GetPages() : 0;
82 
83     if (IsSetCit()) {
84         if ( NStr::EqualNocase( GetCit(), "Unpublished") ) {
85             unpublished = true;
86         } else if (!title) {
87             title2 = &GetCit();
88         }
89     }
90     if (IsSetTitle()) {
91         titleunique = &GetTitle();
92     } else if (title2) {
93         titleunique = title2;
94     } else if (!title && IsSetCit()) {
95         titleunique = &GetCit();
96     }
97     if (!title && !authors && !IsSetTitle() && !volume &&
98         !pages && !issue) {
99         titleunique = 0;
100         if (IsSetCit()) {
101             string cit(GetCit());
102             if (!unique) {
103                 try {
104                     cit.resize(cit.find_last_of('|'));
105                 } catch(length_error&) {}
106             }
107             *label += cit;
108         }
109         return true;
110     }
111 
112     return x_GetLabelV1(label, unique,
113         authors, 0, title, 0, 0, 0, title2, titleunique,
114         date_ptr, volume, issue, pages, unpublished);
115 }
116 
117 
118 // Based on FormatCitGen from the C Toolkit's api/asn2gnb5.c.
GetLabelV2(string * label,TLabelFlags flags) const119 bool CCit_gen::GetLabelV2(string* label, TLabelFlags flags) const
120 {
121     if ( !CanGetCit()  &&  !CanGetJournal()  &&  !CanGetDate()
122         &&  CanGetSerial_number() ) {
123         return false;
124     }
125 
126     if ( !CanGetJournal()  &&  CanGetCit()  &&  SWNC(GetCit(), "unpublished")) {
127         if ((flags & fLabel_NoUnpubAffil) != 0) {
128             MaybeAddSpace(label);
129             *label += "Unpublished";
130             return true;
131         }
132 
133         if (CanGetAuthors()  &&  GetAuthors().CanGetAffil()) {
134             MaybeAddSpace(label);
135             *label += "Unpublished ";
136             GetAuthors().GetAffil().GetLabel(label, flags, eLabel_V2);
137             NStr::TruncateSpacesInPlace(*label, NStr::eTrunc_End);
138             return true;
139         }
140 
141         if (CanGetCit()  &&  HasText(GetCit())) {
142             MaybeAddSpace(label);
143             *label += NStr::TruncateSpaces(GetCit());
144             return true;
145         } else {
146             return false;
147         }
148     }
149 
150     string year  = CanGetDate()  ? GetParenthesizedYear(GetDate()) : kEmptyStr;
151     string pages = CanGetPages() ? FixPages(GetPages())            : kEmptyStr;
152     string journal, inpress;
153     SIZE_TYPE pos;
154 
155     if (CanGetJournal()) {
156         journal = GetJournal().GetTitle();
157     }
158 
159     if (CanGetCit()) {
160         pos = GetCit().find("Journal=\"");
161         if (pos != NPOS) {
162             journal = GetCit().substr(pos + 9);
163         } else if (SWNC(GetCit(), "submitted")
164                    ||  SWNC(GetCit(), "unpublished")) {
165             if ((flags & fLabel_NoBadCitGen) == 0  ||  !journal.empty()) {
166                 inpress = GetCit();
167             } else {
168                 inpress = "Unpublished";
169             }
170         } else if (SWNC(GetCit(), "Online Publication")
171                    ||  SWNC(GetCit(), "Published Only in DataBase")
172                    ||  SWNC(GetCit(), "In press")) {
173             inpress = GetCit();
174         } else if (SWNC(GetCit(), "(er) ")) {
175             journal = GetCit();
176         } else if ((flags & fLabel_NoBadCitGen) == 0  &&  journal.empty()) {
177             journal = GetCit();
178         }
179     }
180 
181     if ((!HasText(pages) || (flags & (fLabel_FlatNCBI | fLabel_FlatEMBL)) == 0)
182         &&  journal.empty()  &&  !HasText(inpress)  &&  !HasText(year)
183         &&  (!CanGetVolume() || !HasText(GetVolume()))) {
184         return false;
185     }
186 
187     string prefix;
188     MaybeAddSpace(label);
189 
190     if ( !journal.empty() ) {
191         pos = journal.find_first_of("=\"");
192         if (pos != NPOS) {
193             journal.resize(pos);
194         }
195         *label += journal;
196         prefix = " ";
197     }
198 
199     if (HasText(inpress)) {
200         *label += prefix + inpress;
201         prefix = " ";
202     }
203 
204     if (CanGetVolume()  &&  HasText(GetVolume())) {
205         *label += prefix + GetVolume();
206     }
207 
208     if (HasText(pages)) {
209         if ((flags & fLabel_FlatNCBI) != 0) {
210             *label += ", " + pages;
211         } else if ((flags & fLabel_FlatEMBL) != 0) {
212             *label += ':' + pages;
213         }
214     }
215 
216     if (HasText(year)) {
217         *label += ' ' + year;
218     }
219 
220     return true;
221 }
222 
223 
224 END_objects_SCOPE // namespace ncbi::objects::
225 
226 END_NCBI_SCOPE
227 
228 /* Original file checksum: lines: 64, chars: 1875, CRC32: 5ca91cd9 */
229