ONE - On-device Neural Engine
Loading...
Searching...
No Matches
flexbuffers::Reference Class Reference

#include <flexbuffers.h>

Public Member Functions

 Reference ()
 
 Reference (const uint8_t *data, uint8_t parent_width, uint8_t byte_width, Type type)
 
 Reference (const uint8_t *data, uint8_t parent_width, uint8_t packed_type)
 
Type GetType () const
 
bool IsNull () const
 
bool IsBool () const
 
bool IsInt () const
 
bool IsUInt () const
 
bool IsIntOrUint () const
 
bool IsFloat () const
 
bool IsNumeric () const
 
bool IsString () const
 
bool IsKey () const
 
bool IsVector () const
 
bool IsUntypedVector () const
 
bool IsTypedVector () const
 
bool IsFixedTypedVector () const
 
bool IsAnyVector () const
 
bool IsMap () const
 
bool IsBlob () const
 
bool AsBool () const
 
int64_t AsInt64 () const
 
int32_t AsInt32 () const
 
int16_t AsInt16 () const
 
int8_t AsInt8 () const
 
uint64_t AsUInt64 () const
 
uint32_t AsUInt32 () const
 
uint16_t AsUInt16 () const
 
uint8_t AsUInt8 () const
 
double AsDouble () const
 
float AsFloat () const
 
const char * AsKey () const
 
String AsString () const
 
std::string ToString () const
 
void ToString (bool strings_quoted, bool keys_quoted, std::string &s) const
 
Blob AsBlob () const
 
Vector AsVector () const
 
TypedVector AsTypedVector () const
 
FixedTypedVector AsFixedTypedVector () const
 
Map AsMap () const
 
template<typename T >
As () const
 
bool MutateInt (int64_t i)
 
bool MutateBool (bool b)
 
bool MutateUInt (uint64_t u)
 
bool MutateFloat (float f)
 
bool MutateFloat (double d)
 
bool MutateString (const char *str, size_t len)
 
bool MutateString (const char *str)
 
bool MutateString (const std::string &str)
 
template<>
bool As () const
 
template<>
int8_t As () const
 
template<>
int16_t As () const
 
template<>
int32_t As () const
 
template<>
int64_t As () const
 
template<>
uint8_t As () const
 
template<>
uint16_t As () const
 
template<>
uint32_t As () const
 
template<>
uint64_t As () const
 
template<>
double As () const
 
template<>
float As () const
 
template<>
String As () const
 
template<>
Blob As () const
 
template<>
Vector As () const
 
template<>
TypedVector As () const
 
template<>
FixedTypedVector As () const
 
template<>
Map As () const
 

Detailed Description

Definition at line 389 of file flexbuffers.h.

Constructor & Destructor Documentation

◆ Reference() [1/3]

flexbuffers::Reference::Reference ( )
inline

Definition at line 392 of file flexbuffers.h.

392: data_(nullptr), parent_width_(0), byte_width_(BIT_WIDTH_8), type_(FBT_NULL) {}

◆ Reference() [2/3]

flexbuffers::Reference::Reference ( const uint8_t *  data,
uint8_t  parent_width,
uint8_t  byte_width,
Type  type 
)
inline

Definition at line 394 of file flexbuffers.h.

395 : data_(data), parent_width_(parent_width), byte_width_(byte_width), type_(type)
396 {
397 }

◆ Reference() [3/3]

flexbuffers::Reference::Reference ( const uint8_t *  data,
uint8_t  parent_width,
uint8_t  packed_type 
)
inline

Definition at line 399 of file flexbuffers.h.

400 : data_(data), parent_width_(parent_width)
401 {
402 byte_width_ = 1U << static_cast<BitWidth>(packed_type & 3);
403 type_ = static_cast<Type>(packed_type >> 2);
404 }

Member Function Documentation

◆ As() [1/18]

template<typename T >
T flexbuffers::Reference::As ( ) const

◆ As() [2/18]

template<>
bool flexbuffers::Reference::As ( ) const
inline

Definition at line 901 of file flexbuffers.h.

901{ return AsBool(); }

References AsBool().

◆ As() [3/18]

template<>
int8_t flexbuffers::Reference::As ( ) const
inline

Definition at line 903 of file flexbuffers.h.

903{ return AsInt8(); }
int8_t AsInt8() const

References AsInt8().

◆ As() [4/18]

