本文整理汇总了C++中StyledWriter类的典型用法代码示例。如果您正苦于以下问题:C++ StyledWriter类的具体用法?C++ StyledWriter怎么用?C++ StyledWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StyledWriter类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST_F
TEST_F(JsonCpp, StyledWriter) {
for (int i = 0; i < kTrialCount; i++) {
StyledWriter writer;
std::string str = writer.write(root_);
//if (i == 0)
// std::cout << str.length() << std::endl;
}
}
示例2: benchmark_jsoncpp
measurements benchmark_jsoncpp(const char *input_filename,
const char* output_filename)
{
size_t start_memory_used;
size_t end_memory_used;
size_t time_to_read;
size_t time_to_write;
{
start_memory_used = memory_measurer::virtual_memory_currently_used_by_current_process();
Value root;
{
try
{
auto start = high_resolution_clock::now();
std::ifstream is(input_filename);
is >> root;
//Reader reader;
//if (!reader.parse(input_filename, root))
//{
// std::cerr << "jsoncpp failed." << std::endl;
//}
auto end = high_resolution_clock::now();
time_to_read = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
}
catch (const std::exception& e)
{
std::cout << e.what() << std::endl;
exit(1);
}
}
end_memory_used = memory_measurer::virtual_memory_currently_used_by_current_process();
{
char writeBuffer[65536];
std::ofstream os; //(output_filename/*,std::ofstream::binary*/);
os.rdbuf()->pubsetbuf(writeBuffer, sizeof(writeBuffer));
os.open(output_filename, std::ios_base::out | std::ios_base::binary);
auto start = high_resolution_clock::now();
//os << root;
StyledWriter styledWriter;
//std::ofstream writer(filename, std::ifstream::binary);
os << styledWriter.write(root);
auto end = high_resolution_clock::now();
time_to_write = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
}
}
size_t final_memory_used = memory_measurer::virtual_memory_currently_used_by_current_process();
measurements results;
results.library_name = library_name;
results.memory_used = (end_memory_used - start_memory_used)/1000000;
results.time_to_read = time_to_read;
results.time_to_write = time_to_write;
return results;
}
示例3: getRawString
//--------------------------------------------------------------
string JSONElement::getRawString(bool pretty) {
string raw;
if(pretty) {
StyledWriter writer;
raw = writer.write(*this);
} else {
FastWriter writer;
raw = writer.write(*this);
}
return raw;
}
示例4: file_key
//--------------------------------------------------------------
bool JSONElement::save(string filename, bool pretty)
{
ofstream file_key(filename.c_str());
if (!file_key.is_open()) {
cout << "Unable to open " << filename << endl;
return false;
}
if(pretty) {
StyledWriter writer;
file_key << writer.write( *this ) << endl;
} else {
FastWriter writer;
file_key << writer.write( *this ) << endl;
}
file_key.close();
return true;
}
示例5: ofToDataPath
//--------------------------------------------------------------
bool ofxJSONElement::save(string filename, bool pretty)
{
filename = ofToDataPath(filename, true);
ofstream file_key(filename.c_str());
if (!file_key.is_open()) {
ofLog(OF_LOG_WARNING, "Unable to open "+filename);
return false;
}
if(pretty) {
StyledWriter writer;
file_key << writer.write( *this ) << endl;
} else {
FastWriter writer;
file_key << writer.write( *this ) << endl;
}
ofLog(OF_LOG_NOTICE, "JSON saved to "+filename);
file_key.close();
return true;
}
示例6:
std::string
Value::toStyledString() const
{
StyledWriter writer;
return writer.write( *this );
}
示例7: toStyledString
JSONCPP_STRING Value::toStyledString() const {
StyledWriter writer;
return writer.write(*this);
}
示例8: sendJSON
void JSONResponse::sendJSON(struct mg_connection *conn, const Value& value) {
StyledWriter writer; //todo(njoubert): Replace with FastWriter for production
string out = writer.write(value);
sendHTTPResponse(conn, out.c_str(), out.length());
}