souffle  2.0.2-371-g6315b36
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes
json11::Json Class Referencefinal

#include <json11.h>

Collaboration diagram for json11::Json:
Collaboration graph

Public Types

using array = std::vector< Json >
 
using object = std::map< std::string, Json >
 
using shape = std::initializer_list< std::pair< std::string, Type > >
 
enum  Type {
  NUL, NUMBER, BOOL, STRING,
  ARRAY, OBJECT
}
 

Public Member Functions

const arrayarray_items () const
 
bool bool_value () const
 
std::string dump () const
 
void dump (std::string &out) const
 
bool has_shape (const shape &types, std::string &err) const
 
int int_value () const
 
bool is_array () const
 
bool is_bool () const
 
bool is_null () const
 
bool is_number () const
 
bool is_object () const
 
bool is_string () const
 
 Json () noexcept
 
 Json (array &&values)
 
 Json (bool value)
 
 Json (const array &values)
 
 Json (const char *value)
 
template<class M , typename std::enable_if< std::is_constructible< std::string, decltype(std::declval< M >().begin() ->first)>::value &&std::is_constructible< Json, decltype(std::declval< M >().begin() ->second)>::value , int , ::type = 0>
 Json (const M &m)
 
 Json (const object &values)
 
 Json (const std::string &value)
 
template<class T , class = decltype(&T::to_json)>
 Json (const T &t)
 
template<class V , typename std::enable_if< std::is_constructible< Json, decltype(*std::declval< V >().begin())>::value , int , ::type = 0>
 Json (const V &v)
 
 Json (double value)
 
 Json (long long value)
 
 Json (object &&values)
 
 Json (std::nullptr_t) noexcept
 
 Json (std::string &&value)
 
 Json (void *)=delete
 
long long long_value () const
 
double number_value () const
 
const objectobject_items () const
 
bool operator!= (const Json &rhs) const
 
bool operator< (const Json &rhs) const
 
bool operator<= (const Json &rhs) const
 
bool operator== (const Json &rhs) const
 
bool operator> (const Json &rhs) const
 
bool operator>= (const Json &rhs) const
 
const Jsonoperator[] (const std::string &key) const
 
const Jsonoperator[] (size_t i) const
 
const std::string & string_value () const
 
Type type () const
 

Static Public Member Functions

static Json parse (const char *in, std::string &err, JsonParse strategy=JsonParse::STANDARD)
 
static Json parse (const std::string &in, std::string &err, JsonParse strategy=JsonParse::STANDARD)
 
static std::vector< Jsonparse_multi (const std::string &in, std::string &err, JsonParse strategy=JsonParse::STANDARD)
 
static std::vector< Jsonparse_multi (const std::string &in, std::string::size_type &parser_stop_pos, std::string &err, JsonParse strategy=JsonParse::STANDARD)
 

Private Attributes

std::shared_ptr< JsonValuem_ptr
 

Detailed Description

Definition at line 87 of file json11.h.

Member Typedef Documentation

◆ array

using json11::Json::array = std::vector<Json>

Definition at line 93 of file json11.h.

◆ object

using json11::Json::object = std::map<std::string, Json>

Definition at line 94 of file json11.h.

◆ shape

using json11::Json::shape = std::initializer_list<std::pair<std::string, Type> >

Definition at line 223 of file json11.h.

Member Enumeration Documentation

◆ Type

Enumerator
NUL 
NUMBER 
BOOL 
STRING 
ARRAY 
OBJECT 

Definition at line 90 of file json11.h.

90 { NUL, NUMBER, BOOL, STRING, ARRAY, OBJECT };

Constructor & Destructor Documentation

◆ Json() [1/16]

json11::Json::Json ( )
inlinenoexcept

Definition at line 519 of file json11.h.

519 : m_ptr(statics().null) {}

Referenced by parse().

◆ Json() [2/16]

json11::Json::Json ( std::nullptr_t  )
inlinenoexcept

Definition at line 520 of file json11.h.

520 : m_ptr(statics().null) {}

◆ Json() [3/16]

json11::Json::Json ( double  value)
inline

Definition at line 521 of file json11.h.

521 : m_ptr(std::make_shared<JsonDouble>(value)) {}

◆ Json() [4/16]

json11::Json::Json ( long long  value)
inline

