X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Fdynamic.h;h=d793c0638f22eeb6b5a8dd3d5b215446d7301db6;hb=908667879945d22a2f026559cbd4c5d9cc0bebaa;hp=1c9ac0e0fea563eb7c526a7898f1479434a75e1e;hpb=73182f6ef64011e8b2493b171d0ae448c89a6178;p=folly.git diff --git a/folly/dynamic.h b/folly/dynamic.h index 1c9ac0e0..d793c063 100644 --- a/folly/dynamic.h +++ b/folly/dynamic.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2011-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -85,7 +85,7 @@ struct dynamic : private boost::operators { OBJECT, STRING, }; - template struct NumericTypeHelper; + template struct NumericTypeHelper; /* * We support direct iteration of arrays, and indirect iteration of objects. @@ -96,9 +96,10 @@ struct dynamic : private boost::operators { * Object value iterators dereference as the values in the object. * Object item iterators dereference as pairs of (key, value). */ -private: + private: typedef std::vector Array; -public: + + public: typedef Array::iterator iterator; typedef Array::const_iterator const_iterator; typedef dynamic value_type; @@ -129,11 +130,11 @@ public: * d["key"] = 12; * d["something_else"] = dynamic::array(1, 2, 3, nullptr); */ -private: + private: struct EmptyArrayTag {}; struct ObjectMaker; -public: + public: static void array(EmptyArrayTag); template static dynamic array(Args&& ...args); @@ -167,14 +168,14 @@ public: * Constructors for integral and float types. * Other types are SFINAEd out with NumericTypeHelper. */ - template::type> + template ::type> /* implicit */ dynamic(T t); /* * Create a dynamic that is an array of the values from the supplied * iterator range. */ - template + template explicit dynamic(Iterator first, Iterator last); dynamic(dynamic const&); @@ -328,13 +329,13 @@ public: iterator begin(); iterator end(); -private: + private: /* * Helper object returned by keys(), values(), and items(). */ template struct IterableProxy; -public: + public: /* * You can iterate over the keys, values, or items (std::pair of key and * value) in an object. Calling these on non-objects will throw a TypeError. @@ -417,15 +418,15 @@ public: dynamic getDefault(const dynamic& k, dynamic&& v) const&; dynamic getDefault(const dynamic& k, const dynamic& v = dynamic::object) &&; dynamic getDefault(const dynamic& k, dynamic&& v) &&; - template + template dynamic& setDefault(K&& k, V&& v); // MSVC 2015 Update 3 needs these extra overloads because if V were a // defaulted template parameter, it causes MSVC to consider v an rvalue // reference rather than a universal reference, resulting in it not being // able to find the correct overload to construct a dynamic with. - template + template dynamic& setDefault(K&& k, dynamic&& v); - template + template dynamic& setDefault(K&& k, const dynamic& v = dynamic::object); /* @@ -445,7 +446,7 @@ public: * * Invalidates iterators. */ - template void insert(K&&, V&& val); + template void insert(K&&, V&& val); /* * These functions merge two folly dynamic objects. @@ -521,40 +522,38 @@ public: */ std::size_t hash() const; -private: + private: friend struct TypeError; struct ObjectImpl; - template struct TypeInfo; - template struct CompareOp; - template struct GetAddrImpl; - template struct PrintImpl; + template struct TypeInfo; + template struct CompareOp; + template struct GetAddrImpl; + template struct PrintImpl; explicit dynamic(Array&& array); - template T const& get() const; - template T& get(); - template T* get_nothrow() & noexcept; - template T const* get_nothrow() const& noexcept; - template T* get_nothrow() && noexcept = delete; - template T* getAddress() noexcept; - template T const* getAddress() const noexcept; + template T const& get() const; + template T& get(); + template T* get_nothrow() & noexcept; + template T const* get_nothrow() const& noexcept; + template T* get_nothrow() && noexcept = delete; + template T* getAddress() noexcept; + template T const* getAddress() const noexcept; - template T asImpl() const; + template T asImpl() const; static char const* typeName(Type); void destroy() noexcept; void print(std::ostream&) const; void print_as_pseudo_json(std::ostream&) const; // see json.cpp -private: + private: Type type_; union Data { explicit Data() : nul(nullptr) {} ~Data() {} - // XXX: gcc does an ICE if we use std::nullptr_t instead of void* - // here. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50361 - void* nul; + std::nullptr_t nul; Array array; bool boolean; double doubl; @@ -577,6 +576,6 @@ private: ////////////////////////////////////////////////////////////////////// -} +} // namespace folly #include