plugin_utils.cpp

来自「ncbi源码」· C++ 代码 · 共 1,523 行 · 第 1/4 页

CPP
1,523
字号
    // we plan to handle one case automatically: the set of arguments has    // one argument that takes a data model object.  Other cases are left    // to the user to clarify because these are too complex to guess    int obj_args = 0;    ITERATE (CPluginArgSet::Tdata, iter, args.Get()) {        const CPluginArg& arg = **iter;        switch (arg.GetType()) {        case CPluginArg::eObject:        case CPluginArg::eDocument:            {{                 ++obj_args;                 const string& target_type = arg.GetObjectSubtype();                 // are there any selections that might support this object                 // type?  if so, we can return true                 ITERATE (TConstScopedObjects, iter, sels) {                     SConstScopedObject cso = *iter;                     CScope& scope = *cso.scope;                     CObjConverter::TObjList obj_list;                     /**                     if (cache) {                         obj_list =                             cache->Convert(scope,                                            *iter->m_Object.GetPointer(),                                            target_type);                     } else **/{                         CObjectConverter::Convert(scope,                                                   *cso.object,                                                   target_type, obj_list);                     }                     if (obj_list.size() == 0) {                         continue;                     }                     ITERATE (CObjConverter::TObjList, obj_iter, obj_list) {                         if ( CheckConstraints(arg, scope, **obj_iter) ) {                             return true;                         }                     }                 }             }}            break;        default:            break;        }    }    // we failed to match any selection to an argument type    // the only case we let pass is that there are no object argument types    return (obj_args == 0);}vector<string> CPluginUtils::ArgToStringVec(const CPluginArg& arg){    if (arg.GetType() != CPluginArg::eString) {        NCBI_THROW(CPluginException, eInvalidArg,                   "CPluginUtil::ArgToStringVec(): "                   "Argument is not of type String");    }    vector<string> vals;    CTypeConstIterator<CPluginValue> iter(arg);    for ( ;  iter;  ++iter) {        vals.push_back(iter->AsString());    }    return vals;}//// return the label of an object based on its type (arg.m_Subtype)//string CPluginUtils::GetLabel(const CObject& obj, CScope* scope){    {{        // generic document handling        const IDocument* doc = dynamic_cast<const IDocument*> (&obj);        if (doc) {            return doc->GetTitle();        }    }}    string label;    CLabel::GetLabel(obj, &label, CLabel::eDefault, scope);    return label;}//// retrieve the CPluginInfo object associated with a named plugin//const CPluginInfo& CPluginUtils::GetInfo(const string& plugin_name){    CPluginHandle handle = CPluginRegistry::GetPlugin(plugin_name);    if ( !handle ) {        NCBI_THROW(CPluginException, eInvalidArg,                   "Invalid plugin name " + plugin_name);    }    return handle.GetInfo();}END_NCBI_SCOPE/* * =========================================================================== * $Log: plugin_utils.cpp,v $ * Revision 1000.5  2004/06/01 20:44:35  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.69 * * Revision 1.69  2004/06/01 18:03:45  dicuccio * Allocate temporary CSelectionBuffer objects on the heap, not on the stack * * Revision 1.68  2004/05/21 22:27:40  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.67  2004/05/07 15:41:27  dicuccio * Use CLabel instead of CSeqUtils::GetLabel() * * Revision 1.66  2004/05/03 12:49:28  dicuccio * gui/utils --> gui/objutils where needed * * Revision 1.65  2004/04/07 12:47:31  dicuccio * Use TConstScopedObjects instead of CSelectionBuffer::TSelList.  Changed * CallPlugin API to include an IReporter interface. * * Revision 1.64  2004/03/08 20:21:05  jcherry * Fixed object argument clearing * * Revision 1.63  2004/02/04 14:09:04  dicuccio * Enable clearing of objects * * Revision 1.62  2004/02/03 23:08:13  ucko * Temporarily remove call to ClearObjects, which doesn't seem to be * implemented yet. * * Revision 1.61  2004/02/03 21:24:31  dicuccio * Clear objects from plugin argument sets prior to filling with new objects * * Revision 1.60  2004/01/30 17:18:11  dicuccio * Moved most of GetLabel() to CSeqUtils - CPluginUtils::GetLabel() only handles * IDocument directly * * Revision 1.59  2004/01/21 12:38:18  dicuccio * redesigned CObjectCOnverter API to eliminate temporary object creation * * Revision 1.58  2004/01/20 18:13:28  dicuccio * Make sure to check for bioseq handle validity before requesting information * from it * * Revision 1.57  2004/01/15 22:50:17  jcherry * Added FinalizeArgs() for plugins * * Revision 1.56  2004/01/07 15:48:10  dicuccio * Renamed GetObjectLabel() to GetLabel().  Dropped use of CSeq_loc::GetLabel() in * favor of internal location processing * * Revision 1.55  2004/01/05 19:10:31  dicuccio * Move comment marker * * Revision 1.54  2003/12/22 19:21:16  dicuccio * GetObjectLabel(): format a nicer string for seq-ids when possible * * Revision 1.53  2003/11/26 17:08:22  dicuccio * Fixed two thinkos: * - in s_CallPlugin(), check to make sure the plugin handle is valid before *   calling FillDefaults() * - make sure that FillArgs() doesn't dereference a NULL pointer * * Revision 1.52  2003/11/18 17:44:31  dicuccio * Added new API for FitArgs() to take a set of CPluginValue objects * * Revision 1.51  2003/11/06 20:04:56  dicuccio * Added context parameter to PluginMessage.  Added APIs to CallPlugin() to permit * passing the context parameter * * Revision 1.50  2003/11/04 17:19:41  dicuccio * Made templateed calls to registry private.  Changed to match API change in * CPluginMessage. * * Revision 1.49  2003/10/27 17:39:54  dicuccio * Changed to match new API for CPluginValue variant * * Revision 1.48  2003/10/23 16:18:09  dicuccio * Fixed to match API change for CPluginArgDialog * * Revision 1.47  2003/10/15 18:28:45  dicuccio * Added handling for new constraint types * * Revision 1.46  2003/10/10 17:15:58  dicuccio * Changed protoypes for CanFitArgs() - take optional conversion cache * * Revision 1.45  2003/10/10 15:57:28  friedman * Changed all CPluginUtils::Convert to use CObjectConverter::Convert. * Label for SeqFeat changed to include the document id and document short title. * * Revision 1.44  2003/10/07 13:36:09  dicuccio * Renamed CPluginURL* to CPluginValue*.  Moved validation code into CPluginUtils * * Revision 1.43  2003/10/01 12:07:35  ucko * +<algorithm> for find() * * Revision 1.42  2003/09/16 14:02:07  dicuccio * Replaced conversion code with calls to new class (CObjectConverter) * * Revision 1.41  2003/09/04 14:01:51  dicuccio * Introduce IDocument and IView as abstract base classes for CDocument and CView * * Revision 1.40  2003/09/02 20:36:26  dicuccio * Corrected x_DocToSeqAnnot to handle the case of a seq-annot-as-document * * Revision 1.39  2003/08/28 15:55:51  ucko * GetObjectLabel: return CNcbiOstrstreamToString(label) rather than * label.str() to ensure proper cleanup and termination. * * Revision 1.38  2003/08/28 00:09:08  ucko * x_SeqLocToSeqAnnot: adjust for latest objmgr API. * * Revision 1.37  2003/08/22 17:28:10  dicuccio * FIxed seq-annot conversions - all now pass through x_SeqLocToSeqAnnot * * Revision 1.36  2003/08/22 17:05:05  dicuccio * Temporary compilation fix: disable annotation conversion * * Revision 1.35  2003/08/22 15:45:12  dicuccio * Removed a number of unnecessary _TRACE() statemens * * Revision 1.34  2003/08/19 18:52:16  friedman * Added the follwing conversion functionclality to Convert: *     doc -> seq-annot, bioseq -> seq-annot, seq-id -> seq-annot, *     seq-loc -> seq-annot, seq-entry -> seq-annot, doc -> seq-align * * Added seq-annot and seq-align label formatting to GetObjectLabel * * Revision 1.33  2003/08/18 19:16:47  dicuccio * Fixed another (hopefully last!) thinko in CanFitArgs() - must pass the logic * "return true if any of our selections matches an object argument or if there * are no object arguments" * * Revision 1.32  2003/08/15 19:34:33  dicuccio * Added early break to loop on failure * * Revision 1.31  2003/08/13 13:33:23  dicuccio * Fixed another thinko - always pass objects regardless of whether the argument is of type single or of type array * * Revision 1.30  2003/08/12 21:41:24  ucko * Fix typo * * Revision 1.29  2003/08/12 19:51:23  dicuccio * Fixed thinko in CanFitArgs() - rather than return false for any failure, return * true for any success * * Revision 1.28  2003/08/11 19:26:21  dicuccio * Favor member insert to std::copy() * * Revision 1.27  2003/08/06 14:38:55  friedman * Add Seq-entry label formatting to GetObjectLabel * * Revision 1.26  2003/08/05 17:07:15  dicuccio * Changed calling semantics for the message queue - pass by reference, not * CConstRef<> * * Revision 1.25  2003/07/31 16:56:06  dicuccio * Changed name of plugin message queue.  Correctly account for hidden arguments * to plugins. * * Revision 1.24  2003/07/24 13:12:29  dicuccio * Added basic bioseq conversion routines * * Revision 1.23  2003/07/23 19:14:08  dicuccio * Moved logic for validating plugin arguments into CPluginUtils. * * Revision 1.22  2003/07/22 17:01:14  dicuccio * Fixed compilation error - return TObjList instead of NULL * * Revision 1.21  2003/07/22 15:29:54  dicuccio * Dropped CSeqVector as an explicitly managed type.  Changed Convert() to perform * a one-to-many conversion * * Revision 1.20  2003/07/21 19:29:17  dicuccio * Changed to match API changes in CSelectionBuffer.  Added CanFitArgs() version * to work with selection buffers * * Revision 1.19  2003/07/17 03:20:19  friedman * Added passing in a TConstScopedObjects to CPluginArgDialog * * Revision 1.18  2003/07/14 11:01:20  shomrat * Plugin messageing system related changes * * Revision 1.17  2003/06/30 13:33:41  dicuccio * Added API to call a plugin with a raw CPluginRequest object * * Revision 1.16  2003/06/25 17:02:54  dicuccio * Split CPluginHandle into a handle (pointer-to-implementation) and * implementation file.  Lots of #include file clean-ups. * * Revision 1.15  2003/06/02 16:06:17  dicuccio * Rearranged src/objects/ subtree.  This includes the following shifts: *     - src/objects/asn2asn --> arc/app/asn2asn *     - src/objects/testmedline --> src/objects/ncbimime/test *     - src/objects/objmgr --> src/objmgr *     - src/objects/util --> src/objmgr/util *     - src/objects/alnmgr --> src/objtools/alnmgr *     - src/objects/flat --> src/objtools/flat *     - src/objects/validator --> src/objtools/validator *     - src/objects/cddalignview --> src/objtools/cddalignview * In addition, libseq now includes six of the objects/seq... libs, and libmmdb * replaces the three libmmdb? libs. * * Revision 1.14  2003/05/19 13:35:59  dicuccio * Moved gui/core/plugin/ -> gui/plugin/.  Merged gui/core/algo, gui/core/doc/, * and gui/core/view/ into one library (gui/core/) * * Revision 1.13  2003/05/06 15:55:16  dicuccio * Dropped identity object conversion in favor of a generic approach * * Revision 1.12  2003/05/05 12:42:48  dicuccio * Added new interface function (CanFitArgs()) to determine if a given set of * objects could possibly apply to a set of arguments * * Revision 1.11  2003/05/01 12:53:36  dicuccio * Added conversion routines for {doc,seq-id,seq-loc,seq-feat} --> seq-entry * * Revision 1.10  2003/04/29 14:44:16  dicuccio * Fixed bungled commit - deleted dead, poorly formatted code that affected * indentation * * Revision 1.9  2003/04/29 14:42:43  dicuccio * Changed SelectionsToArgs() -> FillArgs().  Added API for filling arguments * based solely on the contents of a document.  Made main type conversion * routine public.  Added API for converting objects based on CTypeInfo.  Added * prototype function for conversion of an argument to a vector of strings. * * Revision 1.8  2003/04/24 16:31:07  dicuccio * Large changes.  Added many new interface functions for objects * cast/conversion.  Changed SelBufferToArgs() -> more generic FillArgs(). * Changed internals of filling out plugin arguments automatically to avoid * faulty assumptions about argument contents. * * Revision 1.7  2003/04/16 18:21:27  dicuccio * Added generic plugin launch mechanism (CallPlugin()).  Modified * document-to-argument resolution to permit empty documents to be passed as * documents * * Revision 1.6  2003/03/25 13:11:32  dicuccio * Changed FillArgs() to return the number of unset arguments * * Revision 1.5  2003/03/10 22:58:51  kuznets * iterate -> ITERATE * * Revision 1.4  2003/02/26 14:24:36  dicuccio * Major rewrite of selection-to-argument handling code - most cases should be * handled automatically now, but there is still no manual fall-back. * * Revision 1.3  2003/02/25 14:46:52  dicuccio * Intermediate fix.  Still not working, but at least it compiles. * * Revision 1.2  2003/02/24 13:03:15  dicuccio * Renamed classes in plugin spec: *     CArgSeg --> CPluginArgSet *     CArgument --> CPluginArg *     CPluginArgs --> CPluginCommand *     CPluginCommands --> CPluginCommandSet * * Revision 1.1  2003/02/20 19:49:56  dicuccio * Created new plugin architecture, based on ASN.1 spec.  Moved GBENCH frameowrk * over to use new plugin architecture. * * =========================================================================== */ 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?