template<>
int16_t flexbuffers::Reference::As ( ) const
inline

Definition at line 904 of file flexbuffers.h.

904{ return AsInt16(); }
int16_t AsInt16() const

References AsInt16().

◆ As() [5/18]

template<>
int32_t flexbuffers::Reference::As ( ) const
inline

Definition at line 905 of file flexbuffers.h.

905{ return AsInt32(); }
int32_t AsInt32() const

References AsInt32().

◆ As() [6/18]

template<>
int64_t flexbuffers::Reference::As ( ) const
inline

Definition at line 906 of file flexbuffers.h.

906{ return AsInt64(); }
int64_t AsInt64() const

References AsInt64().

◆ As() [7/18]

template<>
uint8_t flexbuffers::Reference::As ( ) const
inline

Definition at line 908 of file flexbuffers.h.

908{ return AsUInt8(); }
uint8_t AsUInt8() const

References AsUInt8().

◆ As() [8/18]

template<>
uint16_t flexbuffers::Reference::As ( ) const
inline

Definition at line 909 of file flexbuffers.h.

909{ return AsUInt16(); }
uint16_t AsUInt16() const

References AsUInt16().

◆ As() [9/18]

template<>
uint32_t flexbuffers::Reference::As ( ) const
inline

Definition at line 910 of file flexbuffers.h.

910{ return AsUInt32(); }
uint32_t AsUInt32() const

References AsUInt32().

◆ As() [10/18]

template<>
uint64_t flexbuffers::Reference::As ( ) const
inline

Definition at line 911 of file flexbuffers.h.

911{ return AsUInt64(); }
uint64_t AsUInt64() const

References AsUInt64().

◆ As() [11/18]

template<>
double flexbuffers::Reference::As ( ) const
inline

Definition at line 913 of file flexbuffers.h.

913{ return AsDouble(); }
double AsDouble() const

References AsDouble().

◆ As() [12/18]

template<>
float flexbuffers::Reference::As ( ) const
inline

Definition at line 914 of file flexbuffers.h.

914{ return AsFloat(); }
float AsFloat() const

References AsFloat().

◆ As() [13/18]

template<>
String flexbuffers::Reference::As ( ) const
inline

Definition at line 916 of file flexbuffers.h.

916{ return AsString(); }
String AsString() const

References AsString().

◆ As() [14/18]

template<>
Blob flexbuffers::Reference::As ( ) const
inline

Definition at line 919 of file flexbuffers.h.

919{ return AsBlob(); }

References AsBlob().

◆ As() [15/18]

template<>
Vector flexbuffers::Reference::As ( ) const
inline

Definition at line 920 of file flexbuffers.h.

920{ return AsVector(); }
Vector AsVector() const

References AsVector().

◆ As() [16/18]

template<>
TypedVector flexbuffers::Reference::As ( ) const
inline

Definition at line 921 of file flexbuffers.h.

921{ return AsTypedVector(); }
TypedVector AsTypedVector() const

References AsTypedVector().

◆ As() [17/18]

template<>
FixedTypedVector flexbuffers::Reference::As ( ) const
inline

Definition at line 922 of file flexbuffers.h.

923{
924 return AsFixedTypedVector();
925}
FixedTypedVector AsFixedTypedVector() const

References AsFixedTypedVector().

◆ As() [18/18]

template<>
Map flexbuffers::Reference::As ( ) const
inline

Definition at line 926 of file flexbuffers.h.

926{ return AsMap(); }

References AsMap().

◆ AsBlob()

Blob flexbuffers::Reference::AsBlob ( ) const
inline

Definition at line 681 of file flexbuffers.h.

682 {
683 if (type_ == FBT_BLOB || type_ == FBT_STRING)
684 {
685 return Blob(Indirect(), byte_width_);
686 }
687 else
688 {
689 return Blob::EmptyBlob();
690 }
691 }
static Blob EmptyBlob()

References flexbuffers::Blob::EmptyBlob(), flexbuffers::FBT_BLOB, and flexbuffers::FBT_STRING.

Referenced by As(), and ToString().

◆ AsBool()

bool flexbuffers::Reference::AsBool ( ) const
inline

Definition at line 424 of file flexbuffers.h.

425 {
426 return (type_ == FBT_BOOL ? ReadUInt64(data_, parent_width_) : AsUInt64()) != 0;
427 }
uint64_t ReadUInt64(const uint8_t *data, uint8_t byte_width)

