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


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

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


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

示例1: main

int main(){
JSONNode n = read_formatted("input.json");
JSONNode n1 = read_formatted("input1.json");
test *tst = new test();
int status;
//n.set_name(abi::__cxa_demangle(typeid(*tst).name(), 0,0,&status ));
n.push_back(JSONNode("FF::Node_Subclass", abi::__cxa_demangle(typeid(*tst).name(), 0,0,&status )));
if(n1.type()==JSON_NULL){
   std::cout<<"null"<<std::endl; 
}
JSONNode n2 (JSON_NODE);
n2.set_name("Child1");
n2.push_back(JSONNode("id",1));
n.set_name("Parrent");
n.push_back(n2);
JSONNode::iterator it =n.find_nocase("String Node");
if(it->as_string()=="-1"){std::cout<<it->as_int()<<std::endl;}
it->as_int()!=-1 ? (std::cout<< "it is"<<std::endl) : (std::cout<<"Mapper Warning: processor id is -1"<<std::endl);
if (n.at("String Node")==""){
std::cout<<"ha ha ha"<<std::endl;
}
std::cout<< "This is the name: "<<n.name()<<std::endl;
n.at("String Node")="";
bool x =true;
n.push_back(JSONNode("MyBOOLNODE", x));
n["String Node"]=x;
//n.erase(n.find_nocase("String Node"));
write_formatted(n1, "out1.json");
write_formatted(n, "out.json");
JSONNode::const_iterator i =n.find_nocase("ArrayOfNumbers");
std::string strLowerCase= "ARRAYOfNUMbers"; 
std::string myTest= "ff::ff_farm<adaptive_loadbalancer, ff::ff_gatherer>";
std::transform(myTest.begin(), myTest.end(), myTest.begin(), ::tolower);
std::size_t found = myTest.find("adaptive_loadbalancer");
if (found!=std::string::npos)
  std::cout << "first 'needle' found at: " << found << '\n';

std::cout<< "here it is: " << myTest<< std::endl;
JSONNode n_ar = n.at("ArrayOfNumbers");
std::cout<<"here :"<<n_ar[0].as_int()<< std::endl;
// if (0 == strcasecmp("hello", "HELLO"))

if(strcasecmp((i->name()).c_str(), strLowerCase.c_str()) == 0)
//if(!(n2.empty()))
  std::cout<<"haha"<<i->size()<<std::endl;
std::cout<<i->name()<<std::endl;
std::cout<<((i->as_array()).begin()+1)->as_int()<<std::endl;
std::cout<<((i->as_array()).at(1)).as_int()<<std::endl;
std::cout<<((i->as_array())[1]).as_int()<<std::endl;
//std::cout<<i->as_string()<<std::endl;
//JSONNode c(JSON_ARRAY);
//c=i->as_array();
//JSONNode nk= c.at(0);
//JSONNode::const_iterator it = c.begin();
//std::cout <<nk.as_int()<<std::endl;
return 0;
}
开发者ID:mehdi-goli,项目名称:MC-FastFlow-PEI,代码行数:57,代码来源:test_parser.cpp

示例2: toJSON

JSONNode LumiverseFloat::toJSON(string name) {
  JSONNode node;
  node.set_name(name);

  node.push_back(JSONNode("type", getTypeName()));
  node.push_back(JSONNode("val", m_val));
  node.push_back(JSONNode("default", m_default));
  node.push_back(JSONNode("max", m_max));
  node.push_back(JSONNode("min", m_min));

  return node;
}
开发者ID:Chelsea21,项目名称:Lumiverse,代码行数:12,代码来源:LumiverseFloat.cpp

示例3: toJSON

JSONNode Keyframe::toJSON() {
  JSONNode keyframe;
  keyframe.push_back(JSONNode("t", (unsigned long) t));
  if (val != nullptr) {
    keyframe.push_back(val->toJSON("val"));
  }
  keyframe.push_back(JSONNode("useCurrentState", useCurrentState));

  if (timelineID != "") {
    keyframe.push_back(JSONNode("timelineID", timelineID));
    keyframe.push_back(JSONNode("timelineOffset", (unsigned long)timelineOffset));
  }

  return keyframe;
}
开发者ID:ebshimizu,项目名称:Lumiverse,代码行数:15,代码来源:Keyframe.cpp

示例4: toJSON

