aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include/storages
diff options
context:
space:
mode:
authormydesktop <dev.mc2@gmail.com>2014-05-25 13:06:40 -0400
committermydesktop <dev.mc2@gmail.com>2014-05-25 13:06:40 -0400
commit3a3a8176782a4fa75b0607fba0393c9d4a1746be (patch)
treee8e38bdeaf0e9ea8ba773bb27e1de4b288b8150d /contrib/epee/include/storages
parentMerge pull request #12 from quazarcoin/MRO_master (diff)
downloadmonero-3a3a8176782a4fa75b0607fba0393c9d4a1746be.tar.xz
0.8.8update
Diffstat (limited to 'contrib/epee/include/storages')
-rw-r--r--contrib/epee/include/storages/portable_storage.h24
-rw-r--r--contrib/epee/include/storages/portable_storage_template_helper.h11
-rw-r--r--contrib/epee/include/storages/portable_storage_to_json.h59
3 files changed, 53 insertions, 41 deletions
diff --git a/contrib/epee/include/storages/portable_storage.h b/contrib/epee/include/storages/portable_storage.h
index c244dac19..bbfe5f85c 100644
--- a/contrib/epee/include/storages/portable_storage.h
+++ b/contrib/epee/include/storages/portable_storage.h
@@ -83,7 +83,7 @@ namespace epee
bool load_from_binary(const binarybuffer& target);
template<class trace_policy>
bool dump_as_xml(std::string& targetObj, const std::string& root_name = "");
- bool dump_as_json(std::string& targetObj, size_t indent = 0);
+ bool dump_as_json(std::string& targetObj, size_t indent = 0, bool insert_newlines = true);
bool load_from_json(const std::string& source);
private:
@@ -106,17 +106,17 @@ namespace epee
#pragma pack(pop)
};
inline
- bool portable_storage::dump_as_json(std::string& buff, size_t indent)
+ bool portable_storage::dump_as_json(std::string& buff, size_t indent, bool insert_newlines)
{
TRY_ENTRY();
std::stringstream ss;
- epee::serialization::dump_as_json(ss, m_root, indent);
+ epee::serialization::dump_as_json(ss, m_root, indent, insert_newlines);
buff = ss.str();
return true;
CATCH_ENTRY("portable_storage::dump_as_json", false)
}
inline
- bool portable_storage::load_from_json(const std::string& source)
+ bool portable_storage::load_from_json(const std::string& source)
{
TRY_ENTRY();
return json::load_from_json(source, *this);
@@ -124,13 +124,13 @@ namespace epee
}
template<class trace_policy>
- bool portable_storage::dump_as_xml(std::string& targetObj, const std::string& root_name)
+ bool portable_storage::dump_as_xml(std::string& targetObj, const std::string& root_name)
{
return false;//TODO: don't think i ever again will use xml - ambiguous and "overtagged" format
}
inline
- bool portable_storage::store_to_binary(binarybuffer& target)
+ bool portable_storage::store_to_binary(binarybuffer& target)
{
TRY_ENTRY();
std::stringstream ss;
@@ -145,7 +145,7 @@ namespace epee
CATCH_ENTRY("portable_storage::store_to_binary", false)
}
inline
- bool portable_storage::load_from_binary(const binarybuffer& source)
+ bool portable_storage::load_from_binary(const binarybuffer& source)
{
m_root.m_entries.clear();
if(source.size() < sizeof(storage_block_header))
@@ -174,7 +174,7 @@ namespace epee
}
//---------------------------------------------------------------------------------------------------------------
inline
- hsection portable_storage::open_section(const std::string& section_name, hsection hparent_section, bool create_if_notexist)
+ hsection portable_storage::open_section(const std::string& section_name, hsection hparent_section, bool create_if_notexist)
{
TRY_ENTRY();
hparent_section = hparent_section ? hparent_section:&m_root;
@@ -238,7 +238,7 @@ namespace epee
}
//---------------------------------------------------------------------------------------------------------------
template<class t_value>
- bool portable_storage::set_value(const std::string& value_name, const t_value& v, hsection hparent_section)
+ bool portable_storage::set_value(const std::string& value_name, const t_value& v, hsection hparent_section)
{
BOOST_MPL_ASSERT(( boost::mpl::contains<boost::mpl::push_front<storage_entry::types, storage_entry>::type, t_value> ));
TRY_ENTRY();
@@ -345,7 +345,7 @@ namespace epee
template<class t_value>
- bool portable_storage::get_next_value(harray hval_array, t_value& target)
+ bool portable_storage::get_next_value(harray hval_array, t_value& target)
{
BOOST_MPL_ASSERT(( boost::mpl::contains<storage_entry::types, t_value> ));
//TRY_ENTRY();
@@ -462,7 +462,7 @@ namespace epee
}
//---------------------------------------------------------------------------------------------------------------
inline
- bool portable_storage::insert_next_section(harray hsec_array, hsection& hinserted_childsection)
+ bool portable_storage::insert_next_section(harray hsec_array, hsection& hinserted_childsection)
{
TRY_ENTRY();
CHECK_AND_ASSERT(hsec_array, false);
@@ -476,4 +476,4 @@ namespace epee
}
//---------------------------------------------------------------------------------------------------------------
}
-} \ No newline at end of file
+}
diff --git a/contrib/epee/include/storages/portable_storage_template_helper.h b/contrib/epee/include/storages/portable_storage_template_helper.h
index 2163cb879..008f44321 100644
--- a/contrib/epee/include/storages/portable_storage_template_helper.h
+++ b/contrib/epee/include/storages/portable_storage_template_helper.h
@@ -25,6 +25,9 @@
//
#pragma once
+
+#include <string>
+
#include "parserse_base_utils.h"
#include "portable_storage.h"
#include "file_io_utils.h"
@@ -56,19 +59,19 @@ namespace epee
}
//-----------------------------------------------------------------------------------------------------------
template<class t_struct>
- bool store_t_to_json(t_struct& str_in, std::string& json_buff, size_t indent = 0)
+ bool store_t_to_json(t_struct& str_in, std::string& json_buff, size_t indent = 0, bool insert_newlines = true)
{
portable_storage ps;
str_in.store(ps);
- ps.dump_as_json(json_buff, indent);
+ ps.dump_as_json(json_buff, indent, insert_newlines);
return true;
}
//-----------------------------------------------------------------------------------------------------------
template<class t_struct>
- std::string store_t_to_json(t_struct& str_in, size_t indent = 0)
+ std::string store_t_to_json(t_struct& str_in, size_t indent = 0, bool insert_newlines = true)
{
std::string json_buff;
- store_t_to_json(str_in, json_buff, indent);
+ store_t_to_json(str_in, json_buff, indent, insert_newlines);
return std::move(json_buff);
}
//-----------------------------------------------------------------------------------------------------------
diff --git a/contrib/epee/include/storages/portable_storage_to_json.h b/contrib/epee/include/storages/portable_storage_to_json.h
index aff85b201..e3fdcec29 100644
--- a/contrib/epee/include/storages/portable_storage_to_json.h
+++ b/contrib/epee/include/storages/portable_storage_to_json.h
@@ -30,6 +30,7 @@
#include "misc_language.h"
#include "portable_storage_base.h"
+#include "parserse_base_utils.h"
namespace epee
{
@@ -37,21 +38,21 @@ namespace epee
{
template<class t_stream>
- void dump_as_json(t_stream& strm, const array_entry& ae, size_t indent);
+ void dump_as_json(t_stream& strm, const array_entry& ae, size_t indent, bool insert_newlines);
template<class t_stream>
- void dump_as_json(t_stream& strm, const storage_entry& se, size_t indent);
+ void dump_as_json(t_stream& strm, const storage_entry& se, size_t indent, bool insert_newlines);
template<class t_stream>
- void dump_as_json(t_stream& strm, const std::string& v, size_t indent);
+ void dump_as_json(t_stream& strm, const std::string& v, size_t indent, bool insert_newlines);
template<class t_stream>
- void dump_as_json(t_stream& strm, const int8_t& v, size_t indent);
+ void dump_as_json(t_stream& strm, const int8_t& v, size_t indent, bool insert_newlines);
template<class t_stream>
- void dump_as_json(t_stream& strm, const uint8_t& v, size_t indent);
+ void dump_as_json(t_stream& strm, const uint8_t& v, size_t indent, bool insert_newlines);
template<class t_stream>
- void dump_as_json(t_stream& strm, const bool& v, size_t indent);
+ void dump_as_json(t_stream& strm, const bool& v, size_t indent, bool insert_newlines);
template<class t_stream, class t_type>
- void dump_as_json(t_stream& strm, const t_type& v, size_t indent);
+ void dump_as_json(t_stream& strm, const t_type& v, size_t indent, bool insert_newlines);
template<class t_stream>
- void dump_as_json(t_stream& strm, const section& sec, size_t indent);
+ void dump_as_json(t_stream& strm, const section& sec, size_t indent, bool insert_newlines);
inline std::string make_indent(size_t indent)
@@ -64,7 +65,11 @@ namespace epee
{
t_stream& m_strm;
size_t m_indent;
- array_entry_store_to_json_visitor(t_stream& strm, size_t indent):m_strm(strm), m_indent(indent){}
+ bool m_insert_newlines;
+ array_entry_store_to_json_visitor(t_stream& strm, size_t indent,
+ bool insert_newlines = true)
+ : m_strm(strm), m_indent(indent), m_insert_newlines(insert_newlines)
+ {}
template<class t_type>
void operator()(const array_entry_t<t_type>& a)
@@ -75,7 +80,7 @@ namespace epee
auto last_it = --a.m_array.end();
for(auto it = a.m_array.begin(); it != a.m_array.end(); it++)
{
- dump_as_json(m_strm, *it, m_indent);
+ dump_as_json(m_strm, *it, m_indent, m_insert_newlines);
if(it != last_it)
m_strm << ",";
}
@@ -89,50 +94,53 @@ namespace epee
{
t_stream& m_strm;
size_t m_indent;
- storage_entry_store_to_json_visitor(t_stream& strm, size_t indent):m_strm(strm), m_indent(indent)
+ bool m_insert_newlines;
+ storage_entry_store_to_json_visitor(t_stream& strm, size_t indent,
+ bool insert_newlines = true)
+ : m_strm(strm), m_indent(indent), m_insert_newlines(insert_newlines)
{}
//section, array_entry
template<class visited_type>
void operator()(const visited_type& v)
{
- dump_as_json(m_strm, v, m_indent);
+ dump_as_json(m_strm, v, m_indent, m_insert_newlines);
}
};
template<class t_stream>
- void dump_as_json(t_stream& strm, const array_entry& ae, size_t indent)
+ void dump_as_json(t_stream& strm, const array_entry& ae, size_t indent, bool insert_newlines)
{
- array_entry_store_to_json_visitor<t_stream> aesv(strm, indent);
+ array_entry_store_to_json_visitor<t_stream> aesv(strm, indent, insert_newlines);
boost::apply_visitor(aesv, ae);
}
template<class t_stream>
- void dump_as_json(t_stream& strm, const storage_entry& se, size_t indent)
+ void dump_as_json(t_stream& strm, const storage_entry& se, size_t indent, bool insert_newlines)
{
- storage_entry_store_to_json_visitor<t_stream> sv(strm, indent);
+ storage_entry_store_to_json_visitor<t_stream> sv(strm, indent, insert_newlines);
boost::apply_visitor(sv, se);
}
template<class t_stream>
- void dump_as_json(t_stream& strm, const std::string& v, size_t indent)
+ void dump_as_json(t_stream& strm, const std::string& v, size_t indent, bool insert_newlines)
{
strm << "\"" << misc_utils::parse::transform_to_escape_sequence(v) << "\"";
}
template<class t_stream>
- void dump_as_json(t_stream& strm, const int8_t& v, size_t indent)
+ void dump_as_json(t_stream& strm, const int8_t& v, size_t indent, bool insert_newlines)
{
strm << static_cast<int32_t>(v);
}
template<class t_stream>
- void dump_as_json(t_stream& strm, const uint8_t& v, size_t indent)
+ void dump_as_json(t_stream& strm, const uint8_t& v, size_t indent, bool insert_newlines)
{
strm << static_cast<int32_t>(v);
}
template<class t_stream>
- void dump_as_json(t_stream& strm, const bool& v, size_t indent)
+ void dump_as_json(t_stream& strm, const bool& v, size_t indent, bool insert_newlines)
{
if(v)
strm << "true";
@@ -143,16 +151,17 @@ namespace epee
template<class t_stream, class t_type>
- void dump_as_json(t_stream& strm, const t_type& v, size_t indent)
+ void dump_as_json(t_stream& strm, const t_type& v, size_t indent, bool insert_newlines)
{
strm << v;
}
template<class t_stream>
- void dump_as_json(t_stream& strm, const section& sec, size_t indent)
+ void dump_as_json(t_stream& strm, const section& sec, size_t indent, bool insert_newlines)
{
size_t local_indent = indent + 1;
- strm << "{\r\n";
+ std::string newline = insert_newlines ? "\r\n" : "";
+ strm << "{" << newline;
std::string indent_str = make_indent(local_indent);
if(sec.m_entries.size())
{
@@ -160,10 +169,10 @@ namespace epee
for(auto it = sec.m_entries.begin(); it!= sec.m_entries.end();it++)
{
strm << indent_str << "\"" << misc_utils::parse::transform_to_escape_sequence(it->first) << "\"" << ": ";
- dump_as_json(strm, it->second, local_indent);
+ dump_as_json(strm, it->second, local_indent, insert_newlines);
if(it_last != it)
strm << ",";
- strm << "\r\n";
+ strm << newline;
}
}
strm << make_indent(indent) << "}";