pluginargset.cpp
来自「ncbi源码」· C++ 代码 · 共 469 行
CPP
469 行
/* * =========================================================================== * PRODUCTION $Log: PluginArgSet.cpp,v $ * PRODUCTION Revision 1000.2 2004/06/01 20:53:35 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.21 * PRODUCTION * =========================================================================== *//* $Id: PluginArgSet.cpp,v 1000.2 2004/06/01 20:53:35 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. * * =========================================================================== * * Author: Mike DiCuccio, Denis Vakatov, Anatoliy Kuznetsov * * File Description: * CPluginArgSet -- defines an interface for collections of plugin arguments * * Remark: * This code was originally generated by application DATATOOL * using specifications from the data definition file * 'plugin.asn'. */// standard includes#include <ncbi_pch.hpp>#include <gui/core/plugin_exception.hpp>// generated includes#include <gui/plugin/PluginArgSet.hpp>#include <gui/plugin/PluginArg.hpp>#include <gui/plugin/PluginValueConstraint.hpp>// generated classesBEGIN_NCBI_SCOPEBEGIN_objects_SCOPE // namespace ncbi::objects::// destructorCPluginArgSet::~CPluginArgSet(void){}//// indexing operator for accessing arguments based on names//const CPluginArg& CPluginArgSet::operator[] (const string& name) const{ ITERATE (Tdata, iter, Get()) { if ( (*iter)->GetName() == name) { return (**iter); } } // not found - we throw NCBI_THROW(CPluginException, eInvalidArg, "No argument named '" + name + "'");}CPluginArg& CPluginArgSet::operator[] (const string& name){ NON_CONST_ITERATE (Tdata, iter, Set()) { if ( (*iter)->GetName() == name) { return (**iter); } } // not found - we throw NCBI_THROW(CPluginException, eInvalidArg, "No argument named '" + name + "'");}// HasArgument() can be used to tell whether this set of arguments contains an// argument named 'name'bool CPluginArgSet::HasArgument(const string& name) const{ ITERATE (Tdata, iter, Get()) { if ( (*iter)->GetName() == name) { return true; } } return false;}// add a named argument. This argument is required, and has no default// value. Attempts to access the value without setting the value will// result in an exception being thrown.CPluginArg&CPluginArgSet::AddArgument(const string& name, const string& desc, CPluginArg::EType type, CPluginArg::TData::E_Choice single_or_array){ if (HasArgument(name)) { NCBI_THROW(CPluginException, eInvalidArg, string("Argument `") + name + string("' already exists")); } CRef<CPluginArg> arg(new CPluginArg()); switch (type) { case CPluginArg::eBoolean: arg->SetBoolean(); break; case CPluginArg::eInteger: arg->SetInteger(); break; case CPluginArg::eDouble: arg->SetDouble(); break; case CPluginArg::eString: arg->SetString(); break; case CPluginArg::eFile: arg->SetFile(); break; case CPluginArg::eDocument: arg->SetDocument(); break; case CPluginArg::eObject: arg->SetObject(); break; default: case CPluginArg::eNotSet: NCBI_THROW(CPluginException, eInvalidArg, "Invalid argument type in AddArgument()"); } if (single_or_array == CPluginArg::TData::e_Array) { arg->SetList(); } arg->SetName(name); arg->SetDesc(desc); Set().push_back(arg); return *arg;}// add a named argument. This argument is required, and has no default// value. Attempts to access the value without setting the value will// result in an exception being thrown.CPluginArg&CPluginArgSet::AddArgument(const string& name, const string& desc, const CTypeInfo* type, CPluginArg::TData::E_Choice single_or_array){ if (HasArgument(name)) { NCBI_THROW(CPluginException, eInvalidArg, string("Argument `") + name + string("' already exists")); } CRef<CPluginArg> arg(new CPluginArg()); arg->SetObject(type); arg->SetName(name); arg->SetDesc(desc); if (single_or_array == CPluginArg::TData::e_Array) { arg->SetList(); } Set().push_back(arg); return *arg;}// Add a default argument to the set of arguments. This function creates a// named argument with a default value of type string.CPluginArg&CPluginArgSet::AddDefaultArgument(const string& name, const string& desc, CPluginArg::EType type, const string& val){ if (HasArgument(name)) { NCBI_THROW(CPluginException, eInvalidArg, string("Argument `") + name + string("' already exists")); } CRef<CPluginArg> arg(new CPluginArg()); arg->SetName(name); arg->SetDesc(desc); arg->SetDefault(true); switch (type) { case CPluginArg::eInteger: arg->SetInteger(NStr::StringToInt(val)); break; case CPluginArg::eBoolean: arg->SetBoolean(NStr::StringToBool(val)); break; case CPluginArg::eDouble: arg->SetDouble(NStr::StringToDouble(val)); break; case CPluginArg::eString: arg->SetString(val); break; case CPluginArg::eFile: arg->SetFile(val); break; default: NCBI_THROW(CPluginException, eInvalidArg, "Attempt to create non-String argument type with " "string default value"); } Set().push_back(arg); return *arg;}CPluginArg&CPluginArgSet::AddFlag(const string& name, const string& desc){ return AddArgument(name, desc, CPluginArg::eBoolean);}CPluginArg&CPluginArgSet::AddDefaultFlag(const string& name, const string& desc, bool val){ return AddDefaultArgument(name, desc, CPluginArg::eBoolean, NStr::BoolToString(val));}// add an optional argument to the set of arguments. This supports an// optional default value argument. For non-built-in types, the default// value is ignored.CPluginArg&CPluginArgSet::AddOptionalArgument(const string& name, const string& desc, CPluginArg::EType type, CPluginArg::TData::E_Choice s_or_a){ if (HasArgument(name)) { NCBI_THROW(CPluginException, eInvalidArg, string("Argument `") + name + string("' already exists")); } CRef<CPluginArg> arg(new CPluginArg()); switch (type) { case CPluginArg::eBoolean: arg->SetBoolean(); break; case CPluginArg::eInteger: arg->SetInteger(); break; case CPluginArg::eDouble: arg->SetDouble(); break; case CPluginArg::eString: arg->SetString(); break; case CPluginArg::eFile: arg->SetFile(); break; case CPluginArg::eDocument: arg->SetDocument(); break; case CPluginArg::eObject: arg->SetObject(); break; default: case CPluginArg::eNotSet: NCBI_THROW(CPluginException, eInvalidArg, "Invalid argument type in AddArgument()"); } arg->SetName(name); arg->SetDesc(desc); arg->SetOptional(true); if (s_or_a == CPluginArg::TData::e_Array) { arg->SetList(); } Set().push_back(arg); return *arg;}CPluginArg&CPluginArgSet::AddOptionalArgument(const string& name, const string& desc, const CTypeInfo* info, CPluginArg::TData::E_Choice s_or_a){ if (HasArgument(name)) { NCBI_THROW(CPluginException, eInvalidArg, string("Argument `") + name + string("' already exists")); } CRef<CPluginArg> arg(new CPluginArg()); arg->SetName(name); arg->SetDesc(desc); arg->SetOptional(true); arg->SetObject(info); if (s_or_a == CPluginArg::TData::e_Array) { arg->SetList(); } Set().push_back(arg); return *arg;}//// SetConstraint() resets the constraints for a given named argument and adds a// new argument constraint//void CPluginArgSet::SetConstraint(const string& name, CPluginValueConstraint& constraint){ CPluginArg& arg = (*this)[name]; arg.SetConstraint().clear(); arg.SetConstraint().push_back( CRef<CPluginValueConstraint>(&constraint) );}//// AddConstraint() adds a constraint to a named argument//void CPluginArgSet::AddConstraint(const string& name, CPluginValueConstraint& constraint){ CPluginArg& arg = (*this)[name]; arg.SetConstraint().push_back( CRef<CPluginValueConstraint>(&constraint) );}END_objects_SCOPE // namespace ncbi::objects::END_NCBI_SCOPE/* * =========================================================================== * * $Log: PluginArgSet.cpp,v $ * Revision 1000.2 2004/06/01 20:53:35 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.21 * * Revision 1.21 2004/05/21 22:27:45 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.20 2004/01/21 14:13:16 dicuccio * Added AddFlag() and AddDefaultFlag() - front-ends to AddArgument() and * AddDefaultArgument() * * Revision 1.19 2003/12/16 20:39:47 jcherry * Added support for plugin arguments of type file * * Revision 1.18 2003/10/07 13:36:45 dicuccio * Renamed PluginURL* to PluginValue*. Moved validation code into CPluginUtils * * Revision 1.17 2003/07/23 19:14:08 dicuccio * Moved logic for validating plugin arguments into CPluginUtils. * * Revision 1.16 2003/07/22 15:30:47 dicuccio * Dropped support for CSeqVector as a named type. Changed to take advantage of * new Convert() API * * Revision 1.15 2003/06/20 14:48:16 dicuccio * Revised handling of default arguments - all built-in argument types are now * supported * * Revision 1.14 2003/06/02 16:06:20 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.13 2003/05/19 13:37:46 dicuccio * Moved gui/core/plugin/ --> gui/plugin/ * * Revision 1.12 2003/05/09 16:46:31 dicuccio * Added HasArgument() to check for argument existence. Made sure that all * AddArgument() functions will not add two arguments of the same name * * Revision 1.11 2003/04/30 16:27:15 dicuccio * Fixed thinko - forgot to actually set the object type when presented with an * object... * * Revision 1.10 2003/04/30 13:57:06 dicuccio * Added interface for specifying multiple constraints for a given argument * * Revision 1.9 2003/04/29 14:47:34 dicuccio * Added validation hook. Changed management of constraints to match new spec * * Revision 1.8 2003/04/25 14:14:58 dicuccio * Changed optional argument API - allow data model objects as optional * arguments using new plugin API; remove old "optional-and-default" notions * * Revision 1.7 2003/04/24 16:33:03 dicuccio * Simplified object type specification. Added parallel AddArgument() to * indicate argument type from CSerialObject * * Revision 1.6 2003/03/20 19:58:04 dicuccio * Added non-const op[] for indexing * * Revision 1.5 2003/03/10 23:01:18 kuznets * iterate -> ITERATE * * Revision 1.4 2003/03/03 14:50:56 dicuccio * Added plugin argument constraints - lower bound, upper bound, range, and * member-of-set * * Revision 1.3 2003/02/26 20:54:12 dicuccio * Wrapped insertion of options (multimap) to get around compilation issues in * Solaris * * Revision 1.2 2003/02/26 14:27:28 dicuccio * Removed unnecessary _TRACE() statements * * Revision 1.1 2003/02/24 13:03:17 dicuccio * Renamed classes in plugin spec: * CArgSeg --> CPluginArgSet * CArgument --> CPluginArg * CPluginArgs --> CPluginCommand * CPluginCommands --> CPluginCommandSet * * Revision 1.2 2003/02/21 17:16:53 dicuccio * Fixed compilation errors related to changes in plugin architecture * * Revision 1.1 2003/02/20 19:49:57 dicuccio * Created new plugin architecture, based on ASN.1 spec. Moved GBENCH frameowrk * over to use new plugin architecture.*** ===========================================================================*//* Original file checksum: lines: 64, chars: 1873, CRC32: 1571727e */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?