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


C++ JsonValue::toStyledString方法代码示例

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


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

示例1: addTestSignature

bool addTestSignature(FCGI_Stream &stream, jsonParser &jSON)
{
	//string session = jSON.getObject("session", false).asString();
	int task = jSON.getAsIntS("task");//jSON.getObject("task", false).asInt();
	string lang = jSON.getAsString("lang");
	//string signature = jSON.getObject("tests_signatures",false).asString();
	string etalon = jSON.getAsString("etalon");
	Json::FastWriter fastWriter;
	Json::Value signatureValue = jSON.getObject("signature",false);
	std::string signature = fastWriter.write(signatureValue);
	vector<string> labl;
	labl.push_back("task_id");
	labl.push_back("lang");
	labl.push_back("signature");
	labl.push_back("etalon");
	SqlConnectionPool sql;
	bool taskComp = true;
	if (sql.connectToTable(string("tests_signatures"), labl))
	{
		DEBUG("no threa2");
		vector<map<int, string> > records =	sql.getAllRecordsFromTable(
				"`task_id`='"+std::to_string(task)+"'");
		if ((int)records.size()==0)
			taskComp=true;
		else
			taskComp = false;


		vector <map<int, string> > rec;
		map<int, string> temp;
		temp.insert( { 0, std::to_string(task)});
		temp.insert( { 1, lang});
		temp.insert( { 2, str_with_spec_character(signature) });
		temp.insert( { 3, etalon });
		//rec.push_back(temp);

		//MyConnectionPool::getInstance().getAllRecordsFromTable();
		bool res = sql.addRecordsInToTable(temp);
		//MyConnectionPool::getInstance().tt();
		if(!taskComp)
		{
			stream << "Status: 200\r\n Content-type: text/html\r\n" << "\r\n";
			JsonValue res;
			res["status"] = "already exist";
			stream << res.toStyledString();
		}
		else //204
			stream << "Status: 200\r\n Content-type: text/html\r\n" << "\r\n"
			<<"success:"<<to_string(res)<<"signature:"<<signature;


	}
	else
	{
		return false;
	}
	return true;
	// string ip_usera = FCGX_GetParam( "REMOTE_ADDR", request->envp );

}
开发者ID:ITAAcademy,项目名称:Interpretator,代码行数:60,代码来源:main.cpp

示例2: retreiveTests

bool retreiveTests(FCGI_Stream &stream, jsonParser &jSON)
{
	//string session = jSON.getObject("session", false).asString();
	int task = jSON.getAsIntS("task");//jSON.getObject("task", false).asInt();
	vector<string> labl;
	labl.push_back("task_id");

	bool taskComp = true;
	SqlConnectionPool sql;
	if (sql.connectToTable(string("tests"), labl))
	{
		/*l12("no threa2");
				vector<map<int, string> > records =	SqlConnectionPool::getInstance().getAllRecordsFromTable(
						"`task_id`='"+std::to_string(task)+"'");
				if ((int)records.size()==0)
					taskComp=true;
				else
					taskComp = false;
		 */

		vector<map<int, string> > records = sql.getAllRecordsFromTable("`task_id`='"+std::to_string(task)+"'");
		//MyConnectionPool::getInstance().tt();
		bool recordsEmpty = records.size() == 0;
		if (recordsEmpty)stream << "Status: 204\r\n Content-type: text/html\r\n" << "\r\n" <<"task with this id doesn't excist";
		else
		{
			stream << "Status: 200\r\n Content-type: text/html\r\n" << "\r\n";
			JsonValue res;
			res["json"] = records[0][1];
			stream << res.toStyledString();
		}

	}
	else
	{
		return false;
	}
	return true;
	// string ip_usera = FCGX_GetParam( "REMOTE_ADDR", request->envp );

}
开发者ID:ITAAcademy,项目名称:Interpretator,代码行数:41,代码来源:main.cpp

示例3: addNewtask

