pluginvalue.cpp

来自「ncbi源码」· C++ 代码 · 共 522 行

CPP
522
字号
/* * =========================================================================== * PRODUCTION $Log: PluginValue.cpp,v $ * PRODUCTION Revision 1000.3  2004/06/01 20:53:55  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9 * PRODUCTION * =========================================================================== *//* $Id: PluginValue.cpp,v 1000.3 2004/06/01 20:53:55 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/PluginValue.hpp>#include <gui/plugin/PluginObject.hpp>#include <serial/typeinfo.hpp>// generated classesBEGIN_NCBI_SCOPEBEGIN_objects_SCOPE // namespace ncbi::objects::// constructorCPluginValue::CPluginValue(void){}CPluginValue::CPluginValue(int val){    SetInteger(val);}CPluginValue::CPluginValue(double val){    SetDouble(val);}CPluginValue::CPluginValue(bool val){    SetBoolean(val);}CPluginValue::CPluginValue(const string& str){    SetString(str);}CPluginValue::CPluginValue(const IDocument& doc){    SetDocument(doc);}CPluginValue::CPluginValue(const IDocument& doc, const CObject& obj){    SetObject(doc, obj);}CPluginValue::CPluginValue(const CTypeInfo* info){    SetObject(info);}// destructorCPluginValue::~CPluginValue(void){}const string& CPluginValue::SetInteger(){    return Tparent::SetInteger();}void CPluginValue::SetInteger(const string& val){    Tparent::SetInteger(val);}void CPluginValue::SetInteger(int val){    Tparent::SetInteger(NStr::IntToString(val));}const string& CPluginValue::SetDouble(){    return Tparent::SetDouble();}void CPluginValue::SetDouble(const string& val){    Tparent::SetDouble(val);}void CPluginValue::SetDouble(double val){    Tparent::SetDouble(NStr::DoubleToString(val));}const string& CPluginValue::SetBoolean(){    return Tparent::SetBoolean();}void CPluginValue::SetBoolean(const string& val){    Tparent::SetBoolean(val);}void CPluginValue::SetBoolean(bool val){    Tparent::SetBoolean(NStr::BoolToString(val));}void CPluginValue::SetObject(const IDocument& doc, const CObject& obj){	CPluginObject* obj_var = NULL;	if (dynamic_cast<const IDocument*>(&obj)) {		obj_var = &Tparent::SetDocument();	} else {		obj_var = &Tparent::SetObject();	}	if (obj_var) {		obj_var->SetObject(&doc, &obj);	}}void CPluginValue::SetObject(const string& type){    CPluginObject& obj_var = Tparent::SetObject();    obj_var.SetObject(type);}void CPluginValue::SetObject(const CTypeInfo* info){    CPluginObject& obj_var = Tparent::SetObject();    obj_var.SetObject(info);}void CPluginValue::SetDocument(const IDocument& doc){    CPluginObject& obj_var = Tparent::SetDocument();    obj_var.SetDocument(&doc);}void CPluginValue::SetDocument(void){    CPluginObject& obj_var = Tparent::SetDocument();    obj_var.SetDocument(NULL);}const string& CPluginValue::GetObjectSubtype(void) const{    if (IsDocument()) {        return Tparent::GetDocument().GetSubtype();    } else if (IsObject()) {        return Tparent::GetObject().GetSubtype();    }    return kEmptyStr;}bool CPluginValue::AsBoolean(void) const{    if ( !IsBoolean() ) {        NCBI_THROW(CPluginException, eInvalidArg,                   "Attempt to access non-boolean value as boolean");    }    const string& str = GetBoolean();    if (str.empty()) {        return false;    } else {        return NStr::StringToBool(GetBoolean());    }}int CPluginValue::AsInteger(void) const{    if ( !IsInteger() ) {        NCBI_THROW(CPluginException, eInvalidArg,                   "Attempt to access non-integer value as integer");    }    if (GetInteger().empty()) {        NCBI_THROW(CPluginException, eInvalidArg,                   "Attempt to access invalid integer value");    }    return NStr::StringToInt(GetInteger());}double CPluginValue::AsDouble(void) const{    if ( !IsDouble() ) {        NCBI_THROW(CPluginException, eInvalidArg,                   "Attempt to access non-double value as double");    }    if (GetDouble().empty()) {        NCBI_THROW(CPluginException, eInvalidArg,                   "Attempt to access invalid double value");    }    return NStr::StringToDouble(GetDouble());}const string& CPluginValue::AsString(void) const{    switch (Which()) {    case e_Integer:        _TRACE("CPluginValue::AsString(): access to integer value as string");        return GetInteger();    case e_Double:        _TRACE("CPluginValue::AsString(): access to double value as string");        return GetDouble();    case e_Boolean:        _TRACE("CPluginValue::AsString(): access to boolean value as string");        return GetBoolean();    case e_File:        _TRACE("CPluginValue::AsString(): access to file value as string");        return GetFile();    case e_String:        return GetString();    case e_Document:    case e_Object:    default:        NCBI_THROW(CPluginException, eInvalidArg,                   "Attempt to access non-convertable value as string");    }}const string& CPluginValue::AsFile(void) const{    if ( !IsFile() ) {        NCBI_THROW(CPluginException, eInvalidArg,                   "Attempt to access non-file value as file");    }    if (GetFile().empty()) {        NCBI_THROW(CPluginException, eInvalidArg,                   "Attempt to access invalid file value");    }    return GetFile();}const IDocument& CPluginValue::AsDocument(void) const{    if (IsDocument()) {        if (GetDocument()) {            return *GetDocument();        }        NCBI_THROW(CPluginException, eInvalidArg,                   "Attempt to access NULL document");    }    NCBI_THROW(CPluginException, eInvalidArg,               "Attempt to access non-document value as document");}const CObject& CPluginValue::AsObject(void) const{    if (IsObject()) {        if (GetObject()) {            return *GetObject();        }        NCBI_THROW(CPluginException, eInvalidArg,                   "Attempt to access NULL object");    }    NCBI_THROW(CPluginException, eInvalidArg,               "Attempt to access non-object value as object");}//// determine if this URL is empty//bool CPluginValue::IsEmpty(void) const{    switch (Which()) {    case e_String:        return (IsString()  &&  GetString().empty());    case e_File:        return (IsFile()  &&  GetFile().empty());    case e_Integer:        return (IsInteger()  &&  GetInteger().empty());    case e_Double:        return (IsDouble()  &&  GetDouble().empty());    case e_Boolean:        return (IsBoolean()  &&  GetBoolean().empty());    case e_Object:        return (IsObject()  &&  Tparent::GetObject().IsEmpty());    case e_Document:        return (IsDocument()  &&  Tparent::GetDocument().IsEmpty());    default:        // unhandled = always invalid, always empty        return true;    }}END_objects_SCOPE // namespace ncbi::objects::END_NCBI_SCOPE/* * =========================================================================== * * $Log: PluginValue.cpp,v $ * Revision 1000.3  2004/06/01 20:53:55  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9 * * Revision 1.9  2004/06/01 18:10:03  dicuccio * Interpret empty string as false for boolean arguments * * Revision 1.8  2004/05/21 22:27:46  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.7  2004/02/04 13:36:43  dicuccio * Implemented resetting of object-based arguments * * Revision 1.6  2003/12/22 19:24:49  dicuccio * Added getters/setters for types to forward from base class - necessary given change in variant * * Revision 1.5  2003/12/16 21:51:11  jcherry * Processing of file parameters * * Revision 1.4  2003/12/16 20:39:47  jcherry * Added support for plugin arguments of type file * * Revision 1.3  2003/11/03 18:35:54  dicuccio * Fixed setting of objects - SetObject() with a document is the same as * SetDocument() * * Revision 1.2  2003/10/27 17:44:33  dicuccio * Reworked CPluginValue to be a variant.  Removed ad hoc URL encoding * * Revision 1.1  2003/10/07 13:36:45  dicuccio * Renamed PluginURL* to PluginValue*.  Moved validation code into CPluginUtils * * Revision 1.23  2003/09/04 14:03:20  dicuccio * Use IDocument instead of CDocument * * Revision 1.22  2003/08/04 17:30:48  dicuccio * Endoce an object's subtype as "Object" if no type is known * * Revision 1.21  2003/07/31 17:02:00  dicuccio * Fixed thinko: in setting an object of type document, make sure to set the * object type to document * * Revision 1.20  2003/07/23 19:14:08  dicuccio * Moved logic for validating plugin arguments into CPluginUtils. * * Revision 1.19  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.18  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.17  2003/05/19 13:37:46  dicuccio * Moved gui/core/plugin/ --> gui/plugin/ * * Revision 1.16  2003/05/09 16:47:45  dicuccio * Added IsEmpty() - useful check for optional arguments.  Changed IsValid() to * report false for empty arguments of built-in types * * Revision 1.15  2003/04/29 14:48:07  dicuccio * Unified internal representation of all CObject-derived arguments * * Revision 1.14  2003/04/25 14:14:20  dicuccio * Remove a hunk fo dead code * * Revision 1.13  2003/04/24 19:01:26  ucko * Remove unbalanced quote from #if-ed out region (still affected some * compilers) * * Revision 1.12  2003/04/24 16:34:08  dicuccio * Large clean-up.  Siplified object type specification and retrieval. * * Revision 1.11  2003/03/28 17:11:10  dicuccio * Added PostRead() to handle type derivation * * Revision 1.10  2003/03/25 19:40:30  dicuccio * Added CSeq_annot as a named type * * Revision 1.9  2003/03/20 21:17:16  dicuccio * Fixed checking of m_Type in retrieval macros to reflect real type returned by * GetType() * * Revision 1.8  2003/03/17 14:50:19  dicuccio * Use dynamic_cast<> where appropriate * * Revision 1.7  2003/03/10 23:01:18  kuznets * iterate -> ITERATE * * Revision 1.6  2003/02/28 15:08:22  dicuccio * Added overloaded Assign().  Commented out some unnecessary _TRACE() statements * * Revision 1.5  2003/02/27 16:25:13  dicuccio * Fixed bug in encoding of document - was encoded as integer (ooops). * * Revision 1.4  2003/02/26 20:54:12  dicuccio * Wrapped insertion of options (multimap) to get around compilation issues in * Solaris * * Revision 1.3  2003/02/26 14:28:59  dicuccio * Converted all setters to take const arguments, to avoid using const_cast<> * outside of this class.  Added beefed up value validation * * Revision 1.2  2003/02/25 14:46:24  dicuccio * Changed internal representation of plugin URL.  Changed data model value * types to support an implied document value as well - this enables such * arguments to pass scopes with the value 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: 1864, CRC32: 5ef4a2cd */

⌨️ 快捷键说明

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