proxygen
folly::dynamic Struct Reference

#include <dynamic.h>

Inheritance diagram for folly::dynamic:

Classes

struct  CompareOp
 
struct  CompareOp< dynamic::ObjectImpl >
 
struct  CompareOp< std::nullptr_t >
 
struct  const_item_iterator
 
struct  const_key_iterator
 
struct  const_value_iterator
 
union  Data
 
struct  EmptyArrayTag
 
struct  GetAddrImpl
 
struct  GetAddrImpl< bool >
 
struct  GetAddrImpl< double >
 
struct  GetAddrImpl< dynamic::Array >
 
struct  GetAddrImpl< dynamic::ObjectImpl >
 
struct  GetAddrImpl< int64_t >
 
struct  GetAddrImpl< std::nullptr_t >
 
struct  GetAddrImpl< std::string >
 
struct  item_iterator
 
struct  IterableProxy
 
struct  NumericTypeHelper
 
struct  NumericTypeHelper< bool >
 
struct  NumericTypeHelper< double >
 
struct  NumericTypeHelper< float >
 
struct  NumericTypeHelper< T, typename std::enable_if< std::is_integral< T >::value >::type >
 
struct  ObjectImpl
 
struct  ObjectMaker
 
struct  PrintImpl
 
struct  PrintImpl< dynamic::Array >
 
struct  PrintImpl< dynamic::ObjectImpl >
 
struct  PrintImpl< std::nullptr_t >
 
struct  TypeInfo
 
struct  TypeInfo< bool >
 
struct  TypeInfo< double >
 
struct  TypeInfo< dynamic::Array >
 
struct  TypeInfo< dynamic::ObjectImpl >
 
struct  TypeInfo< int64_t >
 
struct  TypeInfo< std::nullptr_t >
 
struct  TypeInfo< std::string >
 
struct  value_iterator
 
struct  VectorBoolConstRefFake
 

Public Types

enum  Type {
  NULLT, ARRAY, BOOL, DOUBLE,
  INT64, OBJECT, STRING
}
 
typedef Array::iterator iterator
 
typedef Array::const_iterator const_iterator
 
typedef dynamic value_type
 

Public Member Functions

 dynamic ()
 
 dynamic (std::nullptr_t)
 
 dynamic (StringPiece val)
 
 dynamic (char const *val)
 
 dynamic (std::string val)
 
 dynamic (void(*)(EmptyArrayTag))
 
 dynamic (ObjectMaker(*)())
 
 dynamic (ObjectMaker const &)=delete
 
 dynamic (ObjectMaker &&)
 
template<class T , class NumericType = typename NumericTypeHelper<T>::type>
 dynamic (T t)
 
 dynamic (std::vector< bool >::reference val)
 
 dynamic (VectorBoolConstRefCtorType val)
 
template<class Iterator >
 dynamic (Iterator first, Iterator last)
 
 dynamic (dynamic const &)
 
 dynamic (dynamic &&) noexcept
 
 ~dynamic () noexcept
 
bool operator== (dynamic const &o) const
 
bool operator< (dynamic const &o) const
 
dynamicoperator+= (dynamic const &)
 
dynamicoperator-= (dynamic const &)
 
dynamicoperator*= (dynamic const &)
 
dynamicoperator/= (dynamic const &)
 
dynamicoperator%= (dynamic const &)
 
dynamicoperator|= (dynamic const &)
 
dynamicoperator&= (dynamic const &)
 
dynamicoperator^= (dynamic const &)
 
dynamicoperator++ ()
 
dynamicoperator-- ()
 
dynamicoperator= (dynamic const &)
 
dynamicoperator= (dynamic &&) noexcept
 
bool isString () const
 
bool isObject () const
 
bool isBool () const
 
bool isNull () const
 
bool isArray () const
 
bool isDouble () const
 
bool isInt () const
 
bool isNumber () const
 
Type type () const
 
const char * typeName () const
 
std::string asString () const
 
double asDouble () const
 
int64_t asInt () const
 
bool asBool () const
 
const std::stringgetString () const &
 
double getDouble () const &
 
int64_t getInt () const &
 
bool getBool () const &
 
std::stringgetString ()&
 
double & getDouble ()&
 
int64_tgetInt ()&
 
bool & getBool ()&
 
std::string && getString ()&&
 
double getDouble ()&&
 
int64_t getInt ()&&
 
bool getBool ()&&
 
const char * data () const &
 
const char * data ()&&=delete
 
const char * c_str () const &
 
const char * c_str ()&&=delete
 
StringPiece stringPiece () const
 
bool empty () const
 
std::size_t size () const
 
const_iterator begin () const
 
const_iterator end () const
 
iterator begin ()
 
iterator end ()
 
IterableProxy< const_key_iteratorkeys () const
 
IterableProxy< const_value_iteratorvalues () const
 
IterableProxy< const_item_iteratoritems () const
 
IterableProxy< value_iteratorvalues ()
 
IterableProxy< item_iteratoritems ()
 
template<typename K >
IfIsNonStringDynamicConvertible< K, const_item_iteratorfind (K &&) const
 
template<typename K >
IfIsNonStringDynamicConvertible< K, item_iteratorfind (K &&)
 
const_item_iterator find (StringPiece) const
 
item_iterator find (StringPiece)
 
template<typename K >
IfIsNonStringDynamicConvertible< K, std::size_t > count (K &&) const
 
std::size_t count (StringPiece) const
 
template<typename K >
IfIsNonStringDynamicConvertible< K, dynamic const & > at (K &&) const &
 
template<typename K >
IfIsNonStringDynamicConvertible< K, dynamic & > at (K &&)&
 
template<typename K >
IfIsNonStringDynamicConvertible< K, dynamic && > at (K &&)&&
 
dynamic const & at (StringPiece) const &
 
dynamicat (StringPiece)&
 
dynamic && at (StringPiece)&&
 
const dynamicget_ptr (json_pointer const &) const &
 
dynamicget_ptr (json_pointer const &)&
 
const dynamicget_ptr (json_pointer const &) const &&=delete
 
dynamicget_ptr (json_pointer const &)&&=delete
 
template<typename K >
IfIsNonStringDynamicConvertible< K, const dynamic * > get_ptr (K &&) const &
 
template<typename K >
IfIsNonStringDynamicConvertible< K, dynamic * > get_ptr (K &&)&
 
template<typename K >
IfIsNonStringDynamicConvertible< K, dynamic * > get_ptr (K &&)&&=delete
 
const dynamicget_ptr (StringPiece) const &
 
dynamicget_ptr (StringPiece)&
 
dynamicget_ptr (StringPiece)&&=delete
 
template<typename K >
IfIsNonStringDynamicConvertible< K, dynamic & > operator[] (K &&)&
 
template<typename K >
IfIsNonStringDynamicConvertible< K, dynamic const & > operator[] (K &&) const &
 
template<typename K >
IfIsNonStringDynamicConvertible< K, dynamic && > operator[] (K &&)&&
 
dynamicoperator[] (StringPiece)&
 
dynamic const & operator[] (StringPiece) const &
 
dynamic && operator[] (StringPiece)&&
 
template<typename K >
IfIsNonStringDynamicConvertible< K, dynamicgetDefault (K &&k, const dynamic &v=dynamic::object) const &
 
template<typename K >
IfIsNonStringDynamicConvertible< K, dynamicgetDefault (K &&k, dynamic &&v) const &
 
template<typename K >
IfIsNonStringDynamicConvertible< K, dynamicgetDefault (K &&k, const dynamic &v=dynamic::object)&&
 
template<typename K >
IfIsNonStringDynamicConvertible< K, dynamicgetDefault (K &&k, dynamic &&v)&&
 
dynamic getDefault (StringPiece k, const dynamic &v=dynamic::object) const &
 
dynamic getDefault (StringPiece k, dynamic &&v) const &
 
dynamic getDefault (StringPiece k, const dynamic &v=dynamic::object)&&
 
dynamic getDefault (StringPiece k, dynamic &&v)&&
 
template<typename K , typename V >
IfIsNonStringDynamicConvertible< K, dynamic & > setDefault (K &&k, V &&v)
 
template<typename V >
dynamicsetDefault (StringPiece k, V &&v)
 
template<typename K >
IfIsNonStringDynamicConvertible< K, dynamic & > setDefault (K &&k, dynamic &&v)
 
template<typename K >
IfIsNonStringDynamicConvertible< K, dynamic & > setDefault (K &&k, const dynamic &v=dynamic::object)
 
dynamicsetDefault (StringPiece k, dynamic &&v)
 
dynamicsetDefault (StringPiece k, const dynamic &v=dynamic::object)
 
void resize (std::size_t n, dynamic const &=nullptr)
 
template<class K , class V >
void insert (K &&, V &&val)
 
void update (const dynamic &mergeObj)
 
void update_missing (const dynamic &other)
 
void merge_patch (const dynamic &patch)
 
template<typename K >
IfIsNonStringDynamicConvertible< K, std::size_t > erase (K &&)
 
std::size_t erase (StringPiece)
 
iterator erase (const_iterator it)
 
iterator erase (const_iterator first, const_iterator last)
 
const_key_iterator erase (const_key_iterator it)
 
const_key_iterator erase (const_key_iterator first, const_key_iterator last)
 
value_iterator erase (const_value_iterator it)
 
value_iterator erase (const_value_iterator first, const_value_iterator last)
 
item_iterator erase (const_item_iterator it)
 
item_iterator erase (const_item_iterator first, const_item_iterator last)
 
void push_back (dynamic const &)
 
void push_back (dynamic &&)
 
void pop_back ()
 
std::size_t hash () const
 
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, dynamic const * > get_ptr (K &&k) const &
 

Static Public Member Functions

static void array (EmptyArrayTag)
 
template<class... Args>
static dynamic array (Args &&...args)
 
static ObjectMaker object ()
 
static ObjectMaker object (dynamic, dynamic)
 
static dynamic merge (const dynamic &mergeObj1, const dynamic &mergeObj2)
 
static dynamic merge_diff (const dynamic &source, const dynamic &target)
 

Private Types

typedef std::vector< dynamicArray
 
using VectorBoolConstRefCtorType = std::conditional_t< std::is_same< std::vector< bool >::const_reference, bool >::value, VectorBoolConstRefFake, std::vector< bool >::const_reference >
 
template<typename K , typename T >
using IfIsNonStringDynamicConvertible = std::enable_if_t< !std::is_convertible< K, StringPiece >::value &&std::is_convertible< K, dynamic >::value, T >
 

Private Member Functions

dynamic const & atImpl (dynamic const &) const &
 
const dynamicget_ptrImpl (dynamic const &) const &
 
 dynamic (Array &&array)
 
template<class T >
T const & get () const
 
template<class T >
Tget ()
 
template<class T >
Tget_nothrow ()&noexcept
 
template<class T >
T const * get_nothrow () const &noexcept
 
template<class T >
Tget_nothrow ()&&noexcept=delete
 
template<class T >
TgetAddress () noexcept
 
template<class T >
T const * getAddress () const noexcept
 
template<class T >
T asImpl () const
 
void destroy () noexcept
 
void print (std::ostream &) const
 
void print_as_pseudo_json (std::ostream &) const
 

Static Private Member Functions

static char const * typeName (Type)
 

Private Attributes

Type type_
 
union folly::dynamic::Data u_
 

Friends

struct TypeError
 
std::ostream & operator<< (std::ostream &, dynamic const &)
 

Detailed Description

Definition at line 79 of file dynamic.h.

Member Typedef Documentation

typedef std::vector<dynamic> folly::dynamic::Array
private

Definition at line 90 of file dynamic.h.

typedef Array::const_iterator folly::dynamic::const_iterator

Definition at line 119 of file dynamic.h.

template<typename K , typename T >
using folly::dynamic::IfIsNonStringDynamicConvertible = std::enable_if_t< !std::is_convertible<K, StringPiece>::value && std::is_convertible<K, dynamic>::value, T>
private

Definition at line 371 of file dynamic.h.

typedef Array::iterator folly::dynamic::iterator

Definition at line 118 of file dynamic.h.

Definition at line 120 of file dynamic.h.

using folly::dynamic::VectorBoolConstRefCtorType = std::conditional_t< std::is_same<std::vector<bool>::const_reference, bool>::value, VectorBoolConstRefFake, std::vector<bool>::const_reference>
private

Definition at line 115 of file dynamic.h.

Member Enumeration Documentation

Enumerator
NULLT 
ARRAY 
BOOL 
DOUBLE 
INT64 
OBJECT 
STRING 

Definition at line 80 of file dynamic.h.

Constructor & Destructor Documentation

folly::dynamic::dynamic ( )
inline

Default constructor, initializes with nullptr.

Definition at line 348 of file dynamic-inl.h.

348 : dynamic(nullptr) {}
folly::dynamic::dynamic ( std::nullptr_t  )
inline

Definition at line 350 of file dynamic-inl.h.

folly::dynamic::dynamic ( StringPiece  val)
inline

Definition at line 360 of file dynamic-inl.h.

References folly::Range< Iter >::data(), folly::Range< Iter >::size(), string, folly::dynamic::Data::string, and u_.

360  : type_(STRING) {
361  new (&u_.string) std::string(s.data(), s.size());
362 }
union folly::dynamic::Data u_
std::string string
Definition: dynamic.h:698
const char * string
Definition: Conv.cpp:212
static set< string > s
folly::dynamic::dynamic ( char const *  val)
inline

Definition at line 364 of file dynamic-inl.h.

References string, folly::dynamic::Data::string, and u_.

364  : type_(STRING) {
365  new (&u_.string) std::string(s);
366 }
union folly::dynamic::Data u_
std::string string
Definition: dynamic.h:698
const char * string
Definition: Conv.cpp:212
static set< string > s
folly::dynamic::dynamic ( std::string  val)
inline

Definition at line 368 of file dynamic-inl.h.

References folly::gen::move, string, folly::dynamic::Data::string, and u_.

368  : type_(STRING) {
369  new (&u_.string) std::string(std::move(s));
370 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
union folly::dynamic::Data u_
std::string string
Definition: dynamic.h:698
const char * string
Definition: Conv.cpp:212
static set< string > s
folly::dynamic::dynamic ( void(*)(EmptyArrayTag )
inline

Definition at line 352 of file dynamic-inl.h.

References folly::dynamic::Data::array, and u_.

352  : type_(ARRAY) {
353  new (&u_.array) Array();
354 }
std::vector< dynamic > Array
Definition: dynamic.h:90
union folly::dynamic::Data u_
folly::dynamic::dynamic ( ObjectMaker(*)()  )
inline

Definition at line 356 of file dynamic-inl.h.

356  : type_(OBJECT) {
357  new (getAddress<ObjectImpl>()) ObjectImpl();
358 }
folly::dynamic::dynamic ( ObjectMaker const &  )
delete
folly::dynamic::dynamic ( ObjectMaker &&  maker)
inline

Definition at line 372 of file dynamic-inl.h.

References folly::gen::move.

372  : type_(OBJECT) {
373  new (getAddress<ObjectImpl>())
374  ObjectImpl(std::move(*maker.val_.getAddress<ObjectImpl>()));
375 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T , class NumericType >
folly::dynamic::dynamic ( T  t)

Definition at line 420 of file dynamic-inl.h.

References type_.

420  {
422  new (getAddress<NumericType>()) NumericType(NumericType(t));
423 }
PskType type
folly::dynamic::dynamic ( std::vector< bool >::reference  val)
inline

Definition at line 412 of file dynamic-inl.h.

413  : dynamic(static_cast<bool>(b)) {}
char b
folly::dynamic::dynamic ( VectorBoolConstRefCtorType  val)
inline

Definition at line 414 of file dynamic-inl.h.

References folly::T.

415  : dynamic(static_cast<bool>(b)) {}
char b
template<class Iterator >
folly::dynamic::dynamic ( Iterator  first,
Iterator  last 
)
explicit

Definition at line 426 of file dynamic-inl.h.

References folly::dynamic::Data::array, and u_.

426  : type_(ARRAY) {
427  new (&u_.array) Array(first, last);
428 }
std::vector< dynamic > Array
Definition: dynamic.h:90
union folly::dynamic::Data u_
constexpr detail::First first
Definition: Base-inl.h:2553
folly::dynamic::dynamic ( dynamic const &  o)
inline

Definition at line 377 of file dynamic-inl.h.

377  : type_(NULLT) {
378  *this = o;
379 }
folly::dynamic::dynamic ( dynamic &&  o)
inlinenoexcept

Definition at line 381 of file dynamic-inl.h.

References folly::gen::move.

381  : type_(NULLT) {
382  *this = std::move(o);
383 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::dynamic::~dynamic ( )
inlinenoexcept

Definition at line 385 of file dynamic-inl.h.

References destroy().

385  {
386  destroy();
387 }
void destroy() noexcept
Definition: dynamic.cpp:330
folly::dynamic::dynamic ( Array &&  array)
inlineexplicitprivate

Definition at line 986 of file dynamic-inl.h.

References folly::dynamic::Data::array, folly::gen::move, and u_.

986  : type_(ARRAY) {
987  new (&u_.array) Array(std::move(r));
988 }
std::vector< dynamic > Array
Definition: dynamic.h:90
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
union folly::dynamic::Data u_

Member Function Documentation

template<class... Args>
dynamic folly::dynamic::array ( Args &&...  args)
inlinestatic

Definition at line 236 of file dynamic-inl.h.

236  {
237  return dynamic(Array{std::forward<Args>(args)...});
238 }
std::vector< dynamic > Array
Definition: dynamic.h:90
bool folly::dynamic::asBool ( ) const
inline

Definition at line 527 of file dynamic-inl.h.

Referenced by folly::compareDynamicWithTolerance(), folly::DynamicConverter< bool >::convert(), folly::detail::invokeForKeyValue(), and TEST().

527  {
528  return asImpl<bool>();
529 }
double folly::dynamic::asDouble ( ) const
inline
template<class T >
T folly::dynamic::asImpl ( ) const
private

Definition at line 1009 of file dynamic-inl.h.

References BOOL, DOUBLE, INT64, STRING, and type().

1009  {
1010  switch (type()) {
1011  case INT64:
1012  return to<T>(*get_nothrow<int64_t>());
1013  case DOUBLE:
1014  return to<T>(*get_nothrow<double>());
1015  case BOOL:
1016  return to<T>(*get_nothrow<bool>());
1017  case STRING:
1018  return to<T>(*get_nothrow<std::string>());
1019  default:
1020  throw_exception<TypeError>("int/double/bool/string", type());
1021  }
1022 }
Type type() const
Definition: dynamic-inl.h:514
std::string folly::dynamic::asString ( ) const
inline
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, dynamic const & > folly::dynamic::at ( K &&  k) const

Definition at line 792 of file dynamic-inl.h.

References atImpl(), and k.

Referenced by at(), checkItemParseError(), checkMaybeCoercedKeys(), checkXYKeyErrorsAndParseError(), operator[](), and TEST().

793  {
794  return atImpl(std::forward<K>(k));
795 }
dynamic const & atImpl(dynamic const &) const &
Definition: dynamic.cpp:169
KeyT k
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, dynamic & > folly::dynamic::at ( K &&  idx)

Definition at line 798 of file dynamic-inl.h.

References at(), and upload::const.

798  {
799  return const_cast<dynamic&>(const_cast<dynamic const*>(this)->at(idx));
800 }
const
Definition: upload.py:398
IfIsNonStringDynamicConvertible< K, dynamic const & > at(K &&) const &
Definition: dynamic-inl.h:792
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, dynamic && > folly::dynamic::at ( K &&  idx)

Definition at line 803 of file dynamic-inl.h.

References at(), and folly::gen::move.

803  {
804  return std::move(at(idx));
805 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
IfIsNonStringDynamicConvertible< K, dynamic const & > at(K &&) const &
Definition: dynamic-inl.h:792
dynamic const & folly::dynamic::at ( StringPiece  idx) const

Definition at line 190 of file dynamic.cpp.

References k, operator[](), folly::sformat(), and type.

190  {
191  auto* pobject = get_nothrow<ObjectImpl>();
192  if (!pobject) {
193  throw_exception<TypeError>("object", type());
194  }
195  auto it = pobject->find(idx);
196  if (it == pobject->end()) {
197  throw_exception<std::out_of_range>(
198  sformat("couldn't find key {} in dynamic object", idx));
199  }
200  return it->second;
201 }
std::string sformat(StringPiece fmt, Args &&...args)
Definition: Format.h:280
Type type() const
Definition: dynamic-inl.h:514
dynamic && folly::dynamic::at ( StringPiece  idx)
inline

Definition at line 807 of file dynamic-inl.h.

References at(), upload::const, and folly::gen::move.

807  {
808  return const_cast<dynamic&>(const_cast<dynamic const*>(this)->at(idx));
809 }
const
Definition: upload.py:398
IfIsNonStringDynamicConvertible< K, dynamic const & > at(K &&) const &
Definition: dynamic-inl.h:792
dynamic&& folly::dynamic::at ( StringPiece  )
dynamic const & folly::dynamic::atImpl ( dynamic const &  idx) const
private

Definition at line 169 of file dynamic.cpp.

References find(), folly::sformat(), and type.

Referenced by at().

169  {
170  if (auto* parray = get_nothrow<Array>()) {
171  if (!idx.isInt()) {
172  throw_exception<TypeError>("int64", idx.type());
173  }
174  if (idx < 0 || idx >= parray->size()) {
175  throw_exception<std::out_of_range>("out of range in dynamic array");
176  }
177  return (*parray)[size_t(idx.asInt())];
178  } else if (auto* pobject = get_nothrow<ObjectImpl>()) {
179  auto it = pobject->find(idx);
180  if (it == pobject->end()) {
181  throw_exception<std::out_of_range>(
182  sformat("couldn't find key {} in dynamic object", idx.asString()));
183  }
184  return it->second;
185  } else {
186  throw_exception<TypeError>("object/array", type());
187  }
188 }
std::string sformat(StringPiece fmt, Args &&...args)
Definition: Format.h:280
Type type() const
Definition: dynamic-inl.h:514
dynamic::iterator folly::dynamic::begin ( )
inline

Definition at line 439 of file dynamic-inl.h.

References begin().

439  {
440  return get<Array>().begin();
441 }
const_iterator begin() const
Definition: dynamic-inl.h:432
const char * folly::dynamic::c_str ( ) const
inline

Definition at line 573 of file dynamic-inl.h.

Referenced by TEST().

573  {
574  return get<std::string>().c_str();
575 }
const char * c_str() const &
Definition: dynamic-inl.h:573
const char* folly::dynamic::c_str ( )
delete
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, std::size_t > folly::dynamic::count ( K &&  key) const

Definition at line 843 of file dynamic-inl.h.

References find(), and items().

Referenced by wangle::TLSCredProcessor::processTLSTickets(), and TEST().

844  {
845  return find(std::forward<K>(key)) != items().end() ? 1u : 0u;
846 }
IfIsNonStringDynamicConvertible< K, const_item_iterator > find(K &&) const
Definition: dynamic-inl.h:824
IterableProxy< const_item_iterator > items() const
Definition: dynamic-inl.h:476
std::size_t folly::dynamic::count ( StringPiece  key) const
inline

Definition at line 848 of file dynamic-inl.h.

References find(), and items().

848  {
849  return find(key) != items().end() ? 1u : 0u;
850 }
IfIsNonStringDynamicConvertible< K, const_item_iterator > find(K &&) const
Definition: dynamic-inl.h:824
IterableProxy< const_item_iterator > items() const
Definition: dynamic-inl.h:476
const char * folly::dynamic::data ( ) const
inline

Definition at line 570 of file dynamic-inl.h.

Referenced by folly::dynamic::GetAddrImpl< dynamic::ObjectImpl >::get(), and TEST().

570  {
571  return get<std::string>().data();
572 }
const char * data() const &
Definition: dynamic-inl.h:570
const char* folly::dynamic::data ( )
delete
void folly::dynamic::destroy ( )
privatenoexcept

Definition at line 330 of file dynamic.cpp.

References FB_DYNAMIC_APPLY, FB_X, and type_.

Referenced by ~dynamic().

330  {
331  // This short-circuit speeds up some microbenchmarks.
332  if (type_ == NULLT) {
333  return;
334  }
335 
336 #define FB_X(T) detail::Destroy::destroy(getAddress<T>())
338 #undef FB_X
339  type_ = NULLT;
340  u_.nul = nullptr;
341 }
#define FB_DYNAMIC_APPLY(type, apply)
Definition: dynamic.cpp:77
#define FB_X(T)
union folly::dynamic::Data u_
std::nullptr_t nul
Definition: dynamic.h:693
bool folly::dynamic::empty ( ) const
inline

Definition at line 815 of file dynamic-inl.h.

References isNull(), and size().

Referenced by TEST().

815  {
816  if (isNull()) {
817  return true;
818  }
819  return !size();
820 }
bool isNull() const
Definition: dynamic-inl.h:507
std::size_t size() const
Definition: dynamic.cpp:275
dynamic::iterator folly::dynamic::end ( )
inline

Definition at line 442 of file dynamic-inl.h.

References end().

442  {
443  return get<Array>().end();
444 }
const_iterator end() const
Definition: dynamic-inl.h:435
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, std::size_t > folly::dynamic::erase ( K &&  key)

Definition at line 916 of file dynamic-inl.h.

Referenced by erase(), and TEST().

917  {
918  auto& obj = get<ObjectImpl>();
919  return obj.erase(std::forward<K>(key));
920 }
std::size_t folly::dynamic::erase ( StringPiece  key)
inline

Definition at line 921 of file dynamic-inl.h.

921  {
922  auto& obj = get<ObjectImpl>();
923  return obj.erase(key);
924 }
dynamic::iterator folly::dynamic::erase ( const_iterator  it)
inline

Definition at line 926 of file dynamic-inl.h.

References erase().

926  {
927  auto& arr = get<Array>();
928  // std::vector doesn't have an erase method that works on const iterators,
929  // even though the standard says it should, so this hack converts to a
930  // non-const iterator before calling erase.
931  return get<Array>().erase(arr.begin() + (it - arr.begin()));
932 }
IfIsNonStringDynamicConvertible< K, std::size_t > erase(K &&)
Definition: dynamic-inl.h:916
dynamic::iterator folly::dynamic::erase ( const_iterator  first,
const_iterator  last 
)

Definition at line 288 of file dynamic.cpp.

288  {
289  auto& arr = get<Array>();
290  return get<Array>().erase(
291  arr.begin() + (first - arr.begin()), arr.begin() + (last - arr.begin()));
292 }
IfIsNonStringDynamicConvertible< K, std::size_t > erase(K &&)
Definition: dynamic-inl.h:916
constexpr detail::First first
Definition: Base-inl.h:2553
dynamic::const_key_iterator folly::dynamic::erase ( const_key_iterator  it)
inline

Definition at line 934 of file dynamic-inl.h.

References folly::detail::IteratorAdaptor< D, I, V, Tag >::base(), and erase().

934  {
935  return const_key_iterator(get<ObjectImpl>().erase(it.base()));
936 }
IfIsNonStringDynamicConvertible< K, std::size_t > erase(K &&)
Definition: dynamic-inl.h:916
dynamic::const_key_iterator folly::dynamic::erase ( const_key_iterator  first,
const_key_iterator  last 
)
inline

Definition at line 938 of file dynamic-inl.h.

References folly::detail::IteratorAdaptor< D, I, V, Tag >::base(), and erase().

940  {
941  return const_key_iterator(get<ObjectImpl>().erase(first.base(), last.base()));
942 }
IfIsNonStringDynamicConvertible< K, std::size_t > erase(K &&)
Definition: dynamic-inl.h:916
constexpr detail::First first
Definition: Base-inl.h:2553
dynamic::value_iterator folly::dynamic::erase ( const_value_iterator  it)
inline

Definition at line 944 of file dynamic-inl.h.

References folly::detail::IteratorAdaptor< D, I, V, Tag >::base(), and erase().

944  {
945  return value_iterator(get<ObjectImpl>().erase(it.base()));
946 }
IfIsNonStringDynamicConvertible< K, std::size_t > erase(K &&)
Definition: dynamic-inl.h:916
dynamic::value_iterator folly::dynamic::erase ( const_value_iterator  first,
const_value_iterator  last 
)
inline

Definition at line 948 of file dynamic-inl.h.

References folly::detail::IteratorAdaptor< D, I, V, Tag >::base(), and erase().

950  {
951  return value_iterator(get<ObjectImpl>().erase(first.base(), last.base()));
952 }
IfIsNonStringDynamicConvertible< K, std::size_t > erase(K &&)
Definition: dynamic-inl.h:916
constexpr detail::First first
Definition: Base-inl.h:2553
dynamic::item_iterator folly::dynamic::erase ( const_item_iterator  it)
inline

Definition at line 954 of file dynamic-inl.h.

References folly::detail::IteratorAdaptor< D, I, V, Tag >::base(), and erase().

954  {
955  return item_iterator(get<ObjectImpl>().erase(it.base()));
956 }
IfIsNonStringDynamicConvertible< K, std::size_t > erase(K &&)
Definition: dynamic-inl.h:916
dynamic::item_iterator folly::dynamic::erase ( const_item_iterator  first,
const_item_iterator  last 
)
inline

Definition at line 958 of file dynamic-inl.h.

References folly::detail::IteratorAdaptor< D, I, V, Tag >::base(), and erase().

960  {
961  return item_iterator(get<ObjectImpl>().erase(first.base(), last.base()));
962 }
IfIsNonStringDynamicConvertible< K, std::size_t > erase(K &&)
Definition: dynamic-inl.h:916
constexpr detail::First first
Definition: Base-inl.h:2553
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, dynamic::const_item_iterator > folly::dynamic::find ( K &&  key) const

Definition at line 824 of file dynamic-inl.h.

Referenced by atImpl(), count(), find(), get_ptr(), get_ptrImpl(), merge_diff(), and TEST().

824  {
825  return get<ObjectImpl>().find(std::forward<K>(key));
826 }
IfIsNonStringDynamicConvertible< K, const_item_iterator > find(K &&) const
Definition: dynamic-inl.h:824
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, dynamic::item_iterator > folly::dynamic::find ( K &&  key)

Definition at line 830 of file dynamic-inl.h.

References find().

830  {
831  return get<ObjectImpl>().find(std::forward<K>(key));
832 }
IfIsNonStringDynamicConvertible< K, const_item_iterator > find(K &&) const
Definition: dynamic-inl.h:824
dynamic::const_item_iterator folly::dynamic::find ( StringPiece  key) const
inline

Definition at line 834 of file dynamic-inl.h.

References find().

834  {
835  return get<ObjectImpl>().find(key);
836 }
IfIsNonStringDynamicConvertible< K, const_item_iterator > find(K &&) const
Definition: dynamic-inl.h:824
dynamic::item_iterator folly::dynamic::find ( StringPiece  key)
inline

Definition at line 838 of file dynamic-inl.h.

References find().

838  {
839  return get<ObjectImpl>().find(key);
840 }
IfIsNonStringDynamicConvertible< K, const_item_iterator > find(K &&) const
Definition: dynamic-inl.h:824
template<class T >
T const & folly::dynamic::get ( ) const
private

Definition at line 1113 of file dynamic-inl.h.

1113  {
1114  return const_cast<dynamic*>(this)->get<T>();
1115 }
template<class T >
T & folly::dynamic::get ( )
private

Definition at line 1105 of file dynamic-inl.h.

References type().

1105  {
1106  if (auto* p = get_nothrow<T>()) {
1107  return *p;
1108  }
1109  throw_exception<TypeError>(TypeInfo<T>::name, type());
1110 }
const char * name
Definition: http_parser.c:437
Type type() const
Definition: dynamic-inl.h:514
template<class T >
T * folly::dynamic::get_nothrow ( )
privatenoexcept

Definition at line 1027 of file dynamic-inl.h.

References type_.

Referenced by get_ptr().

1027  {
1028  if (type_ != TypeInfo<T>::type) {
1029  return nullptr;
1030  }
1031  return getAddress<T>();
1032 }
PskType type
template<class T >
T const * folly::dynamic::get_nothrow ( ) const
privatenoexcept

Definition at line 1036 of file dynamic-inl.h.

1036  {
1037  return const_cast<dynamic*>(this)->get_nothrow<T>();
1038 }
template<class T >
T* folly::dynamic::get_nothrow ( )
privatedeletenoexcept
const dynamic * folly::dynamic::get_ptr ( json_pointer const &  jsonPtr) const

Definition at line 371 of file dynamic.cpp.

References end(), get_nothrow(), get_ptr(), isObject(), size(), tokens, and type().

Referenced by folly::compareDynamicWithTolerance(), get_ptr(), folly::parseLogConfigDynamic(), and TEST().

371  {
372  auto const& tokens = jsonPtr.tokens();
373  if (tokens.empty()) {
374  return this;
375  }
376  dynamic const* dyn = this;
377  for (auto const& token : tokens) {
378  if (!dyn) {
379  return nullptr;
380  }
381  // special case of parsing "/": lookup key with empty name
382  if (token.empty()) {
383  if (dyn->isObject()) {
384  dyn = dyn->get_ptr("");
385  continue;
386  }
387  throw_exception<TypeError>("object", dyn->type());
388  }
389  if (auto* parray = dyn->get_nothrow<dynamic::Array>()) {
390  if (token.size() > 1 && token.at(0) == '0') {
391  throw std::invalid_argument(
392  "Leading zero not allowed when indexing arrays");
393  }
394  // special case, always return non-existent
395  if (token.size() == 1 && token.at(0) == '-') {
396  dyn = nullptr;
397  continue;
398  }
399  auto const idx = folly::to<size_t>(token);
400  dyn = idx < parray->size() ? &(*parray)[idx] : nullptr;
401  continue;
402  }
403  if (auto* pobject = dyn->get_nothrow<dynamic::ObjectImpl>()) {
404  auto const it = pobject->find(token);
405  dyn = it != pobject->end() ? &it->second : nullptr;
406  continue;
407  }
408  throw_exception<TypeError>("object/array", dyn->type());
409  }
410  return dyn;
411 }
std::vector< dynamic > Array
Definition: dynamic.h:90
static const char tokens[256]
Definition: http_parser.c:184
dynamic * folly::dynamic::get_ptr ( json_pointer const &  jsonPtr)
inline

Definition at line 786 of file dynamic-inl.h.

References upload::const, and get_ptr().

786  {
787  return const_cast<dynamic*>(
788  const_cast<dynamic const*>(this)->get_ptr(jsonPtr));
789 }
const
Definition: upload.py:398
const dynamic * get_ptr(json_pointer const &) const &
Definition: dynamic.cpp:371
const dynamic* folly::dynamic::get_ptr ( json_pointer const &  ) const
delete
dynamic* folly::dynamic::get_ptr ( json_pointer const &  )
delete
template<typename K >
IfIsNonStringDynamicConvertible<K, const dynamic*> folly::dynamic::get_ptr ( K &&  ) const
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, dynamic * > folly::dynamic::get_ptr ( K &&  idx)

Definition at line 777 of file dynamic-inl.h.

References upload::const, and get_ptr().

778  {
779  return const_cast<dynamic*>(const_cast<dynamic const*>(this)->get_ptr(idx));
780 }
const
Definition: upload.py:398
const dynamic * get_ptr(json_pointer const &) const &
Definition: dynamic.cpp:371
template<typename K >
IfIsNonStringDynamicConvertible<K, dynamic*> folly::dynamic::get_ptr ( K &&  )
delete
const dynamic * folly::dynamic::get_ptr ( StringPiece  idx) const

Definition at line 263 of file dynamic.cpp.

References find(), and type.

263  {
264  auto* pobject = get_nothrow<ObjectImpl>();
265  if (!pobject) {
266  throw_exception<TypeError>("object", type());
267  }
268  auto it = pobject->find(idx);
269  if (it == pobject->end()) {
270  return nullptr;
271  }
272  return &it->second;
273 }
Type type() const
Definition: dynamic-inl.h:514
dynamic * folly::dynamic::get_ptr ( StringPiece  idx)
inline

Definition at line 782 of file dynamic-inl.h.

References upload::const, and get_ptr().

782  {
783  return const_cast<dynamic*>(const_cast<dynamic const*>(this)->get_ptr(idx));
784 }
const
Definition: upload.py:398
const dynamic * get_ptr(json_pointer const &) const &
Definition: dynamic.cpp:371
dynamic* folly::dynamic::get_ptr ( StringPiece  )
delete
template<typename K >
dynamic::IfIsNonStringDynamicConvertible<K, dynamic const*> folly::dynamic::get_ptr ( K &&  k) const

Definition at line 771 of file dynamic-inl.h.

References get_ptrImpl(), and k.

772  {
773  return get_ptrImpl(std::forward<K>(k));
774 }
const dynamic * get_ptrImpl(dynamic const &) const &
Definition: dynamic.cpp:243
KeyT k
const dynamic * folly::dynamic::get_ptrImpl ( dynamic const &  idx) const
private

Definition at line 243 of file dynamic.cpp.

References find(), and type.

Referenced by get_ptr().

243  {
244  if (auto* parray = get_nothrow<Array>()) {
245  if (!idx.isInt()) {
246  throw_exception<TypeError>("int64", idx.type());
247  }
248  if (idx < 0 || idx >= parray->size()) {
249  return nullptr;
250  }
251  return &(*parray)[size_t(idx.asInt())];
252  } else if (auto* pobject = get_nothrow<ObjectImpl>()) {
253  auto it = pobject->find(idx);
254  if (it == pobject->end()) {
255  return nullptr;
256  }
257  return &it->second;
258  } else {
259  throw_exception<TypeError>("object/array", type());
260  }
261 }
Type type() const
Definition: dynamic-inl.h:514
template<class T >
T * folly::dynamic::getAddress ( )
privatenoexcept

Definition at line 1043 of file dynamic-inl.h.

References folly::pushmi::operators::get, and u_.

Referenced by operator+=().

1043  {
1044  return GetAddrImpl<T>::get(u_);
1045 }
union folly::dynamic::Data u_
PUSHMI_INLINE_VAR constexpr detail::get_fn< T > get
Definition: submit.h:391
template<class T >
T const * folly::dynamic::getAddress ( ) const
privatenoexcept

Definition at line 1048 of file dynamic-inl.h.

1048  {
1049  return const_cast<dynamic*>(this)->getAddress<T>();
1050 }
bool folly::dynamic::getBool ( ) const
inline

Definition at line 540 of file dynamic-inl.h.

Referenced by folly::bser::bserEncode(), getBool(), and TEST().

540  {
541  return get<bool>();
542 }
bool folly::dynamic::getBool ( )
inline

Definition at line 553 of file dynamic-inl.h.

References getBool(), getDouble(), getInt(), getString(), int64_t, folly::gen::move, and string.

553  {
554  return get<bool>();
555 }
bool folly::dynamic::getBool ( )
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, dynamic > folly::dynamic::getDefault ( K &&  k,
const dynamic v = dynamic::object 
) const

Definition at line 685 of file dynamic-inl.h.

References k.

Referenced by folly::convertTo(), and TEST().

687  {
688  auto& obj = get<ObjectImpl>();
689  auto it = obj.find(std::forward<K>(k));
690  return it == obj.end() ? v : it->second;
691 }
KeyT k
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, dynamic > folly::dynamic::getDefault ( K &&  k,
dynamic &&  v 
) const

Definition at line 694 of file dynamic-inl.h.

References k, and folly::gen::move.

696  {
697  auto& obj = get<ObjectImpl>();
698  auto it = obj.find(std::forward<K>(k));
699  // Avoid clang bug with ternary
700  if (it == obj.end()) {
701  return std::move(v);
702  } else {
703  return it->second;
704  }
705 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
KeyT k
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, dynamic > folly::dynamic::getDefault ( K &&  k,
const dynamic v = dynamic::object 
)

Definition at line 708 of file dynamic-inl.h.

References k, folly::gen::move, and v.

710  {
711  auto& obj = get<ObjectImpl>();
712  auto it = obj.find(std::forward<K>(k));
713  // Avoid clang bug with ternary
714  if (it == obj.end()) {
715  return v;
716  } else {
717  return std::move(it->second);
718  }
719 }
auto v
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
KeyT k
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, dynamic > folly::dynamic::getDefault ( K &&  k,
dynamic &&  v 
)

Definition at line 722 of file dynamic-inl.h.

References k, and folly::gen::move.

724  {
725  auto& obj = get<ObjectImpl>();
726  auto it = obj.find(std::forward<K>(k));
727  return std::move(it == obj.end() ? v : it->second);
728 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
KeyT k
dynamic folly::dynamic::getDefault ( StringPiece  k,
const dynamic v = dynamic::object 
) const

Definition at line 209 of file dynamic.cpp.

209  {
210  auto& obj = get<ObjectImpl>();
211  auto it = obj.find(k);
212  return it == obj.end() ? v : it->second;
213 }
KeyT k
dynamic folly::dynamic::getDefault ( StringPiece  k,
dynamic &&  v 
) const

Definition at line 215 of file dynamic.cpp.

References folly::gen::move.

215  {
216  auto& obj = get<ObjectImpl>();
217  auto it = obj.find(k);
218  // Avoid clang bug with ternary
219  if (it == obj.end()) {
220  return std::move(v);
221  } else {
222  return it->second;
223  }
224 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
KeyT k
dynamic folly::dynamic::getDefault ( StringPiece  k,
const dynamic v = dynamic::object 
)

Definition at line 226 of file dynamic.cpp.

References folly::gen::move, and v.

226  {
227  auto& obj = get<ObjectImpl>();
228  auto it = obj.find(k);
229  // Avoid clang bug with ternary
230  if (it == obj.end()) {
231  return v;
232  } else {
233  return std::move(it->second);
234  }
235 }
auto v
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
KeyT k
dynamic folly::dynamic::getDefault ( StringPiece  k,
dynamic &&  v 
)

Definition at line 237 of file dynamic.cpp.

References folly::gen::move.

237  {
238  auto& obj = get<ObjectImpl>();
239  auto it = obj.find(k);
240  return std::move(it == obj.end() ? v : it->second);
241 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
KeyT k
double folly::dynamic::getDouble ( ) const
inline

Definition at line 534 of file dynamic-inl.h.

Referenced by folly::bser::bserEncode(), getBool(), and TEST().

534  {
535  return get<double>();
536 }
double folly::dynamic::getDouble ( )
inline

Definition at line 547 of file dynamic-inl.h.

547  {
548  return get<double>();
549 }
double folly::dynamic::getDouble ( )
int64_t folly::dynamic::getInt ( ) const
inline

Definition at line 537 of file dynamic-inl.h.

Referenced by folly::bser::bserEncode(), getBool(), and TEST().

537  {
538  return get<int64_t>();
539 }
int64_t folly::dynamic::getInt ( )
inline

Definition at line 550 of file dynamic-inl.h.

550  {
551  return get<int64_t>();
552 }
int64_t folly::dynamic::getInt ( )
const std::string & folly::dynamic::getString ( ) const
inline

Definition at line 531 of file dynamic-inl.h.

Referenced by folly::bser::bserEncode(), getBool(), and TEST().

531  {
532  return get<std::string>();
533 }
std::string && folly::dynamic::getString ( )
inline

Definition at line 544 of file dynamic-inl.h.

544  {
545  return get<std::string>();
546 }
std::string&& folly::dynamic::getString ( )
std::size_t folly::dynamic::hash ( ) const

Definition at line 294 of file dynamic.cpp.

References folly::f14::accumulate(), folly::assume_unreachable(), folly::test::begin(), folly::test::end(), h, folly::hash::hash_range(), STRING, and type.

Referenced by folly::detail::DynamicHasher::operator()(), and std::hash<::folly::dynamic >::operator()().

294  {
295  switch (type()) {
296  case NULLT:
297  return 0xBAAAAAAD;
298  case OBJECT: {
299  // Accumulate using addition instead of using hash_range (as in the ARRAY
300  // case), as we need a commutative hash operation since unordered_map's
301  // iteration order is unspecified.
302  auto h = std::hash<std::pair<dynamic, dynamic>>{};
303  return std::accumulate(
304  items().begin(),
305  items().end(),
306  size_t{0x0B1EC7},
307  [&](auto acc, auto item) { return acc + h(item); });
308  }
309  case ARRAY:
310  return folly::hash::hash_range(begin(), end());
311  case INT64:
312  return std::hash<int64_t>()(getInt());
313  case DOUBLE:
314  return std::hash<double>()(getDouble());
315  case BOOL:
316  return std::hash<bool>()(getBool());
317  case STRING:
318  // keep consistent with detail::DynamicHasher
319  return Hash()(getString());
320  }
322 }
*than *hazptr_holder h
Definition: Hazptr.h:116
void accumulate(std::vector< std::size_t > &a, std::vector< std::size_t > const &d)
Definition: F14TestUtil.h:58
double getDouble() const &
Definition: dynamic-inl.h:534
const std::string & getString() const &
Definition: dynamic-inl.h:531
uint64_t hash_range(Iter begin, Iter end, uint64_t hash=0, Hash hasher=Hash())
Definition: Hash.h:604
int64_t getInt() const &
Definition: dynamic-inl.h:537
FOLLY_ALWAYS_INLINE void assume_unreachable()
Definition: Assume.h:59
IterableProxy< const_item_iterator > items() const
Definition: dynamic-inl.h:476
bool getBool() const &
Definition: dynamic-inl.h:540
Type type() const
Definition: dynamic-inl.h:514
const_iterator begin() const
Definition: dynamic-inl.h:432
const_iterator end() const
Definition: dynamic-inl.h:435
template<class K , class V >
void folly::dynamic::insert ( K &&  key,
V &&  val 
)
inline

Definition at line 853 of file dynamic-inl.h.

References val.

Referenced by folly::DynamicConstructor< C, typename std::enable_if< !std::is_same< C, dynamic >::value &&dynamicconverter_detail::is_map< C >::value >::type >::construct(), folly::logConfigToDynamic(), and TEST().

853  {
854  auto& obj = get<ObjectImpl>();
855  obj[std::forward<K>(key)] = std::forward<V>(val);
856 }
double val
Definition: String.cpp:273
bool folly::dynamic::isBool ( ) const
inline

Definition at line 495 of file dynamic-inl.h.

495  {
496  return get_nothrow<bool>() != nullptr;
497 }
bool folly::dynamic::isDouble ( ) const
inline

Definition at line 501 of file dynamic-inl.h.

Referenced by isNumber(), and folly::detail::numericOp().

501  {
502  return get_nothrow<double>() != nullptr;
503 }
bool folly::dynamic::isInt ( ) const
inline

Definition at line 504 of file dynamic-inl.h.

Referenced by folly::compareDynamicWithTolerance(), isNumber(), and folly::detail::numericOp().

504  {
505  return get_nothrow<int64_t>() != nullptr;
506 }
bool folly::dynamic::isNull ( ) const
inline

Definition at line 507 of file dynamic-inl.h.

Referenced by empty(), and TEST().

507  {
508  return get_nothrow<std::nullptr_t>() != nullptr;
509 }
bool folly::dynamic::isNumber ( ) const
inline

Definition at line 510 of file dynamic-inl.h.

References isDouble(), and isInt().

Referenced by folly::compareDynamicWithTolerance(), folly::detail::numericOp(), and operator==().

510  {
511  return isInt() || isDouble();
512 }
bool isInt() const
Definition: dynamic-inl.h:504
bool isDouble() const
Definition: dynamic-inl.h:501
bool folly::dynamic::isString ( ) const
inline

Definition at line 489 of file dynamic-inl.h.

489  {
490  return get_nothrow<std::string>() != nullptr;
491 }
dynamic::IterableProxy< dynamic::item_iterator > folly::dynamic::items ( )
inline

Definition at line 485 of file dynamic-inl.h.

485  {
486  return &(get<ObjectImpl>());
487 }
dynamic::IterableProxy< dynamic::const_key_iterator > folly::dynamic::keys ( ) const
inline

Definition at line 466 of file dynamic-inl.h.

Referenced by TEST().

467  {
468  return &(get<ObjectImpl>());
469 }
dynamic folly::dynamic::merge ( const dynamic mergeObj1,
const dynamic mergeObj2 
)
inlinestatic

Definition at line 904 of file dynamic-inl.h.

References update_missing().

906  {
907  // No checks on type needed here because they are done in update_missing
908  // Note that we do update_missing here instead of update() because
909  // it will prevent the extra writes that would occur with update()
910  auto ret = mergeObj2;
911  ret.update_missing(mergeObj1);
912  return ret;
913 }
dynamic folly::dynamic::merge_diff ( const dynamic source,
const dynamic target 
)
static

Definition at line 343 of file dynamic.cpp.

References diff(), find(), isObject(), items(), object, and type().

343  {
344  if (!source.isObject() || source.type() != target.type()) {
345  return target;
346  }
347 
348  dynamic diff = object;
349 
350  // added/modified keys
351  for (const auto& pair : target.items()) {
352  auto it = source.find(pair.first);
353  if (it == source.items().end()) {
354  diff[pair.first] = pair.second;
355  } else {
356  diff[pair.first] = merge_diff(source[pair.first], target[pair.first]);
357  }
358  }
359 
360  // removed keys
361  for (const auto& pair : source.items()) {
362  auto it = target.find(pair.first);
363  if (it == target.items().end()) {
364  diff[pair.first] = nullptr;
365  }
366  }
367 
368  return diff;
369 }
static ObjectMaker object()
Definition: dynamic-inl.h:240
static dynamic merge_diff(const dynamic &source, const dynamic &target)
Definition: dynamic.cpp:343
uint64_t diff(uint64_t a, uint64_t b)
Definition: FutexTest.cpp:135
Definition: Traits.h:577
void folly::dynamic::merge_patch ( const dynamic patch)
inline

Definition at line 881 of file dynamic-inl.h.

References end(), isObject(), items(), and object().

Referenced by TEST().

881  {
882  auto& self = *this;
883  if (!patch.isObject()) {
884  self = patch;
885  return;
886  }
887  // if we are not an object, erase all contents, reset to object
888  if (!isObject()) {
889  self = object;
890  }
891  for (const auto& pair : patch.items()) {
892  if (pair.second.isNull()) {
893  // if name could be found in current object, remove it
894  auto it = self.find(pair.first);
895  if (it != self.items().end()) {
896  self.erase(it);
897  }
898  } else {
899  self[pair.first].merge_patch(pair.second);
900  }
901  }
902 }
static ObjectMaker object()
Definition: dynamic-inl.h:240
IterableProxy< const_item_iterator > items() const
Definition: dynamic-inl.h:476
Definition: Traits.h:577
bool isObject() const
Definition: dynamic-inl.h:492
const_iterator end() const
Definition: dynamic-inl.h:435
dynamic::ObjectMaker folly::dynamic::object ( dynamic  a,
dynamic  b 
)
inlinestatic

Definition at line 243 of file dynamic-inl.h.

References folly::gen::move.

243  {
244  return ObjectMaker(std::move(a), std::move(b));
245 }
char b
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
char a
dynamic & folly::dynamic::operator%= ( dynamic const &  o)
inline

Definition at line 633 of file dynamic-inl.h.

dynamic & folly::dynamic::operator&= ( dynamic const &  o)
inline

Definition at line 635 of file dynamic-inl.h.

dynamic & folly::dynamic::operator*= ( dynamic const &  o)
inline

Definition at line 614 of file dynamic-inl.h.

614  {
615  *this = detail::numericOp<std::multiplies>(*this, o);
616  return *this;
617 }
dynamic & folly::dynamic::operator++ ( )
inline

Definition at line 640 of file dynamic-inl.h.

640  {
641  ++get<int64_t>();
642  return *this;
643 }
dynamic & folly::dynamic::operator+= ( dynamic const &  o)
inline

Definition at line 600 of file dynamic-inl.h.

References getAddress(), STRING, string, and type().

600  {
601  if (type() == STRING && o.type() == STRING) {
602  *getAddress<std::string>() += *o.getAddress<std::string>();
603  return *this;
604  }
605  *this = detail::numericOp<std::plus>(*this, o);
606  return *this;
607 }
const char * string
Definition: Conv.cpp:212
Type type() const
Definition: dynamic-inl.h:514
dynamic & folly::dynamic::operator-- ( )
inline

Definition at line 645 of file dynamic-inl.h.

645  {
646  --get<int64_t>();
647  return *this;
648 }
dynamic & folly::dynamic::operator-= ( dynamic const &  o)
inline

Definition at line 609 of file dynamic-inl.h.

609  {
610  *this = detail::numericOp<std::minus>(*this, o);
611  return *this;
612 }
dynamic & folly::dynamic::operator/= ( dynamic const &  o)
inline

Definition at line 619 of file dynamic-inl.h.

619  {
620  *this = detail::numericOp<std::divides>(*this, o);
621  return *this;
622 }
bool folly::dynamic::operator< ( dynamic const &  o) const

Definition at line 107 of file dynamic.cpp.

References FB_DYNAMIC_APPLY, FB_X, type_, type_, and UNLIKELY.

107  {
108  if (UNLIKELY(type_ == OBJECT || o.type_ == OBJECT)) {
109  throw_exception<TypeError>("object", type_);
110  }
111  if (type_ != o.type_) {
112  return type_ < o.type_;
113  }
114 
115 #define FB_X(T) return CompareOp<T>::comp(*getAddress<T>(), *o.getAddress<T>())
117 #undef FB_X
118 }
#define FB_DYNAMIC_APPLY(type, apply)
Definition: dynamic.cpp:77
#define FB_X(T)
#define UNLIKELY(x)
Definition: Likely.h:48
dynamic & folly::dynamic::operator= ( dynamic const &  o)

Definition at line 135 of file dynamic.cpp.

References destroy(), FB_DYNAMIC_APPLY, FB_X, type_, and type_.

135  {
136  if (&o != this) {
137  if (type_ == o.type_) {
138 #define FB_X(T) *getAddress<T>() = *o.getAddress<T>()
140 #undef FB_X
141  } else {
142  destroy();
143 #define FB_X(T) new (getAddress<T>()) T(*o.getAddress<T>())
144  FB_DYNAMIC_APPLY(o.type_, FB_X);
145 #undef FB_X
146  type_ = o.type_;
147  }
148  }
149  return *this;
150 }
#define FB_DYNAMIC_APPLY(type, apply)
Definition: dynamic.cpp:77
#define FB_X(T)
void destroy() noexcept
Definition: dynamic.cpp:330
dynamic & folly::dynamic::operator= ( dynamic &&  o)
noexcept

Definition at line 152 of file dynamic.cpp.

References destroy(), FB_DYNAMIC_APPLY, FB_X, and type_.

152  {
153  if (&o != this) {
154  if (type_ == o.type_) {
155 #define FB_X(T) *getAddress<T>() = std::move(*o.getAddress<T>())
157 #undef FB_X
158  } else {
159  destroy();
160 #define FB_X(T) new (getAddress<T>()) T(std::move(*o.getAddress<T>()))
161  FB_DYNAMIC_APPLY(o.type_, FB_X);
162 #undef FB_X
163  type_ = o.type_;
164  }
165  }
166  return *this;
167 }
#define FB_DYNAMIC_APPLY(type, apply)
Definition: dynamic.cpp:77
#define FB_X(T)
void destroy() noexcept
Definition: dynamic.cpp:330
bool folly::dynamic::operator== ( dynamic const &  o) const

Definition at line 120 of file dynamic.cpp.

References asInt(), FB_DYNAMIC_APPLY, FB_X, isNumber(), type(), type, and type_.

120  {
121  if (type() != o.type()) {
122  if (isNumber() && o.isNumber()) {
123  auto& integ = isInt() ? *this : o;
124  auto& doubl = isInt() ? o : *this;
125  return integ.asInt() == doubl.asDouble();
126  }
127  return false;
128  }
129 
130 #define FB_X(T) return *getAddress<T>() == *o.getAddress<T>();
132 #undef FB_X
133 }
#define FB_DYNAMIC_APPLY(type, apply)
Definition: dynamic.cpp:77
#define FB_X(T)
bool isNumber() const
Definition: dynamic-inl.h:510
bool isInt() const
Definition: dynamic-inl.h:504
Type type() const
Definition: dynamic-inl.h:514
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, dynamic & > folly::dynamic::operator[] ( K &&  idx)

Definition at line 657 of file dynamic-inl.h.

References at(), isArray(), isObject(), and type().

Referenced by at().

658  {
659  if (!isObject() && !isArray()) {
660  throw_exception<TypeError>("object/array", type());
661  }
662  if (isArray()) {
663  return at(std::forward<K>(idx));
664  }
665  auto& obj = get<ObjectImpl>();
666  auto ret = obj.emplace(std::forward<K>(idx), nullptr);
667  return ret.first->second;
668 }
bool isArray() const
Definition: dynamic-inl.h:498
IfIsNonStringDynamicConvertible< K, dynamic const & > at(K &&) const &
Definition: dynamic-inl.h:792
Type type() const
Definition: dynamic-inl.h:514
bool isObject() const
Definition: dynamic-inl.h:492
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, dynamic const & > folly::dynamic::operator[] ( K &&  idx) const

Definition at line 651 of file dynamic-inl.h.

References at().

652  {
653  return at(std::forward<K>(idx));
654 }
IfIsNonStringDynamicConvertible< K, dynamic const & > at(K &&) const &
Definition: dynamic-inl.h:792
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, dynamic && > folly::dynamic::operator[] ( K &&  idx)

Definition at line 671 of file dynamic-inl.h.

References folly::gen::move.

672  {
673  return std::move((*this)[std::forward<K>(idx)]);
674 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
dynamic & folly::dynamic::operator[] ( StringPiece  k)
inline

Definition at line 680 of file dynamic-inl.h.

References k, and folly::gen::move.

680  {
681  return std::move((*this)[k]);
682 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
KeyT k
dynamic const & folly::dynamic::operator[] ( StringPiece  k) const
inline

Definition at line 676 of file dynamic-inl.h.

References at(), and k.

676  {
677  return at(k);
678 }
IfIsNonStringDynamicConvertible< K, dynamic const & > at(K &&) const &
Definition: dynamic-inl.h:792
KeyT k
dynamic&& folly::dynamic::operator[] ( StringPiece  )
dynamic & folly::dynamic::operator^= ( dynamic const &  o)
inline

Definition at line 636 of file dynamic-inl.h.

dynamic & folly::dynamic::operator|= ( dynamic const &  o)
inline

Definition at line 634 of file dynamic-inl.h.

void folly::dynamic::pop_back ( )
inline

Definition at line 979 of file dynamic-inl.h.

979  {
980  auto& arr = get<Array>();
981  arr.pop_back();
982 }
void folly::dynamic::print ( std::ostream &  out) const
inlineprivate

Definition at line 1152 of file dynamic-inl.h.

References FB_DYNAMIC_APPLY, FB_X, and type_.

Referenced by folly::operator<<().

1152  {
1153 #define FB_X(T) PrintImpl<T>::print(*this, out, *getAddress<T>())
1155 #undef FB_X
1156 }
#define FB_X(T)
#define FB_DYNAMIC_APPLY(type, apply)
Definition: dynamic-inl.h:97
void folly::dynamic::print_as_pseudo_json ( std::ostream &  out) const
private

Definition at line 930 of file json.cpp.

References folly::json::serialization_opts::allow_nan_inf, folly::json::serialization_opts::allow_non_string_keys, and folly::json::serialize().

Referenced by folly::dynamic::PrintImpl< dynamic::ObjectImpl >::print(), and folly::dynamic::PrintImpl< dynamic::Array >::print().

930  {
931  json::serialization_opts opts;
932  opts.allow_non_string_keys = true;
933  opts.allow_nan_inf = true;
934  out << json::serialize(*this, opts);
935 }
std::string serialize(dynamic const &dyn, serialization_opts const &opts)
Definition: json.cpp:621
void folly::dynamic::push_back ( dynamic &&  v)
inline

Definition at line 974 of file dynamic-inl.h.

References folly::gen::move.

974  {
975  auto& arr = get<Array>();
976  arr.push_back(std::move(v));
977 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void folly::dynamic::resize ( std::size_t  n,
dynamic const &  c = nullptr 
)
inline

Definition at line 964 of file dynamic-inl.h.

Referenced by TEST().

964  {
965  auto& arr = get<Array>();
966  arr.resize(sz, c);
967 }
char c
template<typename K , typename V >
dynamic::IfIsNonStringDynamicConvertible< K, dynamic & > folly::dynamic::setDefault ( K &&  k,
V &&  v 
)

Definition at line 731 of file dynamic-inl.h.

References k.

Referenced by TEST().

733  {
734  auto& obj = get<ObjectImpl>();
735  return obj.emplace(std::forward<K>(k), std::forward<V>(v)).first->second;
736 }
KeyT k
template<typename V >
dynamic & folly::dynamic::setDefault ( StringPiece  k,
V &&  v 
)

Definition at line 755 of file dynamic-inl.h.

755  {
756  auto& obj = get<ObjectImpl>();
757  return obj.emplace(k, std::forward<V>(v)).first->second;
758 }
KeyT k
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, dynamic & > folly::dynamic::setDefault ( K &&  k,
dynamic &&  v 
)

Definition at line 739 of file dynamic-inl.h.

References k, and folly::gen::move.

741  {
742  auto& obj = get<ObjectImpl>();
743  return obj.emplace(std::forward<K>(k), std::move(v)).first->second;
744 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
KeyT k
template<typename K >
dynamic::IfIsNonStringDynamicConvertible< K, dynamic & > folly::dynamic::setDefault ( K &&  k,
const dynamic v = dynamic::object 
)

Definition at line 747 of file dynamic-inl.h.

References k.

749  {
750  auto& obj = get<ObjectImpl>();
751  return obj.emplace(std::forward<K>(k), v).first->second;
752 }
KeyT k
dynamic & folly::dynamic::setDefault ( StringPiece  k,
dynamic &&  v 
)
inline

Definition at line 760 of file dynamic-inl.h.

References folly::gen::move.

760  {
761  auto& obj = get<ObjectImpl>();
762  return obj.emplace(k, std::move(v)).first->second;
763 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
KeyT k
dynamic & folly::dynamic::setDefault ( StringPiece  k,
const dynamic v = dynamic::object 
)
inline

Definition at line 765 of file dynamic-inl.h.

765  {
766  auto& obj = get<ObjectImpl>();
767  return obj.emplace(k, v).first->second;
768 }
KeyT k
std::size_t folly::dynamic::size ( ) const

Definition at line 275 of file dynamic.cpp.

References type.

Referenced by folly::bser::bserEncodeArray(), folly::bser::bserEncodeArraySimple(), folly::bser::bserEncodeObject(), folly::compareDynamicWithTolerance(), folly::DynamicConverter< std::pair< F, S > >::convert(), empty(), get_ptr(), and TEST().

275  {
276  if (auto* ar = get_nothrow<Array>()) {
277  return ar->size();
278  }
279  if (auto* obj = get_nothrow<ObjectImpl>()) {
280  return obj->size();
281  }
282  if (auto* str = get_nothrow<std::string>()) {
283  return str->size();
284  }
285  throw_exception<TypeError>("array/object/string", type());
286 }
Type type() const
Definition: dynamic-inl.h:514
StringPiece folly::dynamic::stringPiece ( ) const
inline

Definition at line 576 of file dynamic-inl.h.

Referenced by folly::detail::DynamicKeyEqual::operator()(), and TEST().

576  {
577  return get<std::string>();
578 }
const char * folly::dynamic::typeName ( ) const

Definition at line 45 of file dynamic.cpp.

References type_.

Referenced by TEST().

45  {
46  return typeName(type_);
47 }
const char * typeName() const
Definition: dynamic.cpp:45
char const * folly::dynamic::typeName ( Type  t)
staticprivate

Definition at line 324 of file dynamic.cpp.

References FB_DYNAMIC_APPLY, and FB_X.

324  {
325 #define FB_X(T) return TypeInfo<T>::name
327 #undef FB_X
328 }
#define FB_DYNAMIC_APPLY(type, apply)
Definition: dynamic.cpp:77
#define FB_X(T)
void folly::dynamic::update ( const dynamic mergeObj)
inline

Definition at line 858 of file dynamic-inl.h.

References isObject(), items(), and type().

Referenced by TEST().

858  {
859  if (!isObject() || !mergeObj.isObject()) {
860  throw_exception<TypeError>("object", type(), mergeObj.type());
861  }
862 
863  for (const auto& pair : mergeObj.items()) {
864  (*this)[pair.first] = pair.second;
865  }
866 }
Definition: Traits.h:577
Type type() const
Definition: dynamic-inl.h:514
bool isObject() const
Definition: dynamic-inl.h:492
void folly::dynamic::update_missing ( const dynamic other)
inline

Definition at line 868 of file dynamic-inl.h.

References isObject(), items(), and type().

Referenced by merge(), and TEST().

868  {
869  if (!isObject() || !mergeObj1.isObject()) {
870  throw_exception<TypeError>("object", type(), mergeObj1.type());
871  }
872 
873  // Only add if not already there
874  for (const auto& pair : mergeObj1.items()) {
875  if ((*this).find(pair.first) == (*this).items().end()) {
876  (*this)[pair.first] = pair.second;
877  }
878  }
879 }
Definition: Traits.h:577
Type type() const
Definition: dynamic-inl.h:514
bool isObject() const
Definition: dynamic-inl.h:492
dynamic::IterableProxy< dynamic::const_value_iterator > folly::dynamic::values ( ) const
inline

Definition at line 471 of file dynamic-inl.h.

Referenced by TEST().

472  {
473  return &(get<ObjectImpl>());
474 }
dynamic::IterableProxy< dynamic::value_iterator > folly::dynamic::values ( )
inline

Definition at line 481 of file dynamic-inl.h.

481  {
482  return &(get<ObjectImpl>());
483 }

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
dynamic const &  d 
)
friend

Definition at line 1158 of file dynamic-inl.h.

1158  {
1159  d.print(out);
1160  return out;
1161 }
friend struct TypeError
friend

Definition at line 647 of file dynamic.h.

Member Data Documentation

Type folly::dynamic::type_
private

Definition at line 688 of file dynamic.h.

Referenced by dynamic(), get_nothrow(), operator<(), operator=(), print(), type(), and typeName().

union folly::dynamic::Data folly::dynamic::u_
private

Referenced by dynamic(), and getAddress().


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