References AsUInt64(), flexbuffers::FBT_BOOL, and flexbuffers::ReadUInt64().

Referenced by As(), and ToString().

◆ AsDouble()

double flexbuffers::Reference::AsDouble ( ) const
inline

Definition at line 510 of file flexbuffers.h.

511 {
512 if (type_ == FBT_FLOAT)
513 {
514 // A fast path for the common case.
515 return ReadDouble(data_, parent_width_);
516 }
517 else
518 switch (type_)
519 {
521 return ReadDouble(Indirect(), byte_width_);
522 case FBT_INT:
523 return static_cast<double>(ReadInt64(data_, parent_width_));
524 case FBT_UINT:
525 return static_cast<double>(ReadUInt64(data_, parent_width_));
526 case FBT_INDIRECT_INT:
527 return static_cast<double>(ReadInt64(Indirect(), byte_width_));
529 return static_cast<double>(ReadUInt64(Indirect(), byte_width_));
530 case FBT_NULL:
531 return 0.0;
532 case FBT_STRING:
533 {
534 double d;
536 return d;
537 }
538 case FBT_VECTOR:
539 return static_cast<double>(AsVector().size());
540 case FBT_BOOL:
541 return static_cast<double>(ReadUInt64(data_, parent_width_));
542 default:
543 // Convert strings and other things to float.
544 return 0;
545 }
546 }
size_t size() const
bool StringToNumber(const char *s, T *val)
Definition util.h:363
double ReadDouble(const uint8_t *data, uint8_t byte_width)
int64_t ReadInt64(const uint8_t *data, uint8_t byte_width)

References AsString(), AsVector(), flexbuffers::FBT_BOOL, flexbuffers::FBT_FLOAT, flexbuffers::FBT_INDIRECT_FLOAT, flexbuffers::FBT_INDIRECT_INT, flexbuffers::FBT_INDIRECT_UINT, flexbuffers::FBT_INT, flexbuffers::FBT_NULL, flexbuffers::FBT_STRING, flexbuffers::FBT_UINT, flexbuffers::FBT_VECTOR, flexbuffers::ReadDouble(), flexbuffers::ReadInt64(), flexbuffers::ReadUInt64(), flexbuffers::Sized::size(), and flatbuffers::StringToNumber().

Referenced by As(), AsFloat(), and ToString().

◆ AsFixedTypedVector()

FixedTypedVector flexbuffers::Reference::AsFixedTypedVector ( ) const
inline

Definition at line 730 of file flexbuffers.h.

731 {
732 if (IsFixedTypedVector())
733 {
734 uint8_t len = 0;
735 auto vtype = ToFixedTypedVectorElementType(type_, &len);
736 return FixedTypedVector(Indirect(), byte_width_, vtype, len);
737 }
738 else
739 {
741 }
742 }
static FixedTypedVector EmptyFixedTypedVector()
bool IsFixedTypedVector() const
Type ToFixedTypedVectorElementType(Type t, uint8_t *len)

References flexbuffers::FixedTypedVector::EmptyFixedTypedVector(), IsFixedTypedVector(), and flexbuffers::ToFixedTypedVectorElementType().

Referenced by As(), and ToString().

◆ AsFloat()

float flexbuffers::Reference::AsFloat ( ) const
inline

Definition at line 548 of file flexbuffers.h.

548{ return static_cast<float>(AsDouble()); }

References AsDouble().

Referenced by As().

◆ AsInt16()

int16_t flexbuffers::Reference::AsInt16 ( ) const
inline

Definition at line 469 of file flexbuffers.h.

469{ return static_cast<int16_t>(AsInt64()); }

References AsInt64().

Referenced by As().

◆ AsInt32()

int32_t flexbuffers::Reference::AsInt32 ( ) const
inline

Definition at line 468 of file flexbuffers.h.

468{ return static_cast<int32_t>(AsInt64()); }

References AsInt64().

Referenced by As().

◆ AsInt64()

int64_t flexbuffers::Reference::AsInt64 ( ) const
inline

Definition at line 432 of file flexbuffers.h.

