/*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2015 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* These will throw a TypeError if the dynamic has a different type.
*/
- const fbstring& getString() const;
- double getDouble() const;
- int64_t getInt() const;
- bool getBool() const;
- fbstring& getString();
- double& getDouble();
- int64_t& getInt();
- bool& getBool();
+ const fbstring& getString() const&;
+ double getDouble() const&;
+ int64_t getInt() const&;
+ bool getBool() const&;
+ fbstring& getString() &;
+ double& getDouble() &;
+ int64_t& getInt() &;
+ bool& getBool() &;
+ fbstring getString() &&;
+ double getDouble() &&;
+ int64_t getInt() &&;
+ bool getBool() &&;
/*
* It is occasionally useful to access a string's internal pointer
*
* These will throw a TypeError if the dynamic is not a string.
*/
- const char* data() const;
- const char* c_str() const;
+ const char* data() const&;
+ const char* data() && = delete;
+ const char* c_str() const&;
+ const char* c_str() && = delete;
StringPiece stringPiece() const;
/*
* will throw a TypeError. Using an index that is out of range or
* object-element that's not present throws std::out_of_range.
*/
- dynamic const& at(dynamic const&) const;
- dynamic& at(dynamic const&);
+ dynamic const& at(dynamic const&) const&;
+ dynamic& at(dynamic const&) &;
+ dynamic at(dynamic const&) &&;
/*
* Like 'at', above, except it returns either a pointer to the contained
* Using these with dynamic objects that are not arrays or objects
* will throw a TypeError.
*/
- const dynamic* get_ptr(dynamic const&) const;
- dynamic* get_ptr(dynamic const&);
+ const dynamic* get_ptr(dynamic const&) const&;
+ dynamic* get_ptr(dynamic const&) &;
+ dynamic* get_ptr(dynamic const&) && = delete;
/*
* This works for access to both objects and arrays.
*
* These functions do not invalidate iterators.
*/
- dynamic& operator[](dynamic const&);
- dynamic const& operator[](dynamic const&) const;
+ dynamic& operator[](dynamic const&) &;
+ dynamic const& operator[](dynamic const&) const&;
+ dynamic operator[](dynamic const&) &&;
/*
* Only defined for objects, throws TypeError otherwise.
* a reference to the existing value if present, the new value otherwise.
*/
dynamic
- getDefault(const dynamic& k, const dynamic& v = dynamic::object) const;
- dynamic&& getDefault(const dynamic& k, dynamic&& v) const;
+ getDefault(const dynamic& k, const dynamic& v = dynamic::object) const&;
+ 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<class K, class V = dynamic>
dynamic& setDefault(K&& k, V&& v = dynamic::object);
*/
template<class K, class V> void insert(K&&, V&& val);
+ /*
+ * These functions merge two folly dynamic objects.
+ * The "update" and "update_missing" functions extend the object by
+ * inserting the key/value pairs of mergeObj into the current object.
+ * For update, if key is duplicated between the two objects, it
+ * will overwrite with the value of the object being inserted (mergeObj).
+ * For "update_missing", it will prefer the value in the original object
+ *
+ * The "merge" function creates a new object consisting of the key/value
+ * pairs of both mergeObj1 and mergeObj2
+ * If the key is duplicated between the two objects,
+ * it will prefer value in the second object (mergeObj2)
+ */
+ void update(const dynamic& mergeObj);
+ void update_missing(const dynamic& other);
+ static dynamic merge(const dynamic& mergeObj1, const dynamic& mergeObj2);
+
/*
* Erase an element from a dynamic object, by key.
*
template<class T> T const& get() const;
template<class T> T& get();
- template<class T> T* get_nothrow() noexcept;
- template<class T> T const* get_nothrow() const noexcept;
+ template<class T> T* get_nothrow() & noexcept;
+ template<class T> T const* get_nothrow() const& noexcept;
+ template<class T> T* get_nothrow() && noexcept = delete;
template<class T> T* getAddress() noexcept;
template<class T> T const* getAddress() const noexcept;
* incomplete type right now). (Note that in contrast we know it
* is ok to do this with fbvector because we own it.)
*/
- typename std::aligned_storage<
+ std::aligned_storage<
sizeof(std::unordered_map<int,int>),
alignof(std::unordered_map<int,int>)
>::type objectBuffer;