bool addNewtask( FCGI_Stream &stream, jsonParser &jSON, int thread_id, string &error, bool &need_stream)//***
{
	cout.flush();
	cout << jSON.getParsedFromString().toStyledString();
	//return false;

	JsonValue res;
	stream << "Status: 200\r\n Content-type: text/html\r\n" << "\r\n";
	if ( !jSON.isJson() )
		{
			string error = "ERROR: json format is not correct. it isn`t json";
			res["status"] = error;
			stream << res.toStyledString();
			stream.close();
			return false;
		}

	if ( !jSON.isValidFields() )
	{
		string error = jSON.getLastError();
		res["status"] = error;
		stream << res.toStyledString();
		stream.close();
		return false;
	}
	string lang = jSON.getAsStringS("lang");
	string table;
	table=ConnectorSQL::getAssignmentTable(lang);

	vector<string> labl;
	labl.push_back("ID");
	labl.push_back("header");
	labl.push_back("etalon");
	labl.push_back("footer");
	labl.push_back("json");
	SqlConnectionPool sql;


	DEBUG("before connectToTable");
	if (sql.connectToTable(table, labl))
	{
		DEBUG("connectedToTable");
		map<int, string> temp;

		//new code for testcases part
		int id = jSON.getAsIntS("task");//t("task",false));
		DEBUG("task");
		DEBUG(std::to_string(id));




		TaskCodeGenerator generator(jSON, thread_id);

		/*{
			string etalona = generator.getEtalon();
			int pre_last_return_pos = 0;
			int last_return_pos = 0;
			while(true)
			{
				int pos = etalona.find("return", last_return_pos + 2);
				if (pos == -1)
					break;
				pre_last_return_pos = last_return_pos;
				last_return_pos = pos;
			}
			etalona.erase(pre_last_return_pos, last_return_pos );

		}*/

		LangCompiler compiler(thread_id);

		string code = sql.generateProgramCode(generator.getHeader(), string(""), generator.getFooter(), lang);
		compiler.compile(code, true, LangCompiler::convertFromName(lang), 1);
		string errors = compiler.getWarningErr();

		int lang_int = jSON.getAsIntS("lang");

		if (errors.size() == 0)
		{

			if (lang_int == (int) LangCompiler::Flag_JS)
			{
				errors = compiler.getResult();
				if (errors.find("error") == -1)
					errors = "";
			}
		}



		if (errors.size() )
		{
			error = "failed code compilation: " + errors ;
			//res["status"] = "failed";
			res["status"] = error;
			stream << res.toStyledString();
			stream.close();

			need_stream = false;
//.........这里部分代码省略.........
开发者ID:ITAAcademy,项目名称:Interpretator,代码行数:101,代码来源:addNewtask.cpp

示例4: addTestsToTask

bool addTestsToTask( FCGI_Stream &stream, jsonParser &jSON, int thread_id, string &error, bool &need_stream)
{



	//string lang = jSON.getAsStringS("lang");
	string table;
	table = ConnectorSQL::getAssignmentTable(" hahaha dont need");

	vector<string> labl = ConnectorSQL::getAssignmentTableLabels();
	/*labl.push_back("ID");
		labl.push_back("header");
		labl.push_back("etalon");
		labl.push_back("footer");
		labl.push_back("json");*/
	SqlConnectionPool sql;

	//stream << "Status: 200\r\n Content-type: text/html\r\n" << "\r\n";
	JsonValue res;

	if (sql.connectToTable(table, labl))
	{

		if (!jSON.mustExistBeInt(jSON.getParsedFromString()[FIELD_TASK_ID], "task"))
		{
			stream << "Status: 200\r\n Content-type: text/html\r\n" << "\r\n";
			res["status"] = "failed";
			res["error"] = jSON.getLastError();
			stream << res.toStyledString();
			stream.close();
			return false;
		}

		int task = jSON.getAsIntS("task");

		string json_prev_task = sql.getJsonFromTable(task);

		jsonParser parse(json_prev_task);

		if (!(parse.isValidFields() && parse.isJson() ))
		{
			stream << "Status: 200\r\n Content-type: text/html\r\n" << "\r\n";
			res["status"] = "failed";
			res["error"] = "Task jsonf from DB invalid";
			stream << res.toStyledString();
			stream.close();
			return false;
		}

		Value json_db(parse.getParsedFromString());


		if ( !jSON.parseAddUtest(json_db))
		{
			stream << "Status: 200\r\n Content-type: text/html\r\n" << "\r\n";
			string last_err = jSON.getLastError();
			last_err = last_err.erase(0, last_err.find("correct") + 8);
			res["json"] = "";
			res["status"] = "failed";
			res["error"] = "Unit tests don`t match structure of task: " + last_err;

			stream << res.toStyledString();
			stream.close();
			return false;
		}

		Value json_tests = jSON.getJsonValue();

		Value res_value = mergeUtestsAndTask(json_tests, json_db);

		string res_value_str = res_value.toStyledString();
		res_value_str = replaceSlashTabsParagBreakets( res_value_str );


		Value val; //(res_value_str);
		Json::Reader reader;
		reader.parse( res_value_str.c_str(), val );

		jsonParser merged_json;
		//merged_json.setParsedFromString(val);
		merged_json.setJson(res_value_str);
		//setJson(res_value_str);



		cout.flush();
		//cout << val.toStyledString();
		//cout << res_value_str;

		//	cout << merged_json.getParsedFromString().toStyledString();
		//merged_json.setParsedFromString(Json(res_value.toStyledString());



		//cout << merged_json.getParsedFromString();

		/*
		map<int, string> temp;

		int valuesCount = 0;
//.........这里部分代码省略.........
开发者ID:ITAAcademy,项目名称:Interpretator,代码行数:101,代码来源:addTestsToTask.cpp

示例5: result_status


//.........这里部分代码省略.........
			 stream << "jobId:"+records[i][2] << "\n";
		 */
		//stream << "status:" +	 records[i].find(keys[r])->second ;
		/*
		 * RESULT
		 */
		//cerr << "before write to stream";

		stream << "Status: 200\r\n Content-type: text/html\r\n" << "\r\n";

		//cerr << "after write to stream";

		JsonValue res;
		if(records.size() > 0)
		{
			res["status"] = records[0][3];
			if (operation == "result" || operation == "r")
			{
				res["date"] = records[0][4];
				res["warning"] = records[0][6];
				//////////////////////////////////////////////////NEW//17.11.15

				/*		string result = records[0][5];
				  smatch m;
				  regex e ("\\b(sub)([^ ]*)");   // matches words beginning by "sub"


				  while (std::regex_search (result,m,e)) {
				    for (auto x:m) std::cout << x << " ";
				    std::cout << std::endl;
				    result = m.suffix().str();
				  }
				 */
				res["testResult"] = JsonValue(arrayValue);

				string part = records[0][5];
				int start = part.find('@');

				if(start == string::npos)
				{
					int position = records[0][5].find("exception");
					if( string::npos != position)
					{
						int p = records[0][5].substr(0, position).find_last_of("\n");
						res["result"] = records[0][5].substr(p + 1);//records[0][5].substr(0, p - 1);
						res["done"] = false;//records[0][5].substr(p);
					}
					else
						res["result"] = records[0][5];

				}
				else
				{
					res["result"] = part.substr(0, start);
					int count = 0;
					bool done = true;
					while(start++ != string::npos)// need test after first fail?
					{
						int next = part.substr(start).find('@');
						string number;
						if(next != string::npos)
						{
							if(next -1 >= 0 && part[start + next - 1] == '!')
							{
								number = part.substr(start, next - 1);
								res["testResult"][count] = JsonValue(false);
								done = false;
							}
							else
							{
								number = part.substr(start, next );
								res["testResult"][count] = JsonValue(true);
							}
						}
						part = part.substr(start + next + 1);
						count++;
						start = part.find('@');
					}
					res["done"] = JsonValue(done);
				}
			}
		}
		else
			res["status"] = "not found";

		stream << res.toStyledString();

		//	stream << "status:" + records[0][3] << "\n\n";
		/*Cool code no delete
		 stream << "date:"+records[i][4] << "\n";
		 stream << "result:"+records[i][5] << "\n";
		 stream << "warning:"+records[i][6] << "\n";
		 */
		//logfile::addLog("Table 'results' outputed");
		cout.flush();
	}
	else
		return false;
	return true;
}
开发者ID:ITAAcademy,项目名称:Interpretator,代码行数:101,代码来源:main.cpp

示例6: processTask

void processTask(int id,Job job) {

	//	logfile::addLog("Connection");
	// ConnectorSQL connector ;

	// int id = ((int *)a)[0];


	//char * inputSTR;
	LangCompiler compiler(id);
	/*
	 * input from PHP form // not use
	 *
	 * 	stream >> inputSTR; // test input
	 char *code = stream.getFormParam("text");
	 char *name = stream.getFormParam("name");
	 */

	/*
	 * problem with CodeClear need fix
	 *
	 CodeClear clr;
	 string outStr = code;
	 clr.ClearText(outStr);*/
	DEBUG("before code empty check");
	if (!job.code.empty())
	{

		vector<string> labl;
		//ADD NEW STARTED COMPILING INFO TO DATABASE
		DEBUG("Before connect to results");
		SqlConnectionPool sql;

		labl.push_back("ID");
		labl.push_back("header");
		labl.push_back("etalon");
		labl.push_back("footer");



		string table;
		table = ConnectorSQL::getAssignmentTable(job.lang);
		if (sql.connectToTable(table, labl))
		{
			job.code =
					sql.getCustomCodeOfProgram(
							to_string(job.task), job.code, id,job.lang);
			DEBUG(job.code);
		}

		INFO(to_string(id)+ " Start compiler");
		JsonValue res;

		compiler.compile(job.code, true, LangCompiler::convertFromName(job.lang),0);


		string date = logfile::getDateStamp();
		res["date"] = date;

		string rezulta = compiler.getResult();
		res["result"] = rezulta;
		string warning = compiler.getWarningErr();
		res["warnings"] = warning;
		DEBUG( res.toStyledString());


		labl.clear();
		//UPDATE COMPILING INFO IN DB
		labl.push_back("id");
		labl.push_back("session");
		labl.push_back("jobid");
		labl.push_back("status");
		labl.push_back("date");
		labl.push_back("result");
		labl.push_back("warning");
		if (sql.connectToTable("results", labl))
		{
			string s_datime = getDateTime(); //'YYYY-MM-DD HH:MM:SS'
			map<int, string> temp;
			temp.insert( { 1, job.session });
			temp.insert( { 2, (job.jobid) });
			if(compiler.getResult().size() == 0)
				temp.insert( { 3, "failed"});
			else
				temp.insert( { 3, "done"});
			temp.insert( { 4, s_datime });
			temp.insert( { 5, compiler.getResult()});
			temp.insert( { 6, compiler.getWarningErr() });
			//4j
			//string where = "`results`.`jobid`='"+to_string(job.jobid)+"' AND `results`.`session`='"+job.session+"'";
			map<int,string> where;
			where.insert({1,job.session});
			where.insert({2,(job.jobid)});
			//ConnectorSQL::getInstance().updateRecordsInToTable(temp,wher);
			sql.updateRecordsInToTable(temp,where);

		}


		INFO(to_string(id) + " Stop compiler");
//.........这里部分代码省略.........
开发者ID:ITAAcademy,项目名称:Interpretator,代码行数:101,代码来源:main.cpp

示例7: stream


//.........这里部分代码省略.........
							if (operation == "start" || operation == "s")
							{
								if(!start(stream, jSON, FCGX_GetParam("REMOTE_ADDR", request->envp), errora, need_stream))
									succsesful = false;
							}
							else
								if (operation == "addUtest" || operation == "u")
								{
									addTestsToTask(stream, jSON, id, errora, need_stream);
								}
								else
									if (operation == "addtestsig")
									{
										if(!addTestSignature(stream, jSON))
											succsesful = false;
									}
									else
										if (operation == "addtestval")
										{
											if (!addTestValues(stream,jSON))
												succsesful = false;
										}
										else
											if (operation == "add_tests")
											{
												if (!addTests(stream,jSON))
													succsesful = false;
											}
											else
												if (operation == "retreive_tests")
												{
													if (!retreiveTests(stream,jSON))
														succsesful = false;
												}
												else
													if (operation == "result" || operation == "status" || operation == "r" )
													{
														if(!result_status(stream, jSON, operation))
															succsesful = false;
													}
													else
														if (operation == "getToken")
														{
															if(!TokenSystem::getObject()->generationToken(stream, jSON))
																succsesful = false;
														}
														else
															if (operation == "getFromToken")
															{
																if(!TokenSystem::getObject()->getFromToken(stream, jSON))
																	succsesful = false;
															}
															else
															{
																errorResponder.showError(505, "operation is invalid");
															}

				if(!succsesful)
				{
					if (need_stream)
					{
						JsonValue res;
						stream << "Status: 200\r\n Content-type: text/html\r\n" << "\r\n";
						string error = jSON.getLastError() + "\n" + errora;
						/*	errorResponder.showError(400, error);
					stream.close();*/

						res["status"] = error;
						stream << res.toStyledString();
						stream.close();
					}
					continue;
				}

			}
			else
			{
				if (need_stream)
				{
					JsonValue res;
					stream << "Status: 200\r\n Content-type: text/html\r\n" << "\r\n";
					//logfile::addLog(id,	"Json format is not correct!!! \n::::::::::::::::::::::::\n" + stream.getRequestBuffer() + "\n::::::::::::::::::::::::");
					/*errorResponder.showError(400, jSON.getLastError());
				stream.close();*/

					res["status"] = jSON.getLastError();
					stream << res.toStyledString();
					stream.close();
				}

				continue;
			}

		}
	}
	//close session
	INFO("session closed");
	stream.close();
	return NULL;
}
开发者ID:ITAAcademy,项目名称:Interpretator,代码行数:101,代码来源:main.cpp

示例8: copyTask

bool copyTask( FCGI_Stream &stream, jsonParser &jSON, int thread_id, string &error, bool &need_stream)
{
	cout.flush();
	JsonValue res;
	stream << "Status: 200\r\n Content-type: text/html\r\n" << "\r\n";
	if ( !jSON.isJson() )
	{
		string error = "ERROR: json format is not correct. it isn`t json";
		res["status"] = error;
		stream << res.toStyledString();
		stream.close();
		return false;
	}

	if ( !jSON.isValidFields() )
	{
		string error = jSON.getLastError();
		res["status"] = error;
		stream << res.toStyledString();
		stream.close();
		return false;
	}

	string table;
	table=ConnectorSQL::getAssignmentTable("");

	vector<string> labl;
	labl.push_back("ID");
	labl.push_back("header");
	labl.push_back("etalon");
	labl.push_back("footer");
	labl.push_back("json");
	SqlConnectionPool sql;

	if (sql.connectToTable(table, labl))
	{
		int id = jSON.getAsIntS("task");
		int new_id = jSON.getAsIntS("new_task");

		if ( sql.copyRecordFromIdToNewId(id, new_id))
		{
			res["status"] = "success";
			res["table"] = table;
			res["id"] = to_string(id);
		}
		else
		{
			if ( sql.updateRecordFromIdToNewId(id, new_id))
			{
				res["status"] = "updated";
				res["table"] = table;
				res["id"] = to_string(id);
			}
			else
				res["status"] = "failed";


		}
		stream << res.toStyledString();
					stream.close();

					need_stream = false;
					return true;
	}
	else
	{
		res["status"] = "failed";

		stream << res.toStyledString();
		stream.close();

		need_stream = false;
		return false;
	}
}
开发者ID:ITAAcademy,项目名称:Interpretator,代码行数:75,代码来源:copyTask.cpp


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