433 {
434 if (type_ == FBT_INT)
435 {
436 // A fast path for the common case.
437 return ReadInt64(data_, parent_width_);
438 }
439 else
440 switch (type_)
441 {
442 case FBT_INDIRECT_INT:
443 return ReadInt64(Indirect(), byte_width_);
444 case FBT_UINT:
445 return ReadUInt64(data_, parent_width_);
447 return ReadUInt64(Indirect(), byte_width_);
448 case FBT_FLOAT:
449 return static_cast<int64_t>(ReadDouble(data_, parent_width_));
451 return static_cast<int64_t>(ReadDouble(Indirect(), byte_width_));
452 case FBT_NULL:
453 return 0;
454 case FBT_STRING:
455 return flatbuffers::StringToInt(AsString().c_str());
456 case FBT_VECTOR:
457 return static_cast<int64_t>(AsVector().size());
458 case FBT_BOOL:
459 return ReadInt64(data_, parent_width_);
460 default:
461 // Convert other things to int.
462 return 0;
463 }
464 }
int64_t StringToInt(const char *s, int base=10)
Definition util.h:435

References AsString(), AsVector(), flexbuffers::FBT_BOOL, flexbuffers::FBT_FLOAT, flexbuffers::FBT_INDIRECT_FLOAT, flexbuffers::FBT_INDIRECT_INT, flexbuffers::FBT_INDIRECT_UINT, flexbuffers::FBT_INT, flexbuffers::FBT_NULL, flexbuffers::FBT_STRING, flexbuffers::FBT_UINT, flexbuffers::FBT_VECTOR, flexbuffers::ReadDouble(), flexbuffers::ReadInt64(), flexbuffers::ReadUInt64(), flexbuffers::Sized::size(), and flatbuffers::StringToInt().

Referenced by As(), AsInt16(), AsInt32(), AsInt8(), and ToString().

◆ AsInt8()

int8_t flexbuffers::Reference::AsInt8 ( ) const
inline

Definition at line 470 of file flexbuffers.h.

470{ return static_cast<int8_t>(AsInt64()); }

References AsInt64().

Referenced by As().

◆ AsKey()

const char * flexbuffers::Reference::AsKey ( ) const
inline

Definition at line 550 of file flexbuffers.h.

551 {
552 if (type_ == FBT_KEY || type_ == FBT_STRING)
553 {
554 return reinterpret_cast<const char *>(Indirect());
555 }
556 else
557 {
558 return "";
559 }
560 }

References flexbuffers::FBT_KEY, and flexbuffers::FBT_STRING.

Referenced by ToString().

◆ AsMap()

Map flexbuffers::Reference::AsMap ( ) const
inline

Definition at line 744 of file flexbuffers.h.

745 {
746 if (type_ == FBT_MAP)
747 {
748 return Map(Indirect(), byte_width_);
749 }
750 else
751 {
752 return Map::EmptyMap();
753 }
754 }
static Map EmptyMap()

References flexbuffers::Map::EmptyMap(), and flexbuffers::FBT_MAP.

Referenced by As(), circledump::CustomOpPrinter::options(), tfldump::CustomOpPrinter::options(), and ToString().

◆ AsString()

String flexbuffers::Reference::AsString ( ) const
inline

Definition at line 564 of file flexbuffers.h.

565 {
566 if (type_ == FBT_STRING)
567 {
568 return String(Indirect(), byte_width_);
569 }
570 else if (type_ == FBT_KEY)
571 {
572 auto key = Indirect();
573 return String(key, byte_width_, strlen(reinterpret_cast<const char *>(key)));
574 }
575 else
576 {
577 return String::EmptyString();
578 }
579 }
static String EmptyString()

References flexbuffers::String::EmptyString(), flexbuffers::FBT_KEY, and flexbuffers::FBT_STRING.

Referenced by As(), AsDouble(), AsInt64(), AsUInt64(), and MutateString().

◆ AsTypedVector()

TypedVector flexbuffers::Reference::AsTypedVector ( ) const
inline

Definition at line 707 of file flexbuffers.h.

708 {
709 if (IsTypedVector())
710 {
711 auto tv = TypedVector(Indirect(), byte_width_, ToTypedVectorElementType(type_));
712 if (tv.type_ == FBT_STRING)
713 {
714 // These can't be accessed as strings, since we don't know the bit-width
715 // of the size field, see the declaration of
716 // FBT_VECTOR_STRING_DEPRECATED above for details.
717 // We change the type here to be keys, which are a subtype of strings,
718 // and will ignore the size field. This will truncate strings with
719 // embedded nulls.
720 tv.type_ = FBT_KEY;
721 }
722 return tv;
723 }
724 else
725 {
727 }
728 }
bool IsTypedVector() const
static TypedVector EmptyTypedVector()
Type ToTypedVectorElementType(Type t)

