48 return std::equal_to<dynamic>()(lhs, rhs);
54 template <
typename A,
typename B>
66 std::equal_to<StringPiece>()(lhs, rhs.
stringPiece());
97 #define FB_DYNAMIC_APPLY(type, apply) \ 101 apply(std::nullptr_t); \ 119 apply(std::string); \ 139 TypeError(
const TypeError&)
noexcept(
141 TypeError& operator=(
const TypeError&)
noexcept(
145 TypeError& operator=(TypeError&&)
noexcept(
147 ~TypeError()
override;
168 template <
template <
class>
class Op>
171 throw_exception<TypeError>(
"numeric", a.
type(), b.
type());
174 auto& integ = a.
isInt() ? a :
b;
175 auto& nonint = a.
isInt() ? b :
a;
176 return Op<double>()(to<double>(integ.asInt()), nonint.asDouble());
199 detail::DynamicHasher,
200 detail::DynamicKeyEqual> {};
235 template <
class...
Args>
250 dynamic::item_iterator,
251 dynamic::ObjectImpl::iterator,
252 std::pair<dynamic const, dynamic>,
253 std::forward_iterator_tag> {
256 dynamic::ObjectImpl::iterator,
257 std::pair<dynamic const, dynamic>,
258 std::forward_iterator_tag>;
265 dynamic::value_iterator,
266 dynamic::ObjectImpl::iterator,
268 std::forward_iterator_tag> {
271 dynamic::ObjectImpl::iterator,
273 std::forward_iterator_tag>;
279 return base()->second;
285 dynamic::const_item_iterator,
286 dynamic::ObjectImpl::const_iterator,
287 std::pair<dynamic const, dynamic> const,
288 std::forward_iterator_tag> {
291 dynamic::ObjectImpl::const_iterator,
292 std::pair<dynamic const, dynamic>
const,
293 std::forward_iterator_tag>;
304 dynamic::const_key_iterator,
305 dynamic::ObjectImpl::const_iterator,
307 std::forward_iterator_tag> {
310 dynamic::ObjectImpl::const_iterator,
312 std::forward_iterator_tag>;
319 return base()->first;
324 dynamic::const_value_iterator,
325 dynamic::ObjectImpl::const_iterator,
327 std::forward_iterator_tag> {
330 dynamic::ObjectImpl::const_iterator,
332 std::forward_iterator_tag>;
342 return base()->second;
373 new (getAddress<ObjectImpl>())
393 typename
std::enable_if<std::is_integral<T>::value>
::type> {
395 !
kIsObjC ||
sizeof(
T) >
sizeof(
char),
396 "char-sized types are ambiguous in objc; cast to bool or wider type");
413 :
dynamic(static_cast<bool>(b)) {}
415 :
dynamic(static_cast<bool>(b)) {}
422 new (getAddress<NumericType>()) NumericType(NumericType(t));
425 template <
class Iterator>
433 return get<Array>().
begin();
436 return get<Array>().
end();
440 return get<Array>().
begin();
443 return get<Array>().
end();
468 return &(get<ObjectImpl>());
473 return &(get<ObjectImpl>());
478 return &(get<ObjectImpl>());
482 return &(get<ObjectImpl>());
486 return &(get<ObjectImpl>());
490 return get_nothrow<std::string>() !=
nullptr;
493 return get_nothrow<ObjectImpl>() !=
nullptr;
496 return get_nothrow<bool>() !=
nullptr;
499 return get_nothrow<Array>() !=
nullptr;
502 return get_nothrow<double>() !=
nullptr;
505 return get_nothrow<int64_t>() !=
nullptr;
508 return get_nothrow<std::nullptr_t>() !=
nullptr;
519 return asImpl<std::string>();
522 return asImpl<double>();
525 return asImpl<int64_t>();
528 return asImpl<bool>();
532 return get<std::string>();
535 return get<double>();
538 return get<int64_t>();
545 return get<std::string>();
548 return get<double>();
551 return get<int64_t>();
561 return get<double>();
564 return get<int64_t>();
571 return get<std::string>().
data();
574 return get<std::string>().
c_str();
577 return get<std::string>();
595 static bool comp(std::nullptr_t
const&, std::nullptr_t
const&) {
605 *
this = detail::numericOp<std::plus>(*
this, o);
610 *
this = detail::numericOp<std::minus>(*
this, o);
615 *
this = detail::numericOp<std::multiplies>(*
this, o);
620 *
this = detail::numericOp<std::divides>(*
this, o);
624 #define FB_DYNAMIC_INTEGER_OP(op) \ 625 inline dynamic& dynamic::operator op(dynamic const& o) { \ 626 if (!isInt() || !o.isInt()) { \ 627 throw_exception<TypeError>("int64", type(), o.type()); \ 629 *getAddress<int64_t>() op o.asInt(); \ 638 #undef FB_DYNAMIC_INTEGER_OP 650 template <
typename K>
653 return at(std::forward<K>(idx));
656 template <
typename K>
660 throw_exception<TypeError>(
"object/array",
type());
663 return at(std::forward<K>(idx));
665 auto& obj = get<ObjectImpl>();
666 auto ret = obj.emplace(std::forward<K>(idx),
nullptr);
667 return ret.first->second;
670 template <
typename K>
673 return std::move((*
this)[std::forward<K>(idx)]);
684 template <
typename K>
688 auto& obj = get<ObjectImpl>();
689 auto it = obj.find(std::forward<K>(
k));
690 return it == obj.end() ?
v : it->second;
693 template <
typename K>
697 auto& obj = get<ObjectImpl>();
698 auto it = obj.find(std::forward<K>(
k));
700 if (it == obj.end()) {
707 template <
typename K>
711 auto& obj = get<ObjectImpl>();
712 auto it = obj.find(std::forward<K>(
k));
714 if (it == obj.end()) {
721 template <
typename K>
725 auto& obj = get<ObjectImpl>();
726 auto it = obj.find(std::forward<K>(
k));
727 return std::move(it == obj.end() ?
v : it->second);
730 template <
typename K,
typename V>
734 auto& obj = get<ObjectImpl>();
735 return obj.emplace(std::forward<K>(
k), std::forward<V>(
v)).first->second;
738 template <
typename K>
742 auto& obj = get<ObjectImpl>();
743 return obj.emplace(std::forward<K>(
k),
std::move(
v)).first->second;
746 template <
typename K>
750 auto& obj = get<ObjectImpl>();
751 return obj.emplace(std::forward<K>(
k), v).first->second;
754 template <
typename V>
756 auto& obj = get<ObjectImpl>();
757 return obj.emplace(k, std::forward<V>(
v)).first->second;
761 auto& obj = get<ObjectImpl>();
762 return obj.emplace(k,
std::move(
v)).first->second;
766 auto& obj = get<ObjectImpl>();
767 return obj.emplace(k, v).first->second;
770 template <
typename K>
776 template <
typename K>
791 template <
typename K>
794 return atImpl(std::forward<K>(
k));
797 template <
typename K>
802 template <
typename K>
822 template <
typename K>
825 return get<ObjectImpl>().
find(std::forward<K>(key));
828 template <
typename K>
831 return get<ObjectImpl>().
find(std::forward<K>(key));
835 return get<ObjectImpl>().
find(key);
839 return get<ObjectImpl>().
find(key);
842 template <
typename K>
845 return find(std::forward<K>(key)) !=
items().end() ? 1u : 0u;
849 return find(key) !=
items().end() ? 1u : 0u;
852 template <
class K,
class V>
854 auto& obj = get<ObjectImpl>();
855 obj[std::forward<K>(key)] = std::forward<V>(
val);
860 throw_exception<TypeError>(
"object",
type(), mergeObj.
type());
863 for (
const auto&
pair : mergeObj.
items()) {
870 throw_exception<TypeError>(
"object",
type(), mergeObj1.
type());
874 for (
const auto&
pair : mergeObj1.
items()) {
875 if ((*this).find(
pair.first) == (*this).items().end()) {
892 if (
pair.second.isNull()) {
894 auto it =
self.find(
pair.first);
899 self[
pair.first].merge_patch(
pair.second);
910 auto ret = mergeObj2;
915 template <
typename K>
918 auto& obj = get<ObjectImpl>();
919 return obj.erase(std::forward<K>(key));
922 auto& obj = get<ObjectImpl>();
923 return obj.erase(key);
927 auto& arr = get<Array>();
931 return get<Array>().
erase(arr.begin() + (it - arr.begin()));
965 auto& arr = get<Array>();
970 auto& arr = get<Array>();
975 auto& arr = get<Array>();
980 auto& arr = get<Array>();
990 #define FOLLY_DYNAMIC_DEC_TYPEINFO(T, str, val) \ 992 struct dynamic::TypeInfo<T> { \ 993 static constexpr const char* name = str; \ 994 static constexpr dynamic::Type type = val; \ 1006 #undef FOLLY_DYNAMIC_DEC_TYPEINFO 1012 return to<T>(*get_nothrow<int64_t>());
1014 return to<T>(*get_nothrow<double>());
1016 return to<T>(*get_nothrow<bool>());
1018 return to<T>(*get_nothrow<std::string>());
1020 throw_exception<TypeError>(
"int/double/bool/string",
type());
1031 return getAddress<T>();
1037 return const_cast<dynamic*
>(
this)->get_nothrow<T>();
1049 return const_cast<dynamic*
>(
this)->getAddress<T>();
1094 "In your implementation, F14NodeMap<> apparently takes different" 1095 " amount of space depending on its template parameters. This is " 1096 "weird. Make objectBuffer bigger if you want to compile dynamic.");
1099 void*
data = &d.objectBuffer;
1100 return static_cast<ObjectImpl*
>(
data);
1106 if (
auto* p = get_nothrow<T>()) {
1114 return const_cast<dynamic*
>(
this)->get<T>();
1153 #define FB_X(T) PrintImpl<T>::print(*this, out, *getAddress<T>()) 1171 template <
class FormatCallback>
1173 switch (val_.type()) {
1208 template <
class FormatCallback>
1210 auto&
c = val_.container;
1221 if (key >= 0 &&
size_t(key) <
c.size()) {
1230 if (pos !=
c.items().end()) {
1246 #undef FB_DYNAMIC_APPLY dynamic & dereference() const
IterableProxy< const_value_iterator > values() const
const_key_iterator(dynamic::ObjectImpl::const_iterator b)
const char * data() const &
static ObjectMaker object()
std::vector< dynamic > Array
StringPiece stringPiece() const
IfIsNonStringDynamicConvertible< K, dynamic > getDefault(K &&k, const dynamic &v=dynamic::object) const &
static bool comp(ObjectImpl const &, ObjectImpl const &)
dynamic const & atImpl(dynamic const &) const &
double getDouble() const &
#define FOLLY_DYNAMIC_DEC_TYPEINFO(T, str, val)
item_iterator(dynamic::ObjectImpl::iterator b)
static bool comp(T const &a, T const &b)
dynamic & operator/=(dynamic const &)
std::enable_if_t< std::is_convertible< A, StringPiece >::value, bool > operator()(A const &lhs, dynamic const &rhs) const
std::aligned_storage< sizeof(F14NodeMap< int, int >), alignof(F14NodeMap< int, int >)>::type objectBuffer
#define FB_DYNAMIC_INTEGER_OP(op)
static void print(dynamic const &d, std::ostream &out, dynamic::Array const &)
T * getAddress() noexcept
constexpr detail::Map< Move > move
size_t operator()(::folly::dynamic const &d) const
std::enable_if_t< !std::is_convertible< K, StringPiece >::value &&std::is_convertible< K, dynamic >::value, T > IfIsNonStringDynamicConvertible
constexpr size_type size() const
IfIsNonStringDynamicConvertible< K, std::size_t > count(K &&) const
bool operator()(const dynamic &lhs, const dynamic &rhs) const
const std::string & getString() const &
const_item_iterator(dynamic::ObjectImpl::const_iterator b)
union folly::dynamic::Data u_
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
static bool comp(std::nullptr_t const &, std::nullptr_t const &)
—— Concurrent Priority Queue Implementation ——
IfIsNonStringDynamicConvertible< K, dynamic & > setDefault(K &&k, V &&v)
requires E e noexcept(noexcept(s.error(std::move(e))))
const_value_iterator(value_iterator i)
static void print(dynamic const &d, std::ostream &out, dynamic::ObjectImpl const &)
const_value_iterator(dynamic::ObjectImpl::const_iterator b)
It::value_type value_type
#define FB_DYNAMIC_APPLY(type, apply)
FOLLY_PUSH_WARNING RHS rhs
static dynamic merge(const dynamic &mergeObj1, const dynamic &mergeObj2)
IfIsNonStringDynamicConvertible< K, dynamic & > operator[](K &&)&
dynamic const & dereference() const
const dynamic * get_ptrImpl(dynamic const &) const &
std::string asString() const
constexpr Iter data() const
ObjectMaker(dynamic key, dynamic val)
void insert(K &&, V &&val)
const_item_iterator(item_iterator i)
IfIsNonStringDynamicConvertible< K, const_item_iterator > find(K &&) const
It::object_type object_type
void print_as_pseudo_json(std::ostream &) const
void push_back(dynamic const &)
static const char *const value
const_value_iterator(dynamic::ObjectImpl::iterator i)
IfIsNonStringDynamicConvertible< K, std::size_t > erase(K &&)
dynamic const & dereference() const
dynamic & operator*=(dynamic const &)
IterableProxy< const_key_iterator > keys() const
std::string toString() const
dynamic & operator+=(dynamic const &)
dynamic & operator-=(dynamic const &)
void update(const dynamic &mergeObj)
IterableProxy< const_item_iterator > items() const
static void print(dynamic const &, std::ostream &out, std::nullptr_t const &)
static void print(dynamic const &, std::ostream &out, T const &t)
static void array(EmptyArrayTag)
value_iterator(dynamic::ObjectImpl::iterator b)
Formatter< false, Args... > format(StringPiece fmt, Args &&...args)
IfIsNonStringDynamicConvertible< K, dynamic const & > at(K &&) const &
IterableProxy(object_type *o)
std::enable_if_t< std::is_convertible< T, StringPiece >::value, size_t > operator()(T const &val) const
dynamic::ObjectImpl const object_type
std::conditional_t< std::is_same< std::vector< bool >::const_reference, bool >::value, VectorBoolConstRefFake, std::vector< bool >::const_reference > VectorBoolConstRefCtorType
friend std::ostream & operator<<(std::ostream &, dynamic const &)
std::enable_if_t< std::is_convertible< B, StringPiece >::value, bool > operator()(dynamic const &lhs, B const &rhs) const
dynamic::ObjectImpl const object_type
void update_missing(const dynamic &other)
const_iterator begin() const
Array::const_iterator const_iterator
PUSHMI_INLINE_VAR constexpr detail::get_fn< T > get
static void destroy(T *t)
dynamic::ObjectImpl const object_type
void merge_patch(const dynamic &patch)
dynamic numericOp(dynamic const &a, dynamic const &b)
void print(std::ostream &) const
void resize(std::size_t n, dynamic const &=nullptr)
T * get_nothrow()&noexcept
const_item_iterator(const_item_iterator const &i)
size_t operator()(dynamic const &d) const
const_iterator end() const
const dynamic * get_ptr(json_pointer const &) const &
ObjectMaker && operator()(dynamic key, dynamic val)
constexpr detail::First first
const char * c_str() const &