当前位置: 首页>>代码示例>>C++>>正文


C++ JSONNode::Append方法代码示例

本文整理汇总了C++中JSONNode::Append方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONNode::Append方法的具体用法?C++ JSONNode::Append怎么用?C++ JSONNode::Append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JSONNode的用法示例。


在下文中一共展示了JSONNode::Append方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: replace

void 
ProgrammableOpAttributes::AddPythonScript(const std::string& name, const stringVector& atts, const std::string& code)
{
    JSONNode vars = JSONNode::JSONArray();
    for(int i = 0; i < atts.size(); ++i)
        vars.Append(atts[i]);

    JSONNode node;
    node["vars"] = vars;

    std::ostringstream pwrapper;

    pwrapper << "from visit_internal_funcs import *\n"
             << code
             << "\n";
    std::string escapedCode = pwrapper.str();
    replace(escapedCode, "\n", "\\n");

    node["source"] = escapedCode;

    script["scripts"][name] = node;

    //update scriptmap
    scriptMap = script.ToString();
    Select(ID_scriptMap, (void *)&scriptMap);
}
开发者ID:HarinarayanKrishnan,项目名称:VisIt28RC_Trunk,代码行数:26,代码来源:ProgrammableOpAttributes.C

示例2: JSONNode

void
ProgrammableOpAttributes::LoadRKernel(const std::string& name, const JSONNode &atts, const std::string& code)
{
    script = JSONNode();
    scriptMap = "";

    stringVector args;
    SetupPipeline(atts,args,name);

    JSONNode vars = JSONNode::JSONArray();
    for(int i = 0; i < args.size(); ++i)
        vars.Append(args[i]);

    JSONNode node;
    node["vars"] = vars;

    std::string argstring = "";
    for(size_t i = 0; i < args.size(); ++i)
        argstring += args[i] + (i == args.size()-1 ? "" : ",");

    std::ostringstream rwrapper;

    rwrapper << "import rpy2,numpy\n"
             << "import rpy2.robjects as robjects\n"
             << "import rpy2.robjects.numpy2ri\n"
             << "rpy2.robjects.numpy2ri.activate()\n"
             << name << " = robjects.r('''\n"
             << code << "\n"
             << "''')\n"
             << "setout(numpy.asarray(" << name << "(" << argstring << ")))\n";

    std::string escapedCode = rwrapper.str();
    //std::cout << escapedCode << std::endl;
    replace(escapedCode, "\n", "\\n");

    node["source"] = escapedCode;

    script["scripts"][name] = node;

    //update scriptmap
    scriptMap = script.ToString();

    AddNode(name,name);
    AddFinalOutputConnection(name);

}
开发者ID:HarinarayanKrishnan,项目名称:VisIt28RC_Trunk,代码行数:46,代码来源:ProgrammableOpAttributes.C

示例3: if

bool
GetJSONVectorFromPyObject(PyObject *obj, JSONNode &vec)
{
    bool retval = true;

    if(obj == 0)
    {
        retval = false;
    }
    else if(PyBool_Check(obj))
    {
        vec = obj == Py_True ? true : false;
    }
    else if(PyTuple_Check(obj))
    {
        // Extract arguments from the tuple.
        vec = JSONNode::JSONArray();

        for(int i = 0; i < PyTuple_Size(obj); ++i)
        {
            PyObject *item = PyTuple_GET_ITEM(obj, i);
            JSONNode node;
            if(!GetJSONVectorFromPyObject(item,node))
                return false;
            vec.Append(node);
        }
    }
    else if(PyList_Check(obj))
    {
        vec = JSONNode::JSONArray();

        // Extract arguments from the list.
        for(int i = 0; i < PyList_Size(obj); ++i)
        {
            PyObject *item = PyList_GET_ITEM(obj, i);
            JSONNode node;
            if(!GetJSONVectorFromPyObject(item,node))
                return false;
            vec.Append(node);
        }
    }
    else if(PyString_Check(obj))
    {
        vec = PyString_AS_STRING(obj);
    }
    else if(PyInt_Check(obj))
    {
        vec = PyInt_AsLong(obj);
    }
    else if(PyFloat_Check(obj))
    {
        vec = PyFloat_AsDouble(obj);
    }
    else if(PyDict_Check(obj))
    {
        vec = JSONNode::JSONObject();

        PyObject* keys = PyDict_Keys(obj);
        for(int i = 0; i < PyList_Size(keys); ++i)
        {
            PyObject *item = PyList_GET_ITEM(keys, i);
            if(!PyString_Check(item))
            {
                std::cerr << "unknown element type, skipping " << std::endl;
                continue;
            }

            JSONNode node;

            std::string key = PyString_AsString(item);

            PyObject *value = PyDict_GetItem(obj,item);
            if(!GetJSONVectorFromPyObject(value,node))
                return false;
            vec[key] = node;
        }
    }
    else
    {
        retval = false;
        VisItErrorFunc("The object could not be converted to a "
                       "vector of strings.");
    }

    return retval;
}
开发者ID:burlen,项目名称:visit_vtk_7_src,代码行数:86,代码来源:PyProgrammableOpAttributes.C


注:本文中的JSONNode::Append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。