References flexbuffers::TypedVector::EmptyTypedVector(), flexbuffers::FBT_KEY, flexbuffers::FBT_STRING, IsTypedVector(), and flexbuffers::ToTypedVectorElementType().

Referenced by As(), and ToString().

◆ AsUInt16()

uint16_t flexbuffers::Reference::AsUInt16 ( ) const
inline

Definition at line 507 of file flexbuffers.h.

507{ return static_cast<uint16_t>(AsUInt64()); }

References AsUInt64().

Referenced by As().

◆ AsUInt32()

uint32_t flexbuffers::Reference::AsUInt32 ( ) const
inline

Definition at line 506 of file flexbuffers.h.

506{ return static_cast<uint32_t>(AsUInt64()); }

References AsUInt64().

Referenced by As().

◆ AsUInt64()

uint64_t flexbuffers::Reference::AsUInt64 ( ) const
inline

Definition at line 472 of file flexbuffers.h.

473 {
474 if (type_ == FBT_UINT)
475 {
476 // A fast path for the common case.
477 return ReadUInt64(data_, parent_width_);
478 }
479 else
480 switch (type_)
481 {
483 return ReadUInt64(Indirect(), byte_width_);
484 case FBT_INT:
485 return ReadInt64(data_, parent_width_);
486 case FBT_INDIRECT_INT:
487 return ReadInt64(Indirect(), byte_width_);
488 case FBT_FLOAT:
489 return static_cast<uint64_t>(ReadDouble(data_, parent_width_));
491 return static_cast<uint64_t>(ReadDouble(Indirect(), byte_width_));
492 case FBT_NULL:
493 return 0;
494 case FBT_STRING:
495 return flatbuffers::StringToUInt(AsString().c_str());
496 case FBT_VECTOR:
497 return static_cast<uint64_t>(AsVector().size());
498 case FBT_BOOL:
499 return ReadUInt64(data_, parent_width_);
500 default:
501 // Convert other things to uint.
502 return 0;
503 }
504 }
uint64_t StringToUInt(const char *s, int base=10)
Definition util.h:441

References AsString(), AsVector(), flexbuffers::FBT_BOOL, flexbuffers::FBT_FLOAT, flexbuffers::FBT_INDIRECT_FLOAT, flexbuffers::FBT_INDIRECT_INT, flexbuffers::FBT_INDIRECT_UINT, flexbuffers::FBT_INT, flexbuffers::FBT_NULL, flexbuffers::FBT_STRING, flexbuffers::FBT_UINT, flexbuffers::FBT_VECTOR, flexbuffers::ReadDouble(), flexbuffers::ReadInt64(), flexbuffers::ReadUInt64(), flexbuffers::Sized::size(), and flatbuffers::StringToUInt().

Referenced by As(), AsBool(), AsUInt16(), AsUInt32(), AsUInt8(), and ToString().

◆ AsUInt8()

uint8_t flexbuffers::Reference::AsUInt8 ( ) const
inline

Definition at line 508 of file flexbuffers.h.

508{ return static_cast<uint8_t>(AsUInt64()); }

References AsUInt64().

Referenced by As().

◆ AsVector()

Vector flexbuffers::Reference::AsVector ( ) const
inline

Definition at line 695 of file flexbuffers.h.

696 {
697 if (type_ == FBT_VECTOR || type_ == FBT_MAP)
698 {
699 return Vector(Indirect(), byte_width_);
700 }
701 else
702 {
703 return Vector::EmptyVector();
704 }
705 }

References flexbuffers::FBT_MAP, and flexbuffers::FBT_VECTOR.

Referenced by As(), AsDouble(), AsInt64(), AsUInt64(), and ToString().

◆ GetType()

Type flexbuffers::Reference::GetType ( ) const
inline

Definition at line 406 of file flexbuffers.h.

406{ return type_; }

◆ IsAnyVector()

bool flexbuffers::Reference::IsAnyVector ( ) const
inline

Definition at line 421 of file flexbuffers.h.

421{ return (IsTypedVector() || IsFixedTypedVector() || IsVector()); }

References IsFixedTypedVector(), IsTypedVector(), and IsVector().

◆ IsBlob()

bool flexbuffers::Reference::IsBlob ( ) const
inline