JSONNode Programmer::toJSON() {
  JSONNode root;
  root.set_name("programmer");

  JSONNode devices;
  devices.set_name("devices");

  for (const auto& kvp : m_devices) {
    devices.push_back(kvp.second->toJSON());
  }

  root.push_back(devices);

  root.push_back(captured.toJSON("captured"));

  return root;
}
开发者ID:ebshimizu,项目名称:Lumiverse,代码行数:17,代码来源:Programmer.cpp

示例5: sframe_row_to_json

/**
 * Write column_names and column_values (as a row in the sframe) to JSONNode.
 */
void sframe_row_to_json(const std::vector<std::string>& column_names,
                        const std::vector<flexible_type>& column_values,
                        JSONNode& node) {
    DASSERT_EQ(column_names.size(), column_values.size());
    for (size_t i = 0; i < column_names.size(); ++i) {
        node.push_back(flexible_type_to_json(column_values[i], column_names[i]));
    }
}
开发者ID:hoytak,项目名称:SFrame,代码行数:11,代码来源:sframe_io.cpp

示例6: getAllCurrenciesInJsonFormat

ptree currencyHandler::getAllCurrenciesInJsonFormat() {
	JSONNode n(JSON_NODE);

	n.push_back(JSONNode("String Node", "String Value"));
	n.push_back(JSONNode("Integer Node", 42));
	n.push_back(JSONNode("Floating Point Node", 3.14));
	n.push_back(JSONNode("Boolean Node", true));
	std::string jc = n.write_formatted();
	std::cout << jc << std::endl;


	JSONNode n(JSON_NODE);
	n.push_back(JSONNode("RootA", "Hello World"));
	JSONNode c(JSON_ARRAY);
	c.set_name("ArrayOfNumbers");
	c.push_back(JSONNode("", 16));
	c.push_back(JSONNode("", 42));
	c.push_back(JSONNode("", 128));
	n.push_back(c);
	std::string jc = n.write_formatted();
	std::cout << jc << std::endl;


	std::string json = "{\"RootA\":\"Value in parent node\",\"ChildNode\":{\"ChildA\":\"String Value\",\"ChildB\":42}}";
	JSONNode n = libjson::parse(json);
	ParseJSON(n);


	JSONNode n(JSON_NODE);
	n.push_back(JSONNode("RootA", "Value in parent node"));
	JSONNode c(JSON_NODE);
	c.set_name("ChildNode");
	c.push_back(JSONNode("ChildA", "String Value"));
	c.push_back(JSONNode("ChildB", 42));
	n.push_back(c);
	std::string jc = n.write_formatted();
	std::cout << jc << std::endl;


	return allCurrenciesJsonArray;
}
开发者ID:taabodim,项目名称:QpidClient,代码行数:41,代码来源:currencyHandler.cpp

示例7: columns

JSONNode *Database::CreateTable(const string &name, const vector<string> &columnNames)
{
	if (this->FindTable(name))
		return NULL;
	JSONNode table;
	table.set_name(name);
	JSONNode columns(JSON_ARRAY);
	columns.set_name("columns");
	for (auto i = columnNames.begin(); i != columnNames.end(); i++)
		columns.push_back(JSONNode("", *i));
	table.push_back(columns);
	JSONNode rows(JSON_ARRAY);
	rows.set_name("rows");
	table.push_back(rows);
	auto tables = data.find("tables");
	tables->push_back(table);
	//cout << tables->write_formatted() << endl;
	//cout << data.write_formatted() << endl;
	auto t = tables->find(name);
	return t == tables->end() ? NULL : &*t;
}
开发者ID:HackerDom,项目名称:ructf-2013-final,代码行数:21,代码来源:Database.cpp

示例8: on_client_connect

