PluginArg.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:16k
- /*
- * ===========================================================================
- * PRODUCTION $Log: PluginArg.cpp,v $
- * PRODUCTION Revision 1000.2 2004/06/01 20:53:33 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.26
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: PluginArg.cpp,v 1000.2 2004/06/01 20:53:33 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: .......
- *
- * File Description:
- * .......
- *
- * 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/PluginArg.hpp>
- #include <gui/plugin/PluginObject.hpp>
- #include <gui/plugin/PluginValue.hpp>
- #include <gui/plugin/PluginValueConstraint.hpp>
- #include <gui/plugin/PluginValueRangeConstraint.hpp>
- #include <objects/seq/Bioseq.hpp>
- #include <objects/seqalign/Seq_align.hpp>
- #include <objects/seq/Seq_annot.hpp>
- #include <objects/seqfeat/Seq_feat.hpp>
- #include <objects/seqloc/Seq_id.hpp>
- #include <objects/seqloc/Seq_loc.hpp>
- #include <objects/seqres/Seq_graph.hpp>
- #include <objects/seqset/Bioseq_set.hpp>
- #include <objects/seqset/Seq_entry.hpp>
- #include <serial/iterator.hpp>
- // generated classes
- BEGIN_NCBI_SCOPE
- BEGIN_objects_SCOPE // namespace ncbi::objects::
- // destructor
- CPluginArg::~CPluginArg(void)
- {
- }
- // access the type for this argument
- CPluginArg::EType CPluginArg::GetType(void) const
- {
- CPluginValue::E_Choice choice = CPluginValue::e_not_set;
- if (GetData().IsSingle()) {
- choice = GetData().GetSingle().Which();
- } else if (GetData().IsArray() &&
- GetData().GetArray().size() != 0) {
- choice = GetData().GetArray().front()->Which();
- }
- switch (choice) {
- case CPluginValue::e_Integer:
- return eInteger;
- case CPluginValue::e_Double:
- return eDouble;
- case CPluginValue::e_Boolean:
- return eBoolean;
- case CPluginValue::e_String:
- return eString;
- case CPluginValue::e_Document:
- return eDocument;
- case CPluginValue::e_Object:
- return eObject;
- case CPluginValue::e_File:
- return eFile;
- default:
- return eNotSet;
- }
- }
- // accessors for specific sub-components
- const IDocument* CPluginArg::GetDocument(void) const
- {
- if (GetData().IsSingle()) {
- return GetData().GetSingle().GetDocument();
- } else {
- return GetData().GetArray().front()->GetDocument();
- }
- }
- const CObject* CPluginArg::GetObject(void) const
- {
- if (GetData().IsSingle()) {
- return GetData().GetSingle().GetObject();
- } else {
- return GetData().GetArray().front()->GetObject();
- }
- }
- const string& CPluginArg::GetObjectSubtype(void) const
- {
- if (GetData().IsSingle()) {
- return GetData().GetSingle().GetObjectSubtype();
- } else {
- return GetData().GetArray().front()->GetObjectSubtype();
- }
- }
- bool CPluginArg::IsEmpty(void) const
- {
- CTypeConstIterator<CPluginValue> iter(*this);
- for ( ; iter; ++iter) {
- if ( !iter->IsEmpty() ) {
- return false;
- }
- }
- return true;
- }
- void CPluginArg::ClearObjects()
- {
- switch (GetType()) {
- default:
- break;
- case eDocument:
- if (GetData().IsSingle()) {
- ResetData();
- SetDocument();
- } else {
- ResetData();
- SetDocument();
- SetList();
- }
- break;
- case eObject:
- {{
- string subtype = GetObjectSubtype();
- if (GetData().IsSingle()) {
- ResetData();
- SetObject(subtype);
- } else {
- ResetData();
- SetObject(subtype);
- SetList();
- }
- }}
- break;
- }
- }
- //
- // integer handlers
- //
- void CPluginArg::SetInteger(void)
- {
- SetData().Reset();
- SetData().SetSingle().SetInteger();
- }
- void CPluginArg::SetInteger(const string& arg)
- {
- SetData().Reset();
- SetData().SetSingle().SetInteger(arg);
- }
- void CPluginArg::SetInteger(int arg)
- {
- SetData().Reset();
- SetData().SetSingle().SetInteger(arg);
- }
- void CPluginArg::SetInteger(const list<int>& int_list)
- {
- SetData().Reset();
- ITERATE (list<int>, iter, int_list) {
- CRef<CPluginValue> value(new CPluginValue());
- value->SetInteger(*iter);
- SetData().SetArray().push_back(value);
- }
- }
- int CPluginArg::AsInteger(void) const
- {
- if ( !GetData().IsSingle() ) {
- NCBI_THROW(CPluginException, eInvalidArg,
- "Attempt to cast array argument to single object");
- }
- return GetData().GetSingle().AsInteger();
- }
- //
- // double handlers
- //
- void CPluginArg::SetDouble(void)
- {
- SetData().Reset();
- SetData().SetSingle().SetDouble();
- }
- void CPluginArg::SetDouble(const string& arg)
- {
- SetData().Reset();
- SetData().SetSingle().SetDouble(arg);
- }
- void CPluginArg::SetDouble(double arg)
- {
- SetData().Reset();
- SetData().SetSingle().SetDouble(arg);
- }
- void CPluginArg::SetDouble(const list<double>& double_list)
- {
- SetData().Reset();
- ITERATE (list<double>, iter, double_list) {
- CRef<CPluginValue> value(new CPluginValue());
- value->SetDouble(*iter);
- SetData().SetArray().push_back(value);
- }
- }
- double CPluginArg::AsDouble(void) const
- {
- if ( !GetData().IsSingle() ) {
- NCBI_THROW(CPluginException, eInvalidArg,
- "Attempt to cast array argument to single object");
- }
- return GetData().GetSingle().AsDouble();
- }
- //
- // boolean handlers
- //
- void CPluginArg::SetBoolean(void)
- {
- SetData().Reset();
- SetData().SetSingle().SetBoolean();
- }
- void CPluginArg::SetBoolean(bool arg)
- {
- SetData().Reset();
- SetData().SetSingle().SetBoolean(arg);
- }
- void CPluginArg::SetBoolean(const list<bool>& bool_list)
- {
- SetData().Reset();
- ITERATE (list<bool>, iter, bool_list) {
- CRef<CPluginValue> value(new CPluginValue());
- value->SetBoolean(*iter);
- SetData().SetArray().push_back(value);
- }
- }
- bool CPluginArg::AsBoolean(void) const
- {
- if ( !GetData().IsSingle() ) {
- NCBI_THROW(CPluginException, eInvalidArg,
- "Attempt to cast array argument to single object");
- }
- return GetData().GetSingle().AsBoolean();
- }
- //
- // string handlers
- //
- void CPluginArg::SetString(void)
- {
- SetData().Reset();
- SetData().SetSingle().SetString();
- }
- void CPluginArg::SetString(const string& arg)
- {
- SetData().Reset();
- SetData().SetSingle().SetString(arg);
- }
- void CPluginArg::SetString(const list<string>& string_list)
- {
- SetData().Reset();
- ITERATE (list<string>, iter, string_list) {
- CRef<CPluginValue> value(new CPluginValue());
- value->SetString(*iter);
- SetData().SetArray().push_back(value);
- }
- }
- const string& CPluginArg::AsString(void) const
- {
- if ( !GetData().IsSingle() ) {
- NCBI_THROW(CPluginException, eInvalidArg,
- "Attempt to cast array argument to single object");
- }
- return GetData().GetSingle().AsString();
- }
- //
- // file handlers
- //
- void CPluginArg::SetFile(void)
- {
- SetData().Reset();
- SetData().SetSingle().SetFile();
- }
- void CPluginArg::SetFile(const string& arg)
- {
- SetData().Reset();
- SetData().SetSingle().SetFile(arg);
- }
- void CPluginArg::SetFile(const list<string>& file_list)
- {
- SetData().Reset();
- ITERATE (list<string>, iter, file_list) {
- CRef<CPluginValue> value(new CPluginValue());
- value->SetFile(*iter);
- SetData().SetArray().push_back(value);
- }
- }
- const string& CPluginArg::AsFile(void) const
- {
- if ( !GetData().IsSingle() ) {
- NCBI_THROW(CPluginException, eInvalidArg,
- "Attempt to cast array argument to single object");
- }
- return GetData().GetSingle().AsFile();
- }
- //
- // document handlers
- //
- void CPluginArg::SetDocument(void)
- {
- SetData().Reset();
- CPluginValue& value = SetData().SetSingle();
- value.SetDocument();
- }
- void CPluginArg::SetDocument(const IDocument& arg)
- {
- SetData().Reset();
- SetData().SetSingle().SetDocument(arg);
- }
- void CPluginArg::SetDocument(const TValues& Document_list)
- {
- SetData().Reset();
- ITERATE (TValues, iter, Document_list) {
- CRef<CPluginValue> value(new CPluginValue());
- value->SetDocument(*(*iter)->GetDocument());
- SetData().SetArray().push_back(value);
- }
- }
- const IDocument& CPluginArg::AsDocument(void) const
- {
- if ( !GetData().IsSingle() ) {
- NCBI_THROW(CPluginException, eInvalidArg,
- "Attempt to cast array argument to single object");
- }
- return GetData().GetSingle().AsDocument();
- }
- //
- // object handlers
- //
- void CPluginArg::SetObject(const string& type)
- {
- SetData().Reset();
- SetData().SetSingle().SetObject(type);
- }
- void CPluginArg::SetObject(const CTypeInfo* info)
- {
- SetData().Reset();
- SetData().SetSingle().SetObject(info);
- }
- void CPluginArg::SetObject(const IDocument& doc, const CObject& obj)
- {
- SetData().Reset();
- SetData().SetSingle().SetObject(doc, obj);
- }
- void CPluginArg::SetObject(const TValues& obj_list)
- {
- SetData().Reset();
- ITERATE (TValues, iter, obj_list) {
- SetData().SetArray().push_back
- (CRef<CPluginValue> (const_cast<CPluginValue*>(iter->GetPointer())));
- }
- }
- const CObject& CPluginArg::AsObject(void) const
- {
- if ( !GetData().IsSingle() ) {
- NCBI_THROW(CPluginException, eInvalidArg,
- "Attempt to cast array argument to single object");
- }
- return GetData().GetSingle().AsObject();
- }
- //
- // generic list accessors
- //
- void CPluginArg::SetList(void)
- {
- if (GetData().IsSingle()) {
- CRef<CPluginValue> value(&SetData().SetSingle());
- SetData().Reset();
- SetData().SetArray().push_back(value);
- }
- }
- void CPluginArg::SetList(const TValues& args)
- {
- SetData().Reset();
- SetData().SetArray();
- ITERATE (TValues, iter, args) {
- CPluginValue* value = const_cast<CPluginValue*> (iter->GetPointer());
- SetData().SetArray().push_back( CRef<CPluginValue>(value));
- }
- }
- void CPluginArg::AsList(TValues& arg) const
- {
- if ( !GetData().IsArray() ) {
- NCBI_THROW(CPluginException, eInvalidArg,
- "Attempt to cast single argument to array");
- }
- arg.clear();
- ITERATE (TData::TArray, iter, GetData().GetArray()) {
- arg.push_back(*iter);
- }
- }
- END_objects_SCOPE // namespace ncbi::objects::
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- *
- * $Log: PluginArg.cpp,v $
- * Revision 1000.2 2004/06/01 20:53:33 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.26
- *
- * Revision 1.26 2004/05/21 22:27:45 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.25 2004/03/08 20:21:06 jcherry
- * Fixed object argument clearing
- *
- * Revision 1.24 2004/02/04 13:36:42 dicuccio
- * Implemented resetting of object-based arguments
- *
- * Revision 1.23 2003/12/23 20:23:21 jcherry
- * Make argument values persist across invocations of plugin
- *
- * Revision 1.22 2003/12/16 20:39:47 jcherry
- * Added support for plugin arguments of type file
- *
- * Revision 1.21 2003/10/27 17:44:33 dicuccio
- * Reworked CPluginValue to be a variant. Removed ad hoc URL encoding
- *
- * Revision 1.20 2003/10/07 13:36:45 dicuccio
- * Renamed PluginURL* to PluginValue*. Moved validation code into CPluginUtils
- *
- * Revision 1.19 2003/09/04 14:03:20 dicuccio
- * Use IDocument instead of CDocument
- *
- * Revision 1.18 2003/07/23 19:14:08 dicuccio
- * Moved logic for validating plugin arguments into CPluginUtils.
- *
- * Revision 1.17 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.16 2003/06/26 15:33:39 dicuccio
- * Moved GetURLValue() from PluginURL.hpp to plugin_utils.hpp. Fixed compilation
- * errors relating to missing #includes
- *
- * Revision 1.15 2003/06/25 17:02:56 dicuccio
- * Split CPluginHandle into a handle (pointer-to-implementation) and
- * implementation file. Lots of #include file clean-ups.
- *
- * Revision 1.14 2003/05/19 13:37:46 dicuccio
- * Moved gui/core/plugin/ --> gui/plugin/
- *
- * Revision 1.13 2003/05/09 16:45:51 dicuccio
- * Cleaned up IsValid(). Added IsEmpty() - useful check for optional arguments
- *
- * Revision 1.12 2003/05/06 15:56:38 dicuccio
- * Added _TRACE() for all failed object constraints - aids debugging. Removed
- * unnecessary const_cast<> following object conversion
- *
- * Revision 1.11 2003/04/30 13:53:57 dicuccio
- * Fixed bug in setting of integral argument types - don't reset the whole object,
- * just the data.
- *
- * Revision 1.10 2003/04/29 14:47:04 dicuccio
- * Added internal API for checking constraints of object arguments. Reworked
- * constraint code in general
- *
- * Revision 1.9 2003/04/24 16:31:57 dicuccio
- * Simplified object storage - use a more generic mechanism for specifying objects.
- *
- * Revision 1.8 2003/03/25 19:40:30 dicuccio
- * Added CSeq_annot as a named type
- *
- * Revision 1.7 2003/03/25 13:12:03 dicuccio
- * Added checking of constraint values in IsValid()
- *
- * Revision 1.6 2003/03/10 23:01:18 kuznets
- * iterate -> ITERATE
- *
- * Revision 1.5 2003/03/10 16:03:42 dicuccio
- * Added accessors for an argument's associated document and abstract object
- *
- * 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 14:28:05 dicuccio
- * Changed all setters to use const objects, to avoid using const_cast<> outside
- * of this class
- *
- * Revision 1.2 2003/02/25 14:46:24 dicuccio
- * Changed internal representation of plugin URL. Changed data model argument
- * types to support an implied document argument as well - this enables such
- * arguments to pass scopes with the argument value
- *
- * 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.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: 1879, CRC32: 6874a1e4 */