Definition at line 423 of file flexbuffers.h.

423{ return type_ == FBT_BLOB; }

References flexbuffers::FBT_BLOB.

Referenced by ToString().

◆ IsBool()

bool flexbuffers::Reference::IsBool ( ) const
inline

Definition at line 409 of file flexbuffers.h.

409{ return type_ == FBT_BOOL; }

References flexbuffers::FBT_BOOL.

Referenced by ToString().

◆ IsFixedTypedVector()

bool flexbuffers::Reference::IsFixedTypedVector ( ) const
inline

Definition at line 420 of file flexbuffers.h.

420{ return flexbuffers::IsFixedTypedVector(type_); }
bool IsFixedTypedVector(Type t)

References flexbuffers::IsFixedTypedVector().

Referenced by AsFixedTypedVector(), IsAnyVector(), and ToString().

◆ IsFloat()

bool flexbuffers::Reference::IsFloat ( ) const
inline

Definition at line 413 of file flexbuffers.h.

413{ return type_ == FBT_FLOAT || type_ == FBT_INDIRECT_FLOAT; }

References flexbuffers::FBT_FLOAT, and flexbuffers::FBT_INDIRECT_FLOAT.

Referenced by IsNumeric(), and ToString().

◆ IsInt()

bool flexbuffers::Reference::IsInt ( ) const
inline

Definition at line 410 of file flexbuffers.h.

410{ return type_ == FBT_INT || type_ == FBT_INDIRECT_INT; }

References flexbuffers::FBT_INDIRECT_INT, and flexbuffers::FBT_INT.

Referenced by IsIntOrUint(), and ToString().

◆ IsIntOrUint()

bool flexbuffers::Reference::IsIntOrUint ( ) const
inline

Definition at line 412 of file flexbuffers.h.

412{ return IsInt() || IsUInt(); }

References IsInt(), and IsUInt().

Referenced by IsNumeric().

◆ IsKey()

bool flexbuffers::Reference::IsKey ( ) const
inline

Definition at line 416 of file flexbuffers.h.

416{ return type_ == FBT_KEY; }

References flexbuffers::FBT_KEY.

Referenced by ToString().

◆ IsMap()

bool flexbuffers::Reference::IsMap ( ) const
inline

Definition at line 422 of file flexbuffers.h.

422{ return type_ == FBT_MAP; }

References flexbuffers::FBT_MAP.

Referenced by ToString().

◆ IsNull()

bool flexbuffers::Reference::IsNull ( ) const
inline

Definition at line 408 of file flexbuffers.h.

408{ return type_ == FBT_NULL; }

References flexbuffers::FBT_NULL.

Referenced by ToString().

◆ IsNumeric()

bool flexbuffers::Reference::IsNumeric ( ) const
inline

Definition at line 414 of file flexbuffers.h.

414{ return IsIntOrUint() || IsFloat(); }
bool IsIntOrUint() const

References IsFloat(), and IsIntOrUint().

◆ IsString()

bool flexbuffers::Reference::IsString ( ) const
inline

Definition at line 415 of file flexbuffers.h.

415{ return type_ == FBT_STRING; }

References flexbuffers::FBT_STRING.

◆ IsTypedVector()

bool flexbuffers::Reference::IsTypedVector ( ) const
inline

Definition at line 419 of file flexbuffers.h.

419{ return flexbuffers::IsTypedVector(type_); }
bool IsTypedVector(Type t)
Definition flexbuffers.h:96

References flexbuffers::IsTypedVector().

Referenced by AsTypedVector(), IsAnyVector(), and ToString().

◆ IsUInt()

bool flexbuffers::Reference::IsUInt ( ) const
inline

Definition at line 411 of file flexbuffers.h.

411{ return type_ == FBT_UINT || type_ == FBT_INDIRECT_UINT; }

References flexbuffers::FBT_INDIRECT_UINT, and flexbuffers::FBT_UINT.

Referenced by IsIntOrUint(), and ToString().

◆ IsUntypedVector()

bool flexbuffers::Reference::IsUntypedVector ( ) const
inline

Definition at line 418 of file flexbuffers.h.

418{ return type_ == FBT_VECTOR; }

References flexbuffers::FBT_VECTOR.

◆ IsVector()

bool flexbuffers::Reference::IsVector ( ) const
inline

Definition at line 417 of file flexbuffers.h.

417{ return type_ == FBT_VECTOR || type_ == FBT_MAP; }

References flexbuffers::FBT_MAP, and flexbuffers::FBT_VECTOR.

Referenced by IsAnyVector(), and ToString().

◆ MutateBool()

bool flexbuffers::Reference::MutateBool ( bool  b)
inline

Definition at line 790 of file flexbuffers.h.

791 {
792 return type_ == FBT_BOOL && Mutate(data_, b, parent_width_, BIT_WIDTH_8);
793 }

References flexbuffers::BIT_WIDTH_8, and flexbuffers::FBT_BOOL.

◆ MutateFloat() [1/2]

bool flexbuffers::Reference::MutateFloat ( double  d)
inline

Definition at line 837 of file flexbuffers.h.

838 {
839 if (type_ == FBT_FLOAT)
840 {
841 return MutateF(data_, d, parent_width_, WidthF(d));
842 }
843 else if (type_ == FBT_INDIRECT_FLOAT)
844 {
845 return MutateF(Indirect(), d, byte_width_, WidthF(d));
846 }
847 else
848 {
849 return false;
850 }
851 }
BitWidth WidthF(double f)

References flexbuffers::FBT_FLOAT, flexbuffers::FBT_INDIRECT_FLOAT, and flexbuffers::WidthF().

◆ MutateFloat() [2/2]

bool flexbuffers::Reference::MutateFloat ( float  f)
inline

Definition at line 821 of file flexbuffers.h.

822 {
823 if (type_ == FBT_FLOAT)
824 {
825 return MutateF(data_, f, parent_width_, BIT_WIDTH_32);
826 }
827 else if (type_ == FBT_INDIRECT_FLOAT)
828 {
829 return MutateF(Indirect(), f, byte_width_, BIT_WIDTH_32);
830 }
831 else
832 {
833 return false;
834 }
835 }

References flexbuffers::BIT_WIDTH_32, flexbuffers::FBT_FLOAT, and flexbuffers::FBT_INDIRECT_FLOAT.

◆ MutateInt()

bool flexbuffers::Reference::MutateInt ( int64_t  i)
inline

Definition at line 764 of file flexbuffers.h.

765 {
766 if (type_ == FBT_INT)
767 {
768 return Mutate(data_, i, parent_width_, WidthI(i));
769 }
770 else if (type_ == FBT_INDIRECT_INT)
771 {
772 return Mutate(Indirect(), i, byte_width_, WidthI(i));
773 }
774 else if (type_ == FBT_UINT)
775 {
776 auto u = static_cast<uint64_t>(i);
777 return Mutate(data_, u, parent_width_, WidthU(u));
778 }
779 else if (type_ == FBT_INDIRECT_UINT)
780 {
781 auto u = static_cast<uint64_t>(i);
782 return Mutate(Indirect(), u, byte_width_, WidthU(u));
783 }
784 else
785 {
786 return false;
787 }
788 }
BitWidth WidthI(int64_t i)
BitWidth WidthU(uint64_t u)

References flexbuffers::FBT_INDIRECT_INT, flexbuffers::FBT_INDIRECT_UINT, flexbuffers::FBT_INT, flexbuffers::FBT_UINT, flexbuffers::WidthI(), and flexbuffers::WidthU().

◆ MutateString() [1/3]

bool flexbuffers::Reference::MutateString ( const char *  str)
inline

Definition at line 865 of file flexbuffers.h.

865{ return MutateString(str, strlen(str)); }
bool MutateString(const char *str, size_t len)

References MutateString().

Referenced by MutateString().

◆ MutateString() [2/3]

bool flexbuffers::Reference::MutateString ( const char *  str,
size_t  len 
)
inline

Definition at line 853 of file flexbuffers.h.

854 {
855 auto s = AsString();
856 if (s.IsTheEmptyString())
857 return false;
858 // This is very strict, could allow shorter strings, but that creates
859 // garbage.
860 if (s.length() != len)
861 return false;
862 memcpy(const_cast<char *>(s.c_str()), str, len);
863 return true;
864 }

References AsString().

◆ MutateString() [3/3]

bool flexbuffers::Reference::MutateString ( const std::string &  str)
inline

Definition at line 866 of file flexbuffers.h.

866{ return MutateString(str.data(), str.length()); }
str
Definition infer.py:18

References MutateString().

Referenced by MutateString().

◆ MutateUInt()

bool flexbuffers::Reference::MutateUInt ( uint64_t  u)
inline

Definition at line 795 of file flexbuffers.h.

796 {
797 if (type_ == FBT_UINT)
798 {
799 return Mutate(data_, u, parent_width_, WidthU(u));
800 }
801 else if (type_ == FBT_INDIRECT_UINT)
802 {
803 return Mutate(Indirect(), u, byte_width_, WidthU(u));
804 }
805 else if (type_ == FBT_INT)
806 {
807 auto i = static_cast<int64_t>(u);
808 return Mutate(data_, i, parent_width_, WidthI(i));
809 }
810 else if (type_ == FBT_INDIRECT_INT)
811 {
812 auto i = static_cast<int64_t>(u);
813 return Mutate(Indirect(), i, byte_width_, WidthI(i));
814 }
815 else
816 {
817 return false;
818 }
819 }

References flexbuffers::FBT_INDIRECT_INT, flexbuffers::FBT_INDIRECT_UINT, flexbuffers::FBT_INT, flexbuffers::FBT_UINT, flexbuffers::WidthI(), and flexbuffers::WidthU().

◆ ToString() [1/2]

std::string flexbuffers::Reference::ToString ( ) const
inline

Definition at line 582 of file flexbuffers.h.

583 {
584 std::string s;
585 ToString(false, false, s);
586 return s;
587 }
std::string ToString() const

References ToString().

Referenced by ToString().

◆ ToString() [2/2]

void flexbuffers::Reference::ToString ( bool  strings_quoted,
bool  keys_quoted,
std::string &  s 
) const
inline

Definition at line 593 of file flexbuffers.h.

594 {
595 if (type_ == FBT_STRING)
596 {
597 String str(Indirect(), byte_width_);
598 if (strings_quoted)
599 {
600 flatbuffers::EscapeString(str.c_str(), str.length(), &s, true, false);
601 }
602 else
603 {
604 s.append(str.c_str(), str.length());
605 }
606 }
607 else if (IsKey())
608 {
609 auto str = AsKey();
610 if (keys_quoted)
611 {
612 flatbuffers::EscapeString(str, strlen(str), &s, true, false);
613 }
614 else
615 {
616 s += str;
617 }
618 }
619 else if (IsInt())
620 {
622 }
623 else if (IsUInt())
624 {
626 }
627 else if (IsFloat())
628 {
630 }
631 else if (IsNull())
632 {
633 s += "null";
634 }
635 else if (IsBool())
636 {
637 s += AsBool() ? "true" : "false";
638 }
639 else if (IsMap())
640 {
641 s += "{ ";
642 auto m = AsMap();
643 auto keys = m.Keys();
644 auto vals = m.Values();
645 for (size_t i = 0; i < keys.size(); i++)
646 {
647 keys[i].ToString(true, keys_quoted, s);
648 s += ": ";
649 vals[i].ToString(true, keys_quoted, s);
650 if (i < keys.size() - 1)
651 s += ", ";
652 }
653 s += " }";
654 }
655 else if (IsVector())
656 {
657 AppendToString<Vector>(s, AsVector(), keys_quoted);
658 }
659 else if (IsTypedVector())
660 {
661 AppendToString<TypedVector>(s, AsTypedVector(), keys_quoted);
662 }
663 else if (IsFixedTypedVector())
664 {
665 AppendToString<FixedTypedVector>(s, AsFixedTypedVector(), keys_quoted);
666 }
667 else if (IsBlob())
668 {
669 auto blob = AsBlob();
670 flatbuffers::EscapeString(reinterpret_cast<const char *>(blob.data()), blob.size(), &s, true,
671 false);
672 }
673 else
674 {
675 s += "(?)";
676 }
677 }
const char * AsKey() const
std::string NumToString(T t)
Definition util.h:139
bool EscapeString(const char *s, size_t length, std::string *_text, bool allow_non_utf8, bool natural_utf8)
Definition util.h:652

References AsBlob(), AsBool(), AsDouble(), AsFixedTypedVector(), AsInt64(), AsKey(), AsMap(), AsTypedVector(), AsUInt64(), AsVector(), flatbuffers::EscapeString(), flexbuffers::FBT_STRING, IsBlob(), IsBool(), IsFixedTypedVector(), IsFloat(), IsInt(), IsKey(), IsMap(), IsNull(), IsTypedVector(), IsUInt(), IsVector(), m, and flatbuffers::NumToString().


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