plugin_args_as_strs.cpp

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

CPP
213
字号
/* * =========================================================================== * PRODUCTION $Log: plugin_args_as_strs.cpp,v $ * PRODUCTION Revision 1000.3  2004/06/01 20:56:09  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9 * PRODUCTION * =========================================================================== *//*  $Id: plugin_args_as_strs.cpp,v 1000.3 2004/06/01 20:56:09 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:  Josh Cherry * * File Description:  Convert plugin arguments to key/value string pairs * */#include <ncbi_pch.hpp>#include "plugin_args_as_strs.hpp"#include <corelib/ncbistd.hpp>#include <gui/core/idocument.hpp>#include <gui/core/plugin_utils.hpp>#include <gui/plugin/PluginValue.hpp>#include <gui/plugin/PluginInfo.hpp>#include <gui/plugin/PluginCommandSet.hpp>#include <gui/plugin/PluginValueConstraint.hpp>#include <gui/core/version.hpp>#include <gui/objutils/utils.hpp>#include <objmgr/seq_vector.hpp>#include <objmgr/util/sequence.hpp>#include <objmgr/seq_vector.hpp>#include <cgi/ncbicgi.hpp>#include <util/regexp.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);// conversion of values for non-object typesstatic string s_ArgToStr(const CPluginValue& value){    switch (value.Which()) {    case CPluginValue::e_Integer:        return NStr::IntToString(value.AsInteger());    case CPluginValue::e_Double:        return NStr::DoubleToString(value.AsDouble());    case CPluginValue::e_String:        return value.AsString();    case CPluginValue::e_Boolean:        return NStr::IntToString(value.AsBoolean());    default:        throw logic_error("Couldn't convert this type of "                          "CPluginValue to string");    }}void PluginArgsAsStrs(const CPluginArgSet::Tdata& argset,                      vector<string>& keys,                      vector<string>& values){    keys.clear();    values.clear();        ITERATE (CPluginArgSet::Tdata, arg_iter, argset) {        const CPluginArg& arg = **arg_iter;        string name = arg.GetName();        if (NStr::StartsWith(name, "__")) {            // these are for internal use only            continue;        }        if (arg.IsEmpty()) {            if (arg.GetOptional()) {                // OK for optional argument to be empty                continue;            } else {                throw logic_error("empty non-optional argument " + name);            }        }        if (!CPluginUtils::IsValid(arg)) {            throw logic_error("invalid argument " + name);        }        string value;        if (arg.GetType() == CPluginArg::eObject) {            if (!(arg.GetObjectSubtype() == "Seq-loc")) {                throw logic_error("can't handle non-Seq-loc eObject");            }            plugin_args::TLocList locs;            GetArgValue(arg, locs);            ITERATE (plugin_args::TLocList, iter, locs) {                const CSeq_loc&  loc = *iter->second;                const IDocument& doc = *iter->first;                try {                    CBioseq_Handle handle =                         doc.GetScope().GetBioseqHandle(loc);                    CSeqVector vec = handle                        .GetSequenceView(loc, CBioseq_Handle::eViewConstructed,                                         CBioseq_Handle::eCoding_Iupac);                    string seq;                    vec.GetSeqData(0, vec.size(), seq);                    NStr::ToUpper(seq);                    // write sequence, title, and short title as a                    // cgi query string; this will wind up as a                    // cgi string within a cgi string (doubly escaped)                    value = "short_title="                         + URL_EncodeString(doc.GetShortTitle())                        + "&title="                        + URL_EncodeString(doc.GetTitle())                        + "&seq=" + seq;                    keys.push_back(name);                    values.push_back(value);                }                catch (...) {                    string str = CPluginUtils::GetLabel(loc, &doc.GetScope());                    LOG_POST(Error << "Error processing location " << str);                }            }        } else {            if (arg.GetData().IsSingle()) {                value = s_ArgToStr(arg.GetData().GetSingle());                keys.push_back(name);                values.push_back(value);            } else {                const CPluginArg_Base::C_Data::TArray& value_list =                     arg.GetData().GetArray();                ITERATE (CPluginArg_Base::C_Data::TArray,                         value_iter, value_list) {                    value = s_ArgToStr(**value_iter);                    keys.push_back(name);                    values.push_back(value);                }            }        }    }}END_NCBI_SCOPE/* * =========================================================================== * $Log: plugin_args_as_strs.cpp,v $ * Revision 1000.3  2004/06/01 20:56:09  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9 * * Revision 1.9  2004/05/21 22:27:47  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.8  2004/05/20 12:38:29  dicuccio * Added missing includes previously acquired through gui/objutils/utils.hpp (seq_vector.hpp, alignment manager * * Revision 1.7  2004/05/15 03:17:04  ucko * Add missing #includes (formerly indirect?) * * Revision 1.6  2004/05/03 13:05:42  dicuccio * gui/utils --> gui/objutils where needed * * Revision 1.5  2004/01/07 15:50:39  dicuccio * Adjusted for API change in CPluginUtils::GetLabel().  Standardized exception * reporting in algorithms. * * Revision 1.4  2003/12/02 15:30:34  jcherry * Differentiate between empty and invalid arguments * * Revision 1.3  2003/12/01 23:14:34  jcherry * Don't throw if an optional argument is invalid * * Revision 1.2  2003/11/26 17:13:08  dicuccio * Lots of code clean-up.  CHanged names of algorithms to * CAlgoWebServices{Init} * * Revision 1.1  2003/11/25 19:08:52  jcherry * Initial version * * =========================================================================== */

⌨️ 快捷键说明

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