bool CCit_gen::GetLabelV1(string* label, TLabelFlags flags) const { bool unique = (flags & fLabel_Unique) != 0; if (IsSetSerial_number()) { *label += "[" + NStr::IntToString(GetSerial_number()) + "]"; } if (IsSetMuid()) { *label += "NLM" + NStr::IntToString(GetMuid()); } string date; string* date_ptr = 0; if ( IsSetDate() ) { date_ptr = &date; GetDate().GetDate(date_ptr, true); } const string* title2 = 0; const string* titleunique = 0; bool unpublished = false; const CTitle* title = IsSetJournal() ? &GetJournal() : 0; const CAuth_list* authors = IsSetAuthors() ? &GetAuthors() : 0; const string* volume = IsSetVolume() ? &GetVolume() : 0; const string* issue = IsSetIssue() ? &GetIssue() : 0; const string* pages = IsSetPages() ? &GetPages() : 0; if (IsSetCit()) { if ( NStr::EqualNocase( GetCit(), "Unpublished") ) { unpublished = true; } else if (!title) { title2 = &GetCit(); } } if (IsSetTitle()) { titleunique = &GetTitle(); } else if (title2) { titleunique = title2; } else if (!title && IsSetCit()) { titleunique = &GetCit(); } if (!title && !authors && !IsSetTitle() && !volume && !pages && !issue) { titleunique = 0; if (IsSetCit()) { string cit(GetCit()); if (!unique) { try { cit.resize(cit.find_last_of('|')); } catch(length_error&) {} } *label += cit; } return true; } return x_GetLabelV1(label, unique, authors, 0, title, 0, 0, 0, title2, titleunique, date_ptr, volume, issue, pages, unpublished); }
// Determines the type of set and calls the appropriately instantiated // s_GetLabel bool CPub_set::GetLabel(string* label, TLabelFlags flags, ELabelVersion version) const { // Ensure label exists if (!label) { return false; } switch (Which()) { case e_Pub: return s_GetLabel<CPub>(label, GetPub(), flags, version); case e_Medline: return s_GetLabel<CMedline_entry>(label, GetMedline(), flags, version); case e_Article: return s_GetLabel<CCit_art>(label, GetArticle(), flags, version); case e_Journal: return s_GetLabel<CCit_jour>(label, GetJournal(), flags, version); case e_Book: return s_GetLabel<CCit_book>(label, GetBook(), flags, version); case e_Proc: return s_GetLabel<CCit_proc>(label, GetProc(), flags, version); case e_Patent: return s_GetLabel<CCit_pat>(label, GetPatent(), flags, version); default: return false; } }
bool Journalist::AddJournal(const SmartPtr<Journal> jrnl) { DBG_ASSERT(IsValid(jrnl)); std::string name = jrnl->Name(); SmartPtr<Journal> temp = GetJournal(name); DBG_ASSERT(IsNull(temp)); if (IsValid(temp)) { return false; } journals_.push_back(jrnl); return true; }
// Appends a label to "label" bool CPub::GetLabel(string* label, ELabelType type, TLabelFlags flags, ELabelVersion version) const { static const char* s_PubTypes[14] = { "Unknown", "Generic", "Submit", "Medline", "MUID", "Article", "Journal", "Book", "Proceedings", "Patent", "PatID", "Manuscript", "Equiv", "PMID" }; // Check that label exists if (!label) { return false; } // Get the index into the s_PubTypes array corresponding to pub type int idx = static_cast<int>(Which()); idx = idx >= 0 && idx < 14 ? idx : 0; if (type == eType) { // Append pub type to label and return *label += s_PubTypes[idx]; return true; } if (type == eBoth) { // Append pub type to label *label += string(s_PubTypes[idx]) + ": "; } switch (Which()) { case e_Muid: *label += "NLM" + NStr::IntToString(GetMuid()); return true; case e_Pmid: *label += "PM" + NStr::IntToString(GetPmid().Get()); return true; case e_Equiv: return GetEquiv().GetLabel(label, flags, version); case e_Medline: return GetMedline().GetLabel(label, flags, version); case e_Article: return GetArticle().GetLabel(label, flags, version); case e_Journal: return GetJournal().GetLabel(label, flags, version); case e_Book: return GetBook().GetLabel(label, flags, version); case e_Proc: return GetProc().GetLabel(label, flags, version); case e_Man: return GetMan().GetLabel(label, flags, version); case e_Sub: return GetSub().GetLabel(label, flags, version); case e_Patent: return GetPatent().GetLabel(label, flags, version); case e_Pat_id: return GetPat_id().GetLabel(label, flags, version); case e_Gen: return GetGen().GetLabel(label, flags, version); default: return false; } }
void CPub::GetTitles( TOneTitleRefVec & out_title, size_t iMaxToGet ) const { // this "if" lets us assume below this point that // we have room for at least one if( iMaxToGet <= 0 ) { return; } switch( Which() ) { case CPub::e_not_set: case CPub::e_Medline: case CPub::e_Pmid: case CPub::e_Pat_id: // these types don't have titles, so nothing to do break; case CPub::e_Gen: if( GetGen().IsSetTitle() ) { out_title.push_back( xs_GetTitleFromPlainString( GetGen().GetTitle()) ); } break; case CPub::e_Sub: if( GetSub().IsSetDescr() ) { out_title.push_back( xs_GetTitleFromPlainString( GetSub().GetDescr()) ); } break; case CPub::e_Article: if( GetArticle().IsSetTitle() && GetArticle().GetTitle().IsSet() ) { xs_AppendTitles( out_title, iMaxToGet, GetArticle().GetTitle() ); } break; case CPub::e_Journal: if( GetJournal().IsSetTitle() ) { xs_AppendTitles( out_title, iMaxToGet, GetJournal().GetTitle() ); } break; case CPub::e_Book: if( GetBook().IsSetTitle() ) { xs_AppendTitles( out_title, iMaxToGet, GetBook().GetTitle() ); } break; case CPub::e_Proc: // what to do here? It has a book and meeting // It's not entirely clear if this is the best course of action if( FIELD_CHAIN_OF_2_IS_SET(GetProc(), Book, Title) ) { xs_AppendTitles( out_title, iMaxToGet, GetProc().GetBook().GetTitle() ); } break; case CPub::e_Patent: if( GetPatent().IsSetTitle() ) { out_title.push_back( xs_GetTitleFromPlainString( GetPatent().GetTitle()) ); } break; case CPub::e_Man: if( FIELD_CHAIN_OF_2_IS_SET(GetMan(), Cit, Title) ) { xs_AppendTitles( out_title, iMaxToGet, GetMan().GetCit().GetTitle() ); } break; case CPub::e_Equiv: { size_t iMaxTitleSizeAllowed = ( out_title.size() + iMaxToGet ); if( iMaxTitleSizeAllowed < out_title.size() ) { // integer overflowed iMaxTitleSizeAllowed = std::numeric_limits<std::size_t>::max(); } FOR_EACH_PUB_ON_PUBEQUIV(pub_it, GetEquiv()) { if( out_title.size() >= iMaxTitleSizeAllowed ) { break; } // dig down recursively (*pub_it)->GetTitles(out_title, (iMaxTitleSizeAllowed - out_title.size()) ); } } break; default: NCBI_THROW(CException, eUnknown, "unhandled pub type"); } }
// Based on FormatCitGen from the C Toolkit's api/asn2gnb5.c. bool CCit_gen::GetLabelV2(string* label, TLabelFlags flags) const { if ( !CanGetCit() && !CanGetJournal() && !CanGetDate() && CanGetSerial_number() ) { return false; } if ( !CanGetJournal() && CanGetCit() && SWNC(GetCit(), "unpublished")) { if ((flags & fLabel_NoUnpubAffil) != 0) { MaybeAddSpace(label); *label += "Unpublished"; return true; } if (CanGetAuthors() && GetAuthors().CanGetAffil()) { MaybeAddSpace(label); *label += "Unpublished "; GetAuthors().GetAffil().GetLabel(label, flags, eLabel_V2); NStr::TruncateSpacesInPlace(*label, NStr::eTrunc_End); return true; } if (CanGetCit() && HasText(GetCit())) { MaybeAddSpace(label); *label += NStr::TruncateSpaces(GetCit()); return true; } else { return false; } } string year = CanGetDate() ? GetParenthesizedYear(GetDate()) : kEmptyStr; string pages = CanGetPages() ? FixPages(GetPages()) : kEmptyStr; string journal, inpress; SIZE_TYPE pos; if (CanGetJournal()) { journal = GetJournal().GetTitle(); } if (CanGetCit()) { pos = GetCit().find("Journal=\""); if (pos != NPOS) { journal = GetCit().substr(pos + 9); } else if (SWNC(GetCit(), "submitted") || SWNC(GetCit(), "unpublished")) { if ((flags & fLabel_NoBadCitGen) == 0 || !journal.empty()) { inpress = GetCit(); } else { inpress = "Unpublished"; } } else if (SWNC(GetCit(), "Online Publication") || SWNC(GetCit(), "Published Only in DataBase") || SWNC(GetCit(), "In press")) { inpress = GetCit(); } else if (SWNC(GetCit(), "(er) ")) { journal = GetCit(); } else if ((flags & fLabel_NoBadCitGen) == 0 && journal.empty()) { journal = GetCit(); } } if ((!HasText(pages) || (flags & (fLabel_FlatNCBI | fLabel_FlatEMBL)) == 0) && journal.empty() && !HasText(inpress) && !HasText(year) && (!CanGetVolume() || !HasText(GetVolume()))) { return false; } string prefix; MaybeAddSpace(label); if ( !journal.empty() ) { pos = journal.find_first_of("=\""); if (pos != NPOS) { journal.resize(pos); } *label += journal; prefix = " "; } if (HasText(inpress)) { *label += prefix + inpress; prefix = " "; } if (CanGetVolume() && HasText(GetVolume())) { *label += prefix + GetVolume(); } if (HasText(pages)) { if ((flags & fLabel_FlatNCBI) != 0) { *label += ", " + pages; } else if ((flags & fLabel_FlatEMBL) != 0) { *label += ':' + pages; } } if (HasText(year)) { *label += ' ' + year; } return true; }