void data_server_handler::on_client_connect(websocketpp::session_ptr client){
	static const boost::regex nonolith_domain("^https?://[[:w:]\\.-]*?nonolithlabs.com$");
	static const boost::regex localhost_domain("^https?://localhost(:[[:d:]]+)?$");
	const string origin = client->get_client_header("Origin");

	if (!allowAnyOrigin 
			&& origin!=""
			&& origin!="null"
			&& !regex_match(origin, localhost_domain) 
			&& !regex_match(origin, nonolith_domain)
			){
		client->start_http(403, "Origin not allowed");
		std::cerr << "Rejected client with unknown origin " << origin << std::endl;
		return;
	}
	
	const std::string resource = client->get_resource();
	Url url(resource);
	UrlPath path(url, 1);

	try{
		if (path.leaf()){ // "/"
			client->set_header("Location", redir_url);
			client->start_http(301);
		}else if (path.matches("rest")){
			handleJSONRequest(path.sub(), client);
		}else if (path.matches("ws")){
			client->start_websocket();
		}else{
			client->start_http(404, "Not found");
		}
	}catch(std::exception& e){
		JSONNode j;
		j.push_back(JSONNode("error", e.what()));
		std::cerr << "Exception while processing request: " << e.what() <<std::endl;
		respondJSON(client, j, 500);
	}
}
开发者ID:nonolith,项目名称:connect,代码行数:38,代码来源:server.cpp

示例9: TestInspectors

