本文整理汇总了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);
}
示例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);
}
示例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;
}