2
2
#include < fc/variant.hpp>
3
3
#include < fc/filesystem.hpp>
4
4
5
+ #define DEFAULT_MAX_RECURSION_DEPTH 200
6
+
5
7
namespace fc
6
8
{
7
9
using std::ostream;
@@ -28,49 +30,53 @@ namespace fc
28
30
};
29
31
30
32
static ostream& to_stream ( ostream& out, const fc::string&);
31
- static ostream& to_stream ( ostream& out, const variant& v, output_formatting format = stringify_large_ints_and_doubles );
32
- static ostream& to_stream ( ostream& out, const variants& v, output_formatting format = stringify_large_ints_and_doubles );
33
- static ostream& to_stream ( ostream& out, const variant_object& v, output_formatting format = stringify_large_ints_and_doubles );
33
+ static ostream& to_stream ( ostream& out, const variant& v, output_formatting format = stringify_large_ints_and_doubles, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH );
34
+ static ostream& to_stream ( ostream& out, const variants& v, output_formatting format = stringify_large_ints_and_doubles, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH );
35
+ static ostream& to_stream ( ostream& out, const variant_object& v, output_formatting format = stringify_large_ints_and_doubles, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH );
36
+
37
+ // XXX static variant from_stream( buffered_istream& in, parse_type ptype = legacy_parser, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH );
34
38
35
- static variant from_string ( const string& utf8_str, parse_type ptype = legacy_parser );
36
- static variants variants_from_string ( const string& utf8_str, parse_type ptype = legacy_parser );
37
- static string to_string ( const variant& v, output_formatting format = stringify_large_ints_and_doubles );
38
- static string to_pretty_string ( const variant& v, output_formatting format = stringify_large_ints_and_doubles );
39
+ static variant from_string ( const string& utf8_str, parse_type ptype = legacy_parser, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH );
40
+ static variants variants_from_string ( const string& utf8_str, parse_type ptype = legacy_parser, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH );
41
+ static string to_string ( const variant& v, output_formatting format = stringify_large_ints_and_doubles, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH );
42
+ static string to_pretty_string ( const variant& v, output_formatting format = stringify_large_ints_and_doubles, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH );
39
43
40
- static bool is_valid ( const std::string& json_str, parse_type ptype = legacy_parser );
44
+ static bool is_valid ( const std::string& json_str, parse_type ptype = legacy_parser, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH );
41
45
42
46
template <typename T>
43
- static void save_to_file ( const T& v, const fc::path& fi, bool pretty = true , output_formatting format = stringify_large_ints_and_doubles )
47
+ static void save_to_file ( const T& v, const fc::path& fi, bool pretty = true , output_formatting format = stringify_large_ints_and_doubles, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH )
44
48
{
45
- save_to_file ( variant (v), fi, pretty, format );
49
+ save_to_file ( variant (v, max_depth ), fi, pretty, format, max_depth );
46
50
}
47
51
48
- static void save_to_file ( const variant& v, const fc::path& fi, bool pretty = true , output_formatting format = stringify_large_ints_and_doubles );
49
- static variant from_file ( const fc::path& p, parse_type ptype = legacy_parser );
52
+ static void save_to_file ( const variant& v, const fc::path& fi, bool pretty = true , output_formatting format = stringify_large_ints_and_doubles, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH );
53
+ static variant from_file ( const fc::path& p, parse_type ptype = legacy_parser, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH );
50
54
51
55
template <typename T>
52
- static T from_file ( const fc::path& p, parse_type ptype = legacy_parser )
56
+ static T from_file ( const fc::path& p, parse_type ptype = legacy_parser, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH )
53
57
{
54
- return json::from_file (p, ptype).as <T>();
58
+ return json::from_file (p, ptype, max_depth ).as <T>();
55
59
}
56
60
57
61
template <typename T>
58
- static string to_string ( const T& v, output_formatting format = stringify_large_ints_and_doubles )
62
+ static string to_string ( const T& v, output_formatting format = stringify_large_ints_and_doubles, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH )
59
63
{
60
- return to_string ( variant (v), format );
64
+ return to_string ( variant (v, max_depth ), format, max_depth );
61
65
}
62
66
63
67
template <typename T>
64
- static string to_pretty_string ( const T& v, output_formatting format = stringify_large_ints_and_doubles )
68
+ static string to_pretty_string ( const T& v, output_formatting format = stringify_large_ints_and_doubles, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH )
65
69
{
66
- return to_pretty_string ( variant (v), format );
70
+ return to_pretty_string ( variant (v, max_depth ), format, max_depth );
67
71
}
68
72
69
73
template <typename T>
70
- static void save_to_file ( const T& v, const std::string& p, bool pretty = true , output_formatting format = stringify_large_ints_and_doubles )
74
+ static void save_to_file ( const T& v, const std::string& p, bool pretty = true , output_formatting format = stringify_large_ints_and_doubles, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH )
71
75
{
72
- save_to_file ( variant (v), fc::path (p), pretty );
76
+ save_to_file ( variant (v, max_depth ), fc::path (p), pretty, format, max_depth );
73
77
}
74
78
};
75
79
76
80
} // fc
81
+
82
+ #undef DEFAULT_MAX_RECURSION_DEPTH
0 commit comments