void TestSuite::TestInspectors(void){
    UnitTest::SetPrefix("TestInspectors.cpp - Inspectors");
    JSONNode test = JSONNode(JSON_NULL);
    #ifdef JSON_CASTABLE
	   assertEquals(test.as_string(), JSON_TEXT(""));
	   assertEquals(test.as_int(), 0);
	   assertEquals(test.as_float(), 0.0f);
	   assertEquals(test.as_bool(), false);
    #endif

    test = 15.5f;
    assertEquals(test.type(), JSON_NUMBER);
  #ifdef JSON_CASTABLE
    assertEquals(test.as_string(), JSON_TEXT("15.5"));
  #endif
    assertEquals(test.as_int(), 15);
    assertEquals(test.as_float(), 15.5f);
    #ifdef JSON_CASTABLE
	   assertEquals(test.as_bool(), true);
    #endif

    test = 0.0f;
    assertEquals(test.type(), JSON_NUMBER);
  #ifdef JSON_CASTABLE
    assertEquals(test.as_string(), JSON_TEXT("0"));
  #endif
    assertEquals(test.as_int(), 0);
    assertEquals(test.as_float(), 0.0f);
    #ifdef JSON_CASTABLE
	   assertEquals(test.as_bool(), false);
    #endif

    test = true;
    assertEquals(test.type(), JSON_BOOL);
    #ifdef JSON_CASTABLE
	   assertEquals(test.as_string(), JSON_TEXT("true"));
	   assertEquals(test.as_int(), 1);
	   assertEquals(test.as_float(), 1.0f);
    #endif
    assertEquals(test.as_bool(), true);

    test = false;
    assertEquals(test.type(), JSON_BOOL);
    #ifdef JSON_CASTABLE
	   assertEquals(test.as_string(), JSON_TEXT("false"));
	   assertEquals(test.as_int(), 0);
	   assertEquals(test.as_float(), 0.0f);
    #endif
    assertEquals(test.as_bool(), false);

    #ifdef JSON_CASTABLE
	   test.cast(JSON_NODE);
    #else
	   test = JSONNode(JSON_NODE);
    #endif
    assertEquals(test.type(), JSON_NODE);
    assertEquals(test.size(), 0);
    test.push_back(JSONNode(JSON_TEXT("hi"), JSON_TEXT("world")));
    test.push_back(JSONNode(JSON_TEXT("hello"), JSON_TEXT("mars")));
    test.push_back(JSONNode(JSON_TEXT("salut"), JSON_TEXT("france")));
    assertEquals(test.size(), 3);
    TestSuite::testParsingItself(test);

    #ifdef JSON_CASTABLE
	   JSONNode casted = test.as_array();
	   #ifdef JSON_UNIT_TEST
		  assertNotEquals(casted.internal, test.internal);
	   #endif
	   assertEquals(casted.type(), JSON_ARRAY);
	   assertEquals(test.type(), JSON_NODE);
	   assertEquals(test.size(), 3);
	   assertEquals(casted.size(), 3);
	   TestSuite::testParsingItself(casted);
    #endif

    UnitTest::SetPrefix("TestInspectors.cpp - Location");

    try {
	   #ifdef JSON_CASTABLE
		  assertEquals(casted.at(0), JSON_TEXT("world"));
		  assertEquals(casted.at(1), JSON_TEXT("mars"));
		  assertEquals(casted.at(2), JSON_TEXT("france"));
		  assertEquals(casted.at(0).name(), JSON_TEXT(""));
		  assertEquals(casted.at(1).name(), JSON_TEXT(""));
		  assertEquals(casted.at(2).name(), JSON_TEXT(""));
	   #endif
	   assertEquals(test.at(0), JSON_TEXT("world"));
	   assertEquals(test.at(1), JSON_TEXT("mars"));
	   assertEquals(test.at(2), JSON_TEXT("france"));
	   assertEquals(test.at(0).name(), JSON_TEXT("hi"));
	   assertEquals(test.at(1).name(), JSON_TEXT("hello"));
	   assertEquals(test.at(2).name(), JSON_TEXT("salut"));
    } catch (std::out_of_range){
	   FAIL("exception caught");
    }

    try {
	   assertEquals(test.at(JSON_TEXT("hi")), JSON_TEXT("world"));
	   assertEquals(test.at(JSON_TEXT("hello")), JSON_TEXT("mars"));
	   assertEquals(test.at(JSON_TEXT("salut")), JSON_TEXT("france"));
//.........这里部分代码省略.........
开发者ID:NatalieWolfe,项目名称:libjson,代码行数:101,代码来源:TestInspectors.cpp

示例10: callMethod

std::string ModuleManager::callMethod(const std::string& sender, const std::string& reciver, const std::string& action, const std::string& jsonString, IrcConnection* connection) {
	if(reciver=="IRCCONNECTION") {
		JSONNode n;
		if(!jsonString.empty()) {
			n = libjson::parse(jsonString);
		}

		if(action == "joinChan") {
			connection->joinChan(n["channel"].as_string());
		}
		else if(action == "partChan") {
			connection->partChan(n["channel"].as_string());
		}
		else if(action == "sendQuit") {
			connection->sendQuit(n["msg"].as_string());
		}
		else if(action == "sendMessage") {
			connection->sendMessage(n["target"].as_string(), n["message"].as_string());
		}
		else if(action == "sendNotice") {
			connection->sendNotice(n["target"].as_string(), n["message"].as_string());
		}
		else if(action == "sendAction") {
			connection->sendNotice(n["target"].as_string(), n["message"].as_string());
		}
		else if(action == "sendCTCP") {
			connection->sendNotice(n["target"].as_string(), n["message"].as_string());
		}
		else if(action == "changeNick") {
			connection->changeNick(n["nick"].as_string());
		}
		else if(action == "setUserMode") {
			connection->setUserMode(n["mode"].as_string());
		}
		else if(action == "setMode") {
			connection->setMode(n["nick"].as_string(), n["mode"].as_string());
		}
		else if(action == "getChannels") {
			JSONNode n(JSON_NODE);

			std::map<std::string, IrcChannel>& channelList = connection->getChannels();
			std::map<std::string, IrcChannel>::iterator iter;
			for(iter=channelList.begin(); iter!=channelList.end(); ++iter) {
				JSONNode n2(JSON_ARRAY);
				n2.set_name(iter->first);
				n2.push_back(convertIrcChannelToJSONString(iter->second));
				n.push_back(n2);
			}
			return n.write();
		}
		else if(action == "getServer") {
			return connection->getServer();
		}
		else if(action == "getPort") {
			return Base::StringUtils::toString(connection->getPort());
		}
		else if(action == "getNick") {
			return connection->getNick();
		}
		else if(action == "getID") {
			return connection->getID();
		}
	}
	else if(reciver=="IRC") {
		JSONNode n;
		if(!jsonString.empty()) {
			n = libjson::parse(jsonString);
		}

		if(action == "disconect") {
			mIRC->disconect(n["id"].as_string());
		}
		else if(action == "disconectAll") {
			mIRC->disconectAll();
		}
	}
	else if(reciver=="MODULEMANAGER") {
		JSONNode n;
		if(!jsonString.empty()) {
			n = libjson::parse(jsonString);
		}

		if(action == "reloadModule") {
			return Base::StringUtils::toString(reloadModule(n["id"].as_string()));
		}
		else if(action == "loadModuleBinary" || action == "loadModuleScript") {
			std::map<std::string, std::string> tmpParams;

			JSONNode n2 = n["params"];
			JSONNode::iterator i = n2.begin();
			for(; i!=n2.end(); ++i) {
				tmpParams[(*i).name()] = (*i).as_string();
			}

			if(action == "loadModuleBinary") {
				return Base::StringUtils::toString(loadModuleBinary(n["id"].as_string(), n["file"].as_string(), tmpParams));
			}
			else {
				return Base::StringUtils::toString(loadModuleScript(n["id"].as_string(), n["file"].as_string(), tmpParams));
			}
//.........这里部分代码省略.........
开发者ID:S1M0NE,项目名称:IrcBot,代码行数:101,代码来源:modulemanager.cpp

示例11: UpdateRepoTagOfTarball

ResponseCode UpdateRepoTagOfTarball(std::string pathTarball, std::string repo, std::string tag, std::string &idImage) {
  TAR *tar = NULL;
  int ret = 0;
  int th_found = 0;
  int exitcode = 0;
//  char tmp_filepath[] = P_tmpdir "/libtar-tmpfile-XXXXXX";
  //gen path to upload image
  char* tmp_imagepath = tempnam (FileUtils::GetPathDir(pathTarball).c_str(), "imageDirTmp_");
  std::string pathTmpDir = tmp_imagepath;
  free(tmp_imagepath);
  std::cout << "path tmp dir: " << pathTmpDir << std::endl;

  int tmp_fd = -1;

  ret = tar_open(&tar, (char*)pathTarball.c_str(), NULL, O_RDONLY, 0, 0);
  if (ret != 0) {
	fprintf(stdout, "Fail to open file: %s\n", pathTarball.c_str());
//	return FILE_ACTION_ERROR;
	exitcode = 2;
  }
	if (exitcode == 0) {
		if (tar_extract_all(tar, (char*)pathTmpDir.c_str()) != 0) {
            fprintf(stderr, "Fail to extract file: %s\n", pathTarball.c_str());
			exitcode = 2;
		}
	}

	if (exitcode == 0) {
		ret = tar_close(tar);
		if (ret != 0) {
			perror("Failed to close tar file.");
			exitcode = 2;
		}
		tar = NULL;
	}

  //Modify repository file
  if (exitcode == 0) {
	char buf[BUFSIZ];
	ssize_t n_buf = 0;
	FILE *tmpfile = NULL;

	std::ifstream in((pathTmpDir + "/" + REPOSITORIES_FILE).c_str(), std::ios::binary);
	std::string info((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());

	JSONNode n;
	try
	{
		n = libjson::parse(info);
	} catch(const std::invalid_argument& e) {
		std::cerr << "Invalid argument: " << e.what() << '\n';
//		return FILE_ACTION_ERROR;
		exitcode = 1;
	}
	if(exitcode == 0){
		JSONNode::const_iterator i = n.begin();
		//if (i != n.end() && i -> name() == TAG_SERVICE_STR && i -> type() != JSON_ARRAY && i -> type() != JSON_NODE)
		if (i != n.end() && i -> type() == JSON_NODE){
			JSONNode tag_id_node = i->as_node();
			i = tag_id_node.begin();
			if (i != n.end() && i -> type() != JSON_ARRAY && i -> type() != JSON_NODE){
				idImage = i->as_string();
			}else{
				std::cout << "Tarball format error.\n";
		//		return FILE_ACTION_ERROR;
				exitcode = 1;
			}
		}
	}else{
		std::cout << "Tarball format error.\n";
//			return FILE_ACTION_ERROR;
		exitcode = 1;
		}
	}

	if(exitcode == 0){
		JSONNode newRepoNode(JSON_NODE);
		newRepoNode.set_name(repo);
		newRepoNode.push_back(JSONNode(tag, idImage));

		JSONNode newNode;
		newNode.push_back(newRepoNode);
		std::string content = newNode.write();

		FILE * pFile;

		if (exitcode == 0) {
			pFile = fopen ((pathTmpDir + "/" + REPOSITORIES_FILE).c_str() , "w");
			if (pFile == NULL) {
			   printf("Error opening file %s\n", (pathTmpDir + "/" + REPOSITORIES_FILE).c_str());
		//	   return FILE_ACTION_ERROR;
			   exitcode = 1;
			}
		}

		if (exitcode == 0) {
			fwrite (content.c_str() , sizeof(char), content.size(), pFile);
			fclose (pFile);
			printf("content tmp file: %s\n", content.c_str());
		}
//.........这里部分代码省略.........
开发者ID:pyotr777,项目名称:kportal,代码行数:101,代码来源:TarUtil.cpp


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