Electroneum
json_archive< true > Struct Template Reference

#include <json_archive.h>

Inheritance diagram for json_archive< true >:
Collaboration diagram for json_archive< true >:

Public Member Functions

 json_archive (stream_type &s, bool indent=false)
 
template<class T >
void serialize_int (T v)
 
void serialize_blob (void *buf, size_t len, const char *delimiter="\)
 
void serialize_string (std::string str, const char *delimiter="\)
 
template<class T >
void serialize_varint (T &v)
 
void begin_string (const char *delimiter="\)
 
void end_string (const char *delimiter="\)
 
void begin_array (size_t s=0)
 
void delimit_array ()
 
void end_array ()
 
void write_variant_tag (const char *t)
 
- Public Member Functions inherited from json_archive_base< std::ostream, true >
 json_archive_base (stream_type &s, bool indent=false)
 
void tag (const char *tag)
 
void begin_object ()
 
void end_object ()
 
void begin_variant ()
 
void end_variant ()
 
std::ostream & stream ()
 

Static Public Member Functions

template<typename T >
static auto promote_to_printable_integer_type (T v) -> decltype(+v)
 

Additional Inherited Members

- Public Types inherited from json_archive_base< std::ostream, true >
typedef std::ostream stream_type
 
typedef json_archive_base< std::ostream, IsSaving > base_type
 
typedef boost::mpl::bool_< IsSaving > is_saving
 
typedef const char * variant_tag_type
 
- Protected Member Functions inherited from json_archive_base< std::ostream, true >
void make_indent ()
 
- Protected Attributes inherited from json_archive_base< std::ostream, true >
stream_typestream_
 
bool indent_
 
bool object_begin
 
size_t depth_
 

Detailed Description

template<>
struct json_archive< true >

Definition at line 115 of file json_archive.h.

Constructor & Destructor Documentation

◆ json_archive()

json_archive< true >::json_archive ( stream_type s,
bool  indent = false 
)
inline

Definition at line 117 of file json_archive.h.

117 : base_type(s, indent), inner_array_size_(0) { }
json_archive_base< std::ostream, IsSaving > base_type
Definition: json_archive.h:54

Member Function Documentation

◆ begin_array()

void json_archive< true >::begin_array ( size_t  s = 0)
inline

Definition at line 164 of file json_archive.h.

165  {
166  inner_array_size_ = s;
167  ++depth_;
168  stream_ << "[ ";
169  }

◆ begin_string()

void json_archive< true >::begin_string ( const char *  delimiter = "\"")
inline

Definition at line 154 of file json_archive.h.

155  {
156  stream_ << delimiter;
157  }

◆ delimit_array()

void json_archive< true >::delimit_array ( )
inline

Definition at line 171 of file json_archive.h.

172  {
173  stream_ << ", ";
174  }

◆ end_array()

void json_archive< true >::end_array ( )
inline

Definition at line 176 of file json_archive.h.

177  {
178  --depth_;
179  if (0 < inner_array_size_)
180  {
181  make_indent();
182  }
183  stream_ << "]";
184  }
Here is the call graph for this function:

◆ end_string()

void json_archive< true >::end_string ( const char *  delimiter = "\"")
inline

Definition at line 159 of file json_archive.h.

160  {
161  stream_ << delimiter;
162  }

◆ promote_to_printable_integer_type()

template<typename T >
static auto json_archive< true >::promote_to_printable_integer_type ( T  v) -> decltype(+v)
inlinestatic

Definition at line 120 of file json_archive.h.

121  {
122  // Unary operator '+' performs integral promotion on type T [expr.unary.op].
123  // If T is signed or unsigned char, it's promoted to int and printed as number.
124  return +v;
125  }

◆ serialize_blob()

void json_archive< true >::serialize_blob ( void *  buf,
size_t  len,
const char *  delimiter = "\"" 
)
inline

Definition at line 133 of file json_archive.h.

133  {
134  begin_string(delimiter);
135  for (size_t i = 0; i < len; i++) {
136  unsigned char c = ((unsigned char *)buf)[i];
137  stream_ << std::hex << std::setw(2) << std::setfill('0') << (int)c;
138  }
139  end_string(delimiter);
140  }
void end_string(const char *delimiter="\)
Definition: json_archive.h:159
void begin_string(const char *delimiter="\)
Definition: json_archive.h:154
const char * buf
Definition: slow_memmem.cpp:74

◆ serialize_int()

template<class T >
void json_archive< true >::serialize_int ( T  v)
inline

Definition at line 128 of file json_archive.h.

129  {
130  stream_ << std::dec << promote_to_printable_integer_type(v);
131  }
static auto promote_to_printable_integer_type(T v) -> decltype(+v)
Definition: json_archive.h:120

◆ serialize_string()

void json_archive< true >::serialize_string ( std::string  str,
const char *  delimiter = "\"" 
)
inline

Definition at line 142 of file json_archive.h.

142  {
143  begin_string(delimiter);
144  stream_ << str;
145  end_string(delimiter);
146  }
void end_string(const char *delimiter="\)
Definition: json_archive.h:159
void begin_string(const char *delimiter="\)
Definition: json_archive.h:154

◆ serialize_varint()

template<class T >
void json_archive< true >::serialize_varint ( T v)
inline

Definition at line 149 of file json_archive.h.

150  {
151  stream_ << std::dec << promote_to_printable_integer_type(v);
152  }
static auto promote_to_printable_integer_type(T v) -> decltype(+v)
Definition: json_archive.h:120

◆ write_variant_tag()

void json_archive< true >::write_variant_tag ( const char *  t)
inline

Definition at line 186 of file json_archive.h.

187  {
188  tag(t);
189  }

The documentation for this struct was generated from the following file: