void RuntimeEnvironment::RegisterNativeFunction(const rstring &name, int argumentCount, NativeFunction nf) { if (FindSub(name) != -1) return; int idx = AddSub(name); Sub *sub = GetSub(idx); sub->SetArgumentsCount(argumentCount); sub->SetNativeFunction(nf); }
AnsiString __fastcall TfrmTreeFrame::GetOption() { AnsiString opt,temp; TTreeNode *node =Tree->Items->GetFirstNode(); while (node !=NULL) { if ((node->ImageIndex==2) || (node->ImageIndex==1)) { temp = GetSub(node); if ((temp !="") & (opt!="")) opt =opt+ CRLF +temp; else opt =opt+temp; } node = node->getNextSibling(); } return opt; }
AnsiString __fastcall TfrmTreeFrame::GetSub(TTreeNode *TN) { AnsiString str,temp; for (int i=0;i<TN->Count;i++) //如果有子节点,先求子节点的值 { if (TN->Item[i]->ImageIndex==2) { temp = GetSub(TN->Item[i]); if (temp != "") str = str+CRLF+temp; } } if (TN->ImageIndex==1) return str; else if (TN->ImageIndex==2) { return ((TMenuItem *)(TN->Data))->Name+str; //如果子节点有值,返回节点及子节点值 } return ""; }
const CAuth_list& CPub::GetAuthors (void) const { switch (Which()) { case CPub::e_Gen : return (GetGen().GetAuthors()); case CPub::e_Sub : return (GetSub().GetAuthors()); case CPub::e_Article : return (GetArticle().GetAuthors()); case CPub::e_Book : return (GetBook().GetAuthors()); case CPub::e_Proc : return (GetProc().GetBook().GetAuthors()); case CPub::e_Patent : return (GetPatent().GetAuthors()); case CPub::e_Man : return (GetMan().GetCit().GetAuthors()); default : NCBI_THROW(CSerialException, eNotImplemented, "CPub::GetAuthors: unsupported entry type " + SelectionName(Which())); } }
bool CPub::IsSetAuthors(void) const { switch (Which()) { case CPub::e_Gen : return (GetGen().IsSetAuthors()); case CPub::e_Sub : return (GetSub().IsSetAuthors()); case CPub::e_Article : return (GetArticle().IsSetAuthors()); case CPub::e_Book : return (GetBook().IsSetAuthors()); case CPub::e_Proc : return (GetProc().IsSetBook() && GetProc().GetBook().IsSetAuthors()); case CPub::e_Patent : return (GetPatent().IsSetAuthors()); case CPub::e_Man : return (GetMan().IsSetCit() && GetMan().GetCit().IsSetAuthors()); default : break; } return false; }
int main(int argc, char **argv) { setlocale(0, ""); char * phrase = strdup("testset"); int len = strlen(phrase), count = 0; for (int i = 0; i < len; i++) { for (int n = 1; n <= len - i; n++) { if(isPal(phrase, i, n)) { printf("%s\n", GetSub(phrase, i, n)); count++; } } } printf("—уществует %i различных способов получить из строки \"%s\" палиндром.\n", count, phrase); return 0; }
// 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"); } }