Definition at line 522 of file json11.h.

522 : m_ptr(std::make_shared<JsonInt>(value)) {}

◆ Json() [5/16]

json11::Json::Json ( bool  value)
inline

Definition at line 523 of file json11.h.

523 : m_ptr(value ? statics().t : statics().f) {}

◆ Json() [6/16]

json11::Json::Json ( const std::string &  value)
inline

Definition at line 524 of file json11.h.

524 : m_ptr(std::make_shared<JsonString>(value)) {}

◆ Json() [7/16]

json11::Json::Json ( std::string &&  value)
inline

Definition at line 525 of file json11.h.

525 : m_ptr(std::make_shared<JsonString>(std::move(value))) {}

◆ Json() [8/16]

json11::Json::Json ( const char *  value)
inline

Definition at line 526 of file json11.h.

526 : m_ptr(std::make_shared<JsonString>(value)) {}

◆ Json() [9/16]

json11::Json::Json ( const array values)
inline

Definition at line 527 of file json11.h.

527 : m_ptr(std::make_shared<JsonArray>(values)) {}

◆ Json() [10/16]

json11::Json::Json ( Json::array &&  values)
inline

Definition at line 528 of file json11.h.

528 : m_ptr(std::make_shared<JsonArray>(std::move(values))) {}

◆ Json() [11/16]

json11::Json::Json ( const object values)
inline

Definition at line 529 of file json11.h.

529 : m_ptr(std::make_shared<JsonObject>(values)) {}

◆ Json() [12/16]

json11::Json::Json ( Json::object &&  values)
inline

Definition at line 530 of file json11.h.

530 : m_ptr(std::make_shared<JsonObject>(std::move(values))) {}

◆ Json() [13/16]

template<class T , class = decltype(&T::to_json)>
json11::Json::Json ( const T &  t)
inline

Definition at line 112 of file json11.h.

112 : Json(t.to_json()) {}

◆ Json() [14/16]

template<class M , typename std::enable_if< std::is_constructible< std::string, decltype(std::declval< M >().begin() ->first)>::value &&std::is_constructible< Json, decltype(std::declval< M >().begin() ->second)>::value , int , ::type = 0>
json11::Json::Json ( const M &  m)
inline

Definition at line 120 of file json11.h.

120 : Json(object(m.begin(), m.end())) {}

◆ Json() [15/16]

template<class V , typename std::enable_if< std::is_constructible< Json, decltype(*std::declval< V >().begin())>::value , int , ::type = 0>
json11::Json::Json ( const V &  v)
inline

Definition at line 126 of file json11.h.

126 : Json(array(v.begin(), v.end())) {}

◆ Json() [16/16]

json11::Json::Json ( void *  )
delete

Member Function Documentation

◆ array_items()

const std::vector< Json > & json11::Json::array_items ( ) const
inline

Definition at line 554 of file json11.h.

554  {
555  return m_ptr->array_items();
556 }

References m_ptr.

◆ bool_value()

bool json11::Json::bool_value ( ) const
inline

Definition at line 548 of file json11.h.

548  {
549  return m_ptr->bool_value();
550 }

References m_ptr.

◆ dump() [1/2]

std::string json11::Json::dump ( ) const
inline

Definition at line 177 of file json11.h.

177  {
178  std::string out;
179  dump(out);
180  return out;
181  }

Referenced by has_shape().

◆ dump() [2/2]

void json11::Json::dump ( std::string &  out) const
inline

Definition at line 370 of file json11.h.

370  {
371  m_ptr->dump(out);
372 }

References m_ptr.

Referenced by souffle::WriteStreamJSON::writeNextTupleJSON().

◆ has_shape()

bool json11::Json::has_shape ( const shape types,
std::string &  err 
) const
inline

Definition at line 224 of file json11.h.

224  {
225  if (!is_object()) {
226  err = "expected JSON object, got " + dump();
227  return false;
228  }
229 
230  for (auto& item : types) {
231  if ((*this)[item.first].type() != item.second) {
232  err = "bad type for " + item.first + " in " + dump();
233  return false;
234  }
235  }
236 
237  return true;
238  }

References dump(), err, is_object(), and types.

Here is the call graph for this function:

◆ int_value()

int json11::Json::int_value ( ) const
inline

Definition at line 542 of file json11.h.

542  {
543  return m_ptr->int_value();
544 }

References m_ptr.

◆ is_array()

bool json11::Json::is_array ( ) const
inline

Definition at line 147 of file json11.h.

147  {
148  return type() == ARRAY;
149  }

References ARRAY, and type().

Here is the call graph for this function:

◆ is_bool()

bool json11::Json::is_bool ( ) const
inline

Definition at line 141 of file json11.h.

141  {
142  return type() == BOOL;
143  }

References BOOL, and type().

Here is the call graph for this function:

◆ is_null()

bool json11::Json::is_null ( ) const
inline

Definition at line 135 of file json11.h.

135  {
136  return type() == NUL;
137  }

References NUL, and type().

Here is the call graph for this function:

◆ is_number()

bool json11::Json::is_number ( ) const
inline

Definition at line 138 of file json11.h.

138  {
139  return type() == NUMBER;
140  }

References NUMBER, and type().

Here is the call graph for this function:

◆ is_object()

bool json11::Json::is_object ( ) const
inline

Definition at line 150 of file json11.h.

150  {
151  return type() == OBJECT;
152  }

References OBJECT, and type().

Referenced by has_shape().

Here is the call graph for this function:

◆ is_string()

bool json11::Json::is_string ( ) const
inline

Definition at line 144 of file json11.h.

144  {
145  return type() == STRING;
146  }

References STRING, and type().

Here is the call graph for this function:

◆ long_value()

long long json11::Json::long_value ( ) const
inline

Definition at line 545 of file json11.h.

545  {
546  return m_ptr->long_value();
547 }

References m_ptr.

◆ number_value()

double json11::Json::number_value ( ) const
inline

Definition at line 539 of file json11.h.

539  {
540  return m_ptr->number_value();
541 }

References m_ptr.

◆ object_items()

const std::map< std::string, Json > & json11::Json::object_items ( ) const
inline

Definition at line 557 of file json11.h.

557  {
558  return m_ptr->object_items();
559 }

References m_ptr.

◆ operator!=()

bool json11::Json::operator!= ( const Json rhs) const
inline

Definition at line 205 of file json11.h.

205  {
206  return !(*this == rhs);
207  }

References rhs.

◆ operator<()

bool json11::Json::operator< ( const Json rhs) const
inline

Definition at line 621 of file json11.h.

621  {
622  if (m_ptr == other.m_ptr) {
623  return false;
624  }
625  if (m_ptr->type() != other.m_ptr->type()) {
626  return m_ptr->type() < other.m_ptr->type();
627  }
628 
629  return m_ptr->less(other.m_ptr.get());
630 }

References m_ptr.

◆ operator<=()

bool json11::Json::operator<= ( const Json rhs) const
inline

Definition at line 208 of file json11.h.

208  {
209  return !(rhs < *this);
210  }

References rhs.

◆ operator==()

bool json11::Json::operator== ( const Json rhs) const
inline

Definition at line 610 of file json11.h.

610  {
611  if (m_ptr == other.m_ptr) {
612  return true;
613  }
614  if (m_ptr->type() != other.m_ptr->type()) {
615  return false;
616  }
617 
618  return m_ptr->equals(other.m_ptr.get());
619 }

References m_ptr.

◆ operator>()

bool json11::Json::operator> ( const Json rhs) const
inline

Definition at line 211 of file json11.h.

211  {
212  return (rhs < *this);
213  }

References rhs.

◆ operator>=()

bool json11::Json::operator>= ( const Json rhs) const
inline

Definition at line 214 of file json11.h.

214  {
215  return !(*this < rhs);
216  }

References rhs.

◆ operator[]() [1/2]

const Json & json11::Json::operator[] ( const std::string &  key) const
inline

Definition at line 563 of file json11.h.

563  {
564  return (*m_ptr)[key];
565 }

References m_ptr.

◆ operator[]() [2/2]

const Json & json11::Json::operator[] ( size_t  i) const
inline

Definition at line 560 of file json11.h.

560  {
561  return (*m_ptr)[i];
562 }

References i, and m_ptr.

◆ parse() [1/2]

static Json json11::Json::parse ( const char *  in,
std::string &  err,
JsonParse  strategy = JsonParse::STANDARD 
)
inlinestatic

Definition at line 186 of file json11.h.

186  {
187  if (in == nullptr) {
188  err = "null input";
189  return nullptr;
190  }
191  return parse(std::string(in), err, strategy);
192  }

References err, parse(), and strategy.

Here is the call graph for this function:

◆ parse() [2/2]

Json json11::Json::parse ( const std::string &  in,
std::string &  err,
JsonParse  strategy = JsonParse::STANDARD 
)
inlinestatic

Definition at line 1071 of file json11.h.

1071  {
1072  JsonParser parser{in, 0, err, false, strategy};
1073  Json result = parser.parse_json(0);
1074 
1075  // Check for any trailing garbage
1076  parser.consume_garbage();
1077  if (parser.failed) {
1078  return Json();
1079  }
1080  if (parser.i != in.size()) {
1081  return parser.fail("unexpected trailing " + esc(in[parser.i]));
1082  }
1083 
1084  return result;
1085 }

References err, json11::esc(), Json(), and strategy.

Referenced by parse(), and souffle::SerialisationStream< true >::SerialisationStream().

Here is the call graph for this function:

◆ parse_multi() [1/2]

static std::vector<Json> json11::Json::parse_multi ( const std::string &  in,
std::string &  err,
JsonParse  strategy = JsonParse::STANDARD 
)
inlinestatic

Definition at line 197 of file json11.h.

198  {
199  std::string::size_type parser_stop_pos;
200  return parse_multi(in, parser_stop_pos, err, strategy);
201  }

References err, parse_multi(), and strategy.

Here is the call graph for this function:

◆ parse_multi() [2/2]

static std::vector<Json> json11::Json::parse_multi ( const std::string &  in,
std::string::size_type &  parser_stop_pos,
std::string &  err,
JsonParse  strategy = JsonParse::STANDARD 
)
static

Referenced by parse_multi().

◆ string_value()

const std::string & json11::Json::string_value ( ) const
inline

Definition at line 551 of file json11.h.

551  {
552  return m_ptr->string_value();
553 }

References m_ptr.

◆ type()

Json::Type json11::Json::type ( ) const
inline

Definition at line 536 of file json11.h.

536  {
537  return m_ptr->type();
538 }

References m_ptr.

Referenced by is_array(), is_bool(), is_null(), is_number(), is_object(), and is_string().

Field Documentation

◆ m_ptr

std::shared_ptr<JsonValue> json11::Json::m_ptr
private

The documentation for this class was generated from the following file:
json11::Json::Json
Json() noexcept
Definition: json11.h:519
json11::statics
static const Statics & statics()
Definition: json11.h:504
err
std::string & err
Definition: json11.h:664
json11::Json::NUL
@ NUL
Definition: json11.h:90
json11::Json::parse
static Json parse(const std::string &in, std::string &err, JsonParse strategy=JsonParse::STANDARD)
Definition: json11.h:1071
m
var m
Definition: htmlJsChartistMin.h:15
json11::Json::m_ptr
std::shared_ptr< JsonValue > m_ptr
Definition: json11.h:241
types
std::vector< Own< ast::Type > > types
Definition: ComponentInstantiation.cpp:64
rhs
Own< Argument > rhs
Definition: ResolveAliases.cpp:185
json11::Json::NUMBER
@ NUMBER
Definition: json11.h:90
json11::Json::parse_multi
static std::vector< Json > parse_multi(const std::string &in, std::string::size_type &parser_stop_pos, std::string &err, JsonParse strategy=JsonParse::STANDARD)
i
size_t i
Definition: json11.h:663
json11::esc
static std::string esc(char c)
Definition: json11.h:640
json11::Json::OBJECT
@ OBJECT
Definition: json11.h:90
strategy
const JsonParse strategy
Definition: json11.h:666
json11::Json::is_object
bool is_object() const
Definition: json11.h:150
json11::Json::array
std::vector< Json > array
Definition: json11.h:93
json11::Json::ARRAY
@ ARRAY
Definition: json11.h:90
json11::Json::type
Type type() const
Definition: json11.h:536
json11::Json::STRING
@ STRING
Definition: json11.h:90
json11::Json::dump
std::string dump() const
Definition: json11.h:177
json11::Json::BOOL
@ BOOL
Definition: json11.h:90