Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
picojson::value Class Reference
Collaboration diagram for picojson::value:

Classes

union  _storage
 

Public Types

typedef std::vector< valuearray
 
typedef std::map< std::string, valueobject
 

Public Member Functions

 value ()
 
 value (int type, bool)
 
 value (bool b)
 
 value (double n)
 
 value (const std::string &s)
 
 value (const array &a)
 
 value (const object &o)
 
 value (const char *s)
 
 value (const char *s, size_t len)
 
 ~value ()
 
 value (const value &x)
 
valueoperator= (const value &x)
 
void swap (value &x) PICOJSON_NOEXCEPT
 
template<typename T >
bool is () const
 
template<typename T >
const Tget () const
 
template<typename T >
Tget ()
 
template<typename T >
void set (const T &)
 
bool evaluate_as_boolean () const
 
const valueget (const size_t idx) const
 
const valueget (const std::string &key) const
 
valueget (const size_t idx)
 
valueget (const std::string &key)
 
bool contains (const size_t idx) const
 
bool contains (const std::string &key) const
 
std::string to_str () const
 
template<typename Iter >
void serialize (Iter os, bool prettify=false) const
 
std::string serialize (bool prettify=false) const
 
template<>
bool is () const
 

Protected Attributes

int type_
 
_storage u_
 

Detailed Description

Definition at line 140 of file spec_test_generator.cpp.

Member Typedef Documentation

◆ array

Definition at line 142 of file spec_test_generator.cpp.

◆ object

std::map<std::string, value> picojson::value::object

Definition at line 143 of file spec_test_generator.cpp.

Constructor & Destructor Documentation

◆ value() [1/10]

picojson::value::value ( )
inline

◆ value() [2/10]

picojson::value::value ( int type,
bool  )
inline

Definition at line 226 of file spec_test_generator.cpp.

226 : type_(type), u_() {
227 switch (type) {
228# define INIT(p, v) \
229 case p##type: u_.p = v; break
230 INIT(boolean_, false);
231 INIT(number_, 0.0);
232# ifdef PICOJSON_USE_INT64
233 INIT(int64_, 0);
234# endif
235 INIT(string_, new std::string());
236 INIT(array_, new array());
237 INIT(object_, new object());
238# undef INIT
239 default: break;
240 }
241}
std::vector< value > array
#define INIT(p, v)

◆ value() [3/10]

picojson::value::value ( bool b)
inlineexplicit

◆ value() [4/10]

picojson::value::value ( double n)
inlineexplicit

Definition at line 249 of file spec_test_generator.cpp.

249 : type_(number_type), u_() {
250 if (
251# ifdef _MSC_VER
252 !_finite(n)
253# elif __cplusplus >= 201103L
254 std::isnan(n) || std::isinf(n)
255# else
256 isnan(n) || isinf(n)
257# endif
258 ) {
259 throw std::overflow_error("");
260 }
261 u_.number_ = n;
262}
bool isnan(float f)

◆ value() [5/10]

picojson::value::value ( const std::string & s)
inlineexplicit

Definition at line 264 of file spec_test_generator.cpp.

264: type_(string_type), u_() { u_.string_ = new std::string(s); }
char * s

◆ value() [6/10]

picojson::value::value ( const array & a)
inlineexplicit

Definition at line 266 of file spec_test_generator.cpp.

266: type_(array_type), u_() { u_.array_ = new array(a); }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181

◆ value() [7/10]

picojson::value::value ( const object & o)
inlineexplicit

Definition at line 268 of file spec_test_generator.cpp.

268: type_(object_type), u_() { u_.object_ = new object(o); }
std::map< std::string, value > object

◆ value() [8/10]

picojson::value::value ( const char * s)
inlineexplicit

Definition at line 278 of file spec_test_generator.cpp.

278: type_(string_type), u_() { u_.string_ = new std::string(s); }

◆ value() [9/10]

picojson::value::value ( const char * s,
size_t len )
inline

Definition at line 280 of file spec_test_generator.cpp.

280: type_(string_type), u_() { u_.string_ = new std::string(s, len); }
size_t len

◆ ~value()

picojson::value::~value ( )
inline

Definition at line 294 of file spec_test_generator.cpp.

294{ clear(); }

◆ value() [10/10]

picojson::value::value ( const value & x)
inline

Definition at line 296 of file spec_test_generator.cpp.

296 : type_(x.type_), u_() {
297 switch (type_) {
298# define INIT(p, v) \
299 case p##type: u_.p = v; break
300 INIT(string_, new std::string(*x.u_.string_));
301 INIT(array_, new array(*x.u_.array_));
302 INIT(object_, new object(*x.u_.object_));
303# undef INIT
304 default: u_ = x.u_; break;
305 }
306}

Member Function Documentation

◆ contains() [1/2]

bool picojson::value::contains ( const size_t idx) const
inline

Definition at line 446 of file spec_test_generator.cpp.

446 {
447 PICOJSON_ASSERT(is<array>());
448 return idx < u_.array_->size();
449}
#define PICOJSON_ASSERT(e)

◆ contains() [2/2]

bool picojson::value::contains ( const std::string & key) const
inline

Definition at line 451 of file spec_test_generator.cpp.

451 {
452 PICOJSON_ASSERT(is<object>());
453 object::const_iterator i = u_.object_->find(key);
454 return i != u_.object_->end();
455}

◆ evaluate_as_boolean()

bool picojson::value::evaluate_as_boolean ( ) const
inline

Definition at line 407 of file spec_test_generator.cpp.

407 {
408 switch (type_) {
409 case null_type: return false;
410 case boolean_type: return u_.boolean_;
411 case number_type: return u_.number_ != 0;
412# ifdef PICOJSON_USE_INT64
413 case int64_type: return u_.int64_ != 0;
414# endif
415 case string_type: return !u_.string_->empty();
416 default: return true;
417 }
418}

◆ get() [1/6]

template<typename T >
T & picojson::value::get ( )

◆ get() [2/6]

template<typename T >
const T & picojson::value::get ( ) const
Here is the caller graph for this function:

◆ get() [3/6]

value & picojson::value::get ( const size_t idx)
inline

Definition at line 426 of file spec_test_generator.cpp.

426 {
427 static value s_null;
428 PICOJSON_ASSERT(is<array>());
429 return idx < u_.array_->size() ? (*u_.array_)[idx] : s_null;
430}

◆ get() [4/6]

const value & picojson::value::get ( const size_t idx) const
inline

Definition at line 420 of file spec_test_generator.cpp.

420 {
421 static value s_null;
422 PICOJSON_ASSERT(is<array>());
423 return idx < u_.array_->size() ? (*u_.array_)[idx] : s_null;
424}

◆ get() [5/6]

value & picojson::value::get ( const std::string & key)
inline

Definition at line 439 of file spec_test_generator.cpp.

439 {
440 static value s_null;
441 PICOJSON_ASSERT(is<object>());
442 object::iterator i = u_.object_->find(key);
443 return i != u_.object_->end() ? i->second : s_null;
444}

◆ get() [6/6]

const value & picojson::value::get ( const std::string & key) const
inline

Definition at line 432 of file spec_test_generator.cpp.

432 {
433 static value s_null;
434 PICOJSON_ASSERT(is<object>());
435 object::const_iterator i = u_.object_->find(key);
436 return i != u_.object_->end() ? i->second : s_null;
437}

◆ is() [1/2]

template<typename T >
bool picojson::value::is ( ) const
Here is the caller graph for this function:

◆ is() [2/2]

template<>
bool picojson::value::is ( ) const
inline

Definition at line 343 of file spec_test_generator.cpp.

343 {
344 return type_ == number_type
345# ifdef PICOJSON_USE_INT64
346 || type_ == int64_type
347# endif
348 ;
349}

◆ operator=()

value & picojson::value::operator= ( const value & x)
inline

Definition at line 308 of file spec_test_generator.cpp.

308 {
309 if (this != &x) {
310 value t(x);
311 swap(t);
312 }
313 return *this;
314}
void swap(value &x) PICOJSON_NOEXCEPT
Here is the call graph for this function:

◆ serialize() [1/2]

std::string picojson::value::serialize ( bool prettify = false) const
inline

Definition at line 544 of file spec_test_generator.cpp.

544{ return _serialize(prettify ? 0 : -1); }

◆ serialize() [2/2]

template<typename Iter >
void picojson::value::serialize ( Iter os,
bool prettify = false ) const

Definition at line 540 of file spec_test_generator.cpp.

540 {
541 return _serialize(oi, prettify ? 0 : -1);
542}
Here is the caller graph for this function:

◆ set()

template<typename T >
void picojson::value::set ( const T & )

◆ swap()

void picojson::value::swap ( value & x)
inline

Definition at line 323 of file spec_test_generator.cpp.

323 {
324 std::swap(type_, x.type_);
325 std::swap(u_, x.u_);
326}
void swap(picojson::value &x, picojson::value &y)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_str()

std::string picojson::value::to_str ( ) const
inline

Definition at line 457 of file spec_test_generator.cpp.

457 {
458 switch (type_) {
459 case null_type: return "null";
460 case boolean_type: return u_.boolean_ ? "true" : "false";
461# ifdef PICOJSON_USE_INT64
462 case int64_type: {
463 char buf[sizeof("-9223372036854775808")];
464 SNPRINTF(buf, sizeof(buf), "%" PRId64, u_.int64_);
465 return buf;
466 }
467# endif
468 case number_type: {
469 char buf[256];
470 double tmp;
471 SNPRINTF(buf, sizeof(buf), fabs(u_.number_) < (1ULL << 53) && modf(u_.number_, &tmp) == 0 ? "%.f" : "%.17g",
472 u_.number_);
473# if PICOJSON_USE_LOCALE
474 char* decimal_point = localeconv()->decimal_point;
475 if (strcmp(decimal_point, ".") != 0) {
476 size_t decimal_point_len = strlen(decimal_point);
477 for (char* p = buf; *p != '\0'; ++p) {
478 if (strncmp(p, decimal_point, decimal_point_len) == 0) {
479 return std::string(buf, p) + "." + (p + decimal_point_len);
480 }
481 }
482 }
483# endif
484 return buf;
485 }
486 case string_type: return *u_.string_;
487 case array_type: return "array";
488 case object_type: return "object";
489 default: PICOJSON_ASSERT(0);
490# ifdef _MSC_VER
491 __assume(0);
492# endif
493 }
494 return std::string();
495}
const mie::Vuint & p
Definition bn.cpp:27
#define PRId64
Definition inttypes.h:88
#define SNPRINTF
void fabs()
uint8_t buf[2048]
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ type_

int picojson::value::type_
protected

Definition at line 156 of file spec_test_generator.cpp.

◆ u_

_storage picojson::value::u_
protected

Definition at line 157 of file spec_test_generator.cpp.


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