plugin_utils.hpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:21k
- /*
- * ===========================================================================
- * PRODUCTION $Log: plugin_utils.hpp,v $
- * PRODUCTION Revision 1000.4 2004/04/12 18:12:51 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.44
- * PRODUCTION
- * ===========================================================================
- */
- #ifndef GUI_CORE___PLUGIN_UTILS__HPP
- #define GUI_CORE___PLUGIN_UTILS__HPP
- /* $Id: plugin_utils.hpp,v 1000.4 2004/04/12 18:12:51 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software/database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software/database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Mike DiCuccio
- *
- * File Description:
- * CPluginUtils -- utilities for managing the interface between the plugin
- * architecture and the GBENCH framework
- */
- #include <gui/core/selection_buffer.hpp>
- #include <gui/core/obj_convert.hpp>
- #include <gui/utils/reporter.hpp>
- #include <gui/plugin/PluginValue.hpp>
- #include <gui/plugin/AlgoCommand.hpp>
- #include <gui/plugin/DataCommand.hpp>
- #include <gui/plugin/ViewCommand.hpp>
- #include <serial/iterator.hpp>
- BEGIN_NCBI_SCOPE
- BEGIN_SCOPE(objects)
- class CPluginArg;
- class CPluginArgSet;
- class CPluginCommand;
- class CPluginInfo;
- class CPluginMessage;
- class CPluginReply;
- class CPluginRequest;
- class CScope;
- class CSeq_align;
- class CSeq_annot;
- class CSeq_entry;
- class CSeq_feat;
- class CSeq_loc;
- END_SCOPE(objects)
- class CPluginHandle;
- class CPluginRegistry;
- class CConvertCache;
- //
- // class CPluginUtils is a place-holder class for static functions that
- // facilitate using the plugin architecture.
- //
- class NCBI_GUICORE_EXPORT CPluginUtils
- {
- public:
- // generic argument list typedef
- typedef list< CRef<objects::CPluginArg> > TArgs;
- // typedef for ordered pairs of selectied items. These are explicitly
- // pairs because we in general need a scoe (document) to travel with the
- // data model object
- typedef pair< CConstRef<CObject>, CConstRef<IDocument> > TSelection;
- // Fit a set of objects into a set of plugin arguments. This version
- // takes as its input a set of selections from a selection buffer.
- static int FillArgs(objects::CPluginArgSet& args,
- const TConstScopedObjects& selections);
- // Fit a set of objects into a set of plugin arguments. This version
- // takes as its input a set of CPluginValues. Only the object
- // values will be processed.
- static int FillArgs(objects::CPluginArgSet& args,
- const objects::CPluginArg::TData::TArray& objects);
- // Fit a set of objects into a set of plugin arguments. This version
- // takes as its input a document.
- static int FillArgs(objects::CPluginArgSet& args,
- const IDocument& doc);
- // this function performs a similar task to FillArgs(); however, instead of
- // actually filling the set of arguments automatically, it returns true if
- // any of the selections indicated *can* fit. The primary use of this is
- // to determine if a set of plugins could accept some of the selections
- static bool CanFitArgs(const objects::CPluginArgSet& args,
- const IDocument& doc,
- CConvertCache* cache = NULL);
- static bool CanFitArgs(const objects::CPluginArgSet& args,
- const CSelectionBuffer& buf,
- CConvertCache* cache = NULL);
- static bool CanFitArgs(const objects::CPluginArgSet& args,
- const TConstScopedObjects& selections,
- CConvertCache* cache = NULL);
- //
- // plugin dispatching
- //
- enum EDispatchWhen {
- eDispatch_Now,
- eDispatch_Deferred
- };
- // call a plugin by name, passing in a selection buffer. This version
- // responds to algorithm commands.
- static void CallPlugin(const string& plugin_name,
- objects::EAlgoCommand cmd,
- const CSelectionBuffer& selections,
- IReporter* reporter = NULL,
- const string& ctx_name = "",
- EDispatchWhen when = eDispatch_Deferred);
- // call a plugin by name, passing in a selection buffer. This version
- // responds to view commands.
- static void CallPlugin(const string& plugin_name,
- objects::EDataCommand cmd,
- const CSelectionBuffer& selections,
- IReporter* reporter = NULL,
- const string& ctx_name = "",
- EDispatchWhen when = eDispatch_Deferred);
- // call a plugin by name, passing in a selection buffer. This version
- // responds to data commands.
- static void CallPlugin(const string& plugin_name,
- objects::EViewCommand cmd,
- const CSelectionBuffer& selections,
- IReporter* reporter = NULL,
- const string& ctx_name = "",
- EDispatchWhen when = eDispatch_Deferred);
- // call a plugin by name, passing in a document. This version
- // responds to algorithm commands.
- static void CallPlugin(const string& plugin_name,
- objects::EAlgoCommand cmd,
- const IDocument* doc = NULL,
- IReporter* reporter = NULL,
- const string& ctx_name = "",
- EDispatchWhen when = eDispatch_Deferred);
- // call a plugin by name, passing in a document. This version
- // responds to view commands.
- static void CallPlugin(const string& plugin_name,
- objects::EDataCommand cmd,
- const IDocument* doc = NULL,
- IReporter* reporter = NULL,
- const string& ctx_name = "",
- EDispatchWhen when = eDispatch_Deferred);
- // call a plugin by name, passing in a document. This version
- // responds to data commands.
- static void CallPlugin(const string& plugin_name,
- objects::EViewCommand cmd,
- const IDocument* doc = NULL,
- IReporter* reporter = NULL,
- const string& ctx_name = "",
- EDispatchWhen when = eDispatch_Deferred);
- // command through which all the CallPlugin(...) commands filter
- static void CallPlugin(objects::CPluginMessage& msg,
- const TConstScopedObjects& selections,
- EDispatchWhen when = eDispatch_Deferred);
- // call a plugin by name, passing in a fully qualified message object.
- // This is the final recipient of all CallPlugin() commands, and will
- // process the request non-interactively
- static void CallPlugin(objects::CPluginMessage& msg,
- EDispatchWhen when = eDispatch_Deferred);
- //
- // argument validation functions
- //
- // validate an entire set of arguments
- static bool IsValid(const objects::CPluginArgSet& args);
- // validate a given argument. This insures that the argument contains
- // a valid value, and that this value meets the argument's constraints.
- static bool IsValid(const objects::CPluginArg& arg);
- // validate a single plugin value
- static bool IsValid(const objects::CPluginValue& value);
- // check the constraints on a given argument
- static bool CheckConstraints(const objects::CPluginArg& arg,
- CConvertCache* cache = NULL);
- // individual constraint checking function. This is used by
- // CheckConstraints() as well as by CanFitArgs(), and its API
- // is a bit odd as a result.
- static bool CheckConstraints(const objects::CPluginArg& arg,
- objects::CScope& scope, const CObject& obj,
- CConvertCache* cache = NULL);
- //
- // object conversion functions
- //
- // convert an argument to a named container of items
- static vector<string> ArgToStringVec(const objects::CPluginArg& arg);
- // retrieve the plugin info object for a named plugin.
- // this will throw if the plugin isn't found.
- static const objects::CPluginInfo& GetInfo(const string& plugin_name);
- // return a string describing an arbitrary object. This is a single
- // entry-point function that will determine the best possible label to use.
- static string GetLabel(const CObject& obj, objects::CScope* scope);
- private:
- static objects::CPluginCommand*
- x_GetCommand(objects::CPluginRequest& request);
- };
- //
- // typedefs to make standard plugin args easier to deal with
- //
- BEGIN_SCOPE(plugin_args)
- typedef list< pair< CConstRef<IDocument>,
- CConstRef<objects::CSeq_id> > > TIdList;
- typedef list< pair< CConstRef<IDocument>,
- CConstRef<objects::CSeq_feat> > > TFeatList;
- typedef list< pair< CConstRef<IDocument>,
- CConstRef<objects::CSeq_loc> > > TLocList;
- typedef list< pair< CConstRef<IDocument>,
- CConstRef<objects::CSeq_entry> > > TEntryList;
- typedef list< pair< CConstRef<IDocument>,
- CConstRef<objects::CSeq_align> > > TAlignList;
- typedef list< pair< CConstRef<IDocument>,
- CConstRef<objects::CSeq_annot> > > TAnnotList;
- typedef list< pair< CConstRef<IDocument>,
- CConstRef<objects::CBioseq> > > TBioseqList;
- END_SCOPE(plugin_args)
- //
- // GetArgValue() offers simple, one-step conversion to a given argument type.
- // The default template assumes that the converted type derives from
- // CSerialObject.
- //
- template <class T>
- inline
- void GetArgValue(const objects::CPluginArg& arg,
- list< pair< CConstRef<IDocument>,
- CConstRef<T> > >& objs)
- {
- CTypeConstIterator<objects::CPluginValue> iter(arg);
- for ( ; iter; ++iter) {
- CConstRef<IDocument> doc(iter->GetDocument());
- CConstRef<CObject> obj(iter->GetObject());
- if ( !doc || !obj ) {
- continue;
- }
- CObjectConverter::TObjList obj_list;
- CObjectConverter::Convert(doc->GetScope(), *obj, T::GetTypeInfo(),
- obj_list);
- ITERATE (CObjectConverter::TObjList, obj_iter, obj_list) {
- CConstRef<T> ref(dynamic_cast<const T*>
- (obj_iter->GetPointer()));
- if (ref) {
- objs.push_back(make_pair(doc, ref));
- }
- }
- }
- }
- //
- // Specialization of GetArgValue for document types
- //
- template <>
- inline
- void GetArgValue(const objects::CPluginArg& arg,
- list< pair< CConstRef<IDocument>,
- CConstRef<IDocument> > >& objs)
- {
- CTypeConstIterator<objects::CPluginValue> iter(arg);
- for ( ; iter; ++iter) {
- CConstRef<IDocument> doc(iter->GetDocument());
- CConstRef<CObject> obj(iter->GetObject());
- if ( !doc || !obj ) {
- continue;
- }
- CObjectConverter::TObjList obj_list;
- CObjectConverter::Convert(doc->GetScope(), *obj, "IDocument", obj_list);
- ITERATE (CObjectConverter::TObjList, obj_iter, obj_list) {
- CConstRef<IDocument> ref(dynamic_cast<const IDocument*>
- (obj_iter->GetPointer()));
- if (ref) {
- objs.push_back(make_pair(doc, ref));
- }
- }
- }
- }
- //
- // Specialization of GetArgValue for generic CObject types
- //
- template <>
- inline
- void GetArgValue(const objects::CPluginArg& arg,
- list< pair< CConstRef<IDocument>,
- CConstRef<CObject> > >& objs)
- {
- CTypeConstIterator<objects::CPluginValue> iter(arg);
- for ( ; iter; ++iter) {
- CConstRef<IDocument> doc(iter->GetDocument());
- CConstRef<CObject> obj(iter->GetObject());
- if ( !doc || !obj ) {
- continue;
- }
- objs.push_back(make_pair(doc, obj));
- }
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: plugin_utils.hpp,v $
- * Revision 1000.4 2004/04/12 18:12:51 gouriano
- * PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.44
- *
- * Revision 1.44 2004/04/07 12:36:02 dicuccio
- * Dropped CSelectionBuffer::TSelList in favor of TConstScopedObjects. Altered
- * CallPlugin API - added default IReporter*. Removed unneeded #includes
- *
- * Revision 1.43 2004/01/27 18:27:59 dicuccio
- * Code clean-up. Removed unneeded headers. Added new typedefs for alignment,
- * annotation lists
- *
- * Revision 1.42 2004/01/21 12:38:17 dicuccio
- * redesigned CObjectCOnverter API to eliminate temporary object creation
- *
- * Revision 1.41 2004/01/07 15:46:16 dicuccio
- * Renamed GetObjectLabel() to GetLabel(). Changed calling semantics to more
- * closely follow other label extraction functions
- *
- * Revision 1.40 2003/12/22 19:13:00 dicuccio
- * Don't include the message queue - not needed
- *
- * Revision 1.39 2003/11/18 17:36:47 dicuccio
- * Cleaned up some comments. Added new FitArgs() API to take a set of
- * CPluginValues
- *
- * Revision 1.38 2003/11/06 19:57:57 dicuccio
- * Removed USING_SCOPE(objects). Changed API for CallPlugin() - added optiona
- * context parameter
- *
- * Revision 1.37 2003/11/04 17:13:14 dicuccio
- * Added new default parameter to force calling of plugins immediately or use
- * dispatch mechanism. Removed templates from header - moved to private
- * implementation
- *
- * Revision 1.36 2003/10/15 18:30:58 dicuccio
- * Added optional conversion cache argument to CheckConstraints()
- *
- * Revision 1.35 2003/10/10 17:12:25 dicuccio
- * Added optional arg to CanFitArgs() for object conversion cache
- *
- * Revision 1.34 2003/10/07 13:33:01 dicuccio
- * Changed CPluginURL* to CPluginValue*. Code clean-up; moved validation code out
- * of xgbplugin and into plugin_utils.cpp
- *
- * Revision 1.33 2003/09/16 14:04:06 dicuccio
- * Made private constraint checking function public
- *
- * Revision 1.32 2003/09/04 14:00:26 dicuccio
- * Introduce IDocument and IView as abstract base classes. Use IDocument instead
- * of CDocument.
- *
- * Revision 1.31 2003/09/03 14:49:02 rsmith
- * change namespace name from args to plugin_args to avoid clashes with variable names.
- *
- * Revision 1.30 2003/08/22 17:28:35 dicuccio
- * Moved prototypes for conversion routines to .cpp file
- *
- * Revision 1.29 2003/08/21 12:14:01 dicuccio
- * Added new typedefs for standard argument objects containers
- *
- * Revision 1.28 2003/08/19 18:51:44 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
- *
- * Revision 1.27 2003/08/05 16:58:39 dicuccio
- * Changed calling conventions for plugin message queue - pass by reference, not
- * CConstRef<>
- *
- * Revision 1.26 2003/07/31 16:42:29 dicuccio
- * Changed calling semantics of CallPlugin() to permit calling a plugin with no
- * selections
- *
- * Revision 1.25 2003/07/25 13:41:08 dicuccio
- * Removed duplicated comment
- *
- * Revision 1.24 2003/07/24 13:11:00 dicuccio
- * Added basic bioseq conversions
- *
- * Revision 1.23 2003/07/23 17:52:23 dicuccio
- * Moved logic for validating arguments into CPluginUtils.
- *
- * Revision 1.22 2003/07/22 15:27:10 dicuccio
- * Changed Convert() to perform one-to-many conversions. Moved GetObjectLabel()
- * from a static internal function of plugin_arg_dialog.cpp to a member of
- * CPluginUtils
- *
- * Revision 1.21 2003/07/21 19:19:40 dicuccio
- * Added an interface to check if a selection buffer can fit into a set of args
- *
- * Revision 1.20 2003/07/14 10:57:52 shomrat
- * Plugin messageing system related changes
- *
- * Revision 1.19 2003/06/30 13:43:37 dicuccio
- * Added API to call a plugin directly with a CPluginRequest object
- *
- * Revision 1.18 2003/06/26 15:32:01 dicuccio
- * Moved GetURLValue() from PluginURL.hpp to plugin_utils.hpp - relieves one
- * circular dependency betweein gui/gqplugin and gui/core/
- *
- * Revision 1.17 2003/06/25 16:59:41 dicuccio
- * Changed CPluginHandle into a pointer-to-implementation (the previous
- * implementation is now the pointer held). Lots of #include file clean-ups.
- *
- * Revision 1.16 2003/06/20 14:44:36 dicuccio
- * Revamped handling of plugin registration. All plugin factories now derive
- * from CPluginFactoryBase; CPluginFactory is a template. There is a new
- * requirement for derived plugin handlers of all types (each must implement a
- * static function of the form 'static void GetInfo(CPluginInfo&)')
- *
- * Revision 1.15 2003/06/02 16:01:29 dicuccio
- * Rearranged include/objects/ subtree. This includes the following shifts:
- * - include/objects/alnmgr --> include/objtools/alnmgr
- * - include/objects/cddalignview --> include/objtools/cddalignview
- * - include/objects/flat --> include/objtools/flat
- * - include/objects/objmgr/ --> include/objmgr/
- * - include/objects/util/ --> include/objmgr/util/
- * - include/objects/validator --> include/objtools/validator
- *
- * Revision 1.14 2003/05/19 13:32:43 dicuccio
- * Moved gui/core/plugin --> gui/plugin/
- *
- * Revision 1.13 2003/05/06 15:51:07 dicuccio
- * Dropped identity object conversions in favor of a generic approach
- *
- * Revision 1.12 2003/05/05 12:39:59 dicuccio
- * Added new interface function 9CanFitArgs()) for testing whether a group of
- * selections or objects could possibly apply to a set of arguments
- *
- * Revision 1.11 2003/05/01 12:53:06 dicuccio
- * Added conversion routines for {doc,seq-id,seq-loc,seq-feat} -> seq-entry
- *
- * Revision 1.10 2003/04/29 14:30:37 dicuccio
- * Made main object conversion function public. Changed SelectionsToArgs() ->
- * FillArgs() and added a second interface that wraps filling arguments with
- * just a document
- *
- * Revision 1.9 2003/04/24 16:13:13 dicuccio
- * Large revision. Added many new interface functions to handle object
- * cats/conversion; simplified filling out of plugin arguments
- *
- * Revision 1.8 2003/04/16 20:11:29 dicuccio
- * Added missing #include for CPluginException
- *
- * Revision 1.7 2003/04/16 18:16:17 dicuccio
- * Added CallPlugin() methods to explicitly call plugins by name or plugin
- * handle
- *
- * Revision 1.6 2003/03/25 14:20:47 dicuccio
- * Changed export specifier from XGBPLUGIN to GUICORE
- *
- * Revision 1.5 2003/03/25 13:05:45 dicuccio
- * Changed SelBufferToArgs() to return the number of unset arguments - used to
- * determine if automated argument processing can continue.
- *
- * Revision 1.4 2003/02/26 14:33:21 dicuccio
- * Major rewrite. Most common cases of selection buffer-to-arguments should now
- * work automatically, but there is still no manual fall-back.
- *
- * Revision 1.3 2003/02/24 13:00:17 dicuccio
- * Renamed classes in plugin spec:
- * CArgSeg --> CPluginArgSet
- * CArgument --> CPluginArg
- * CPluginArgs --> CPluginCommand
- * CPluginCommands --> CPluginCommandSet
- *
- * Revision 1.2 2003/02/21 16:44:13 dicuccio
- * Added Win32 export specifiers for new plugin library. Fixed compilation
- * issues for Win32.
- *
- * Revision 1.1 2003/02/20 19:44:06 dicuccio
- * Created new plugin architecture, mediated via an ASN.1 spec. Moved GBENCH
- * framework over to use new plugin architecture.
- *
- * ===========================================================================
- */
- #endif // GUI_CORE___PLUGIN_UTILS__HPP