Fix HHWheelTimer compilation bug in libc++ build
[folly.git] / folly / dynamic.h
index 8a0178520e09f7921779f3961b8f8bdcd30afe56..906059ca13ee038f50255f8ac0dc218337309dc1 100644 (file)
 #ifndef FOLLY_DYNAMIC_H_
 #define FOLLY_DYNAMIC_H_
 
-#include <unordered_map>
+#include <cstdint>
+#include <initializer_list>
 #include <memory>
-#include <string>
-#include <utility>
 #include <ostream>
+#include <string>
 #include <type_traits>
-#include <initializer_list>
+#include <unordered_map>
+#include <utility>
 #include <vector>
-#include <cstdint>
+
 #include <boost/operators.hpp>
 
-#include "folly/Traits.h"
-#include "folly/FBString.h"
+#include <folly/FBString.h>
+#include <folly/Range.h>
+#include <folly/Traits.h>
 
 namespace folly {
 
@@ -110,6 +112,7 @@ private:
   typedef std::vector<dynamic> Array;
 public:
   typedef Array::const_iterator const_iterator;
+  typedef dynamic value_type;
   struct const_key_iterator;
   struct const_value_iterator;
   struct const_item_iterator;
@@ -142,8 +145,11 @@ public:
   /*
    * String compatibility constructors.
    */
+  /* implicit */ dynamic(StringPiece val);
   /* implicit */ dynamic(char const* val);
   /* implicit */ dynamic(std::string const& val);
+  /* implicit */ dynamic(fbstring const& val);
+  /* implicit */ dynamic(fbstring&& val);
 
   /*
    * This is part of the plumbing for object(), above.  Used to create
@@ -174,8 +180,8 @@ public:
   template<class Iterator> dynamic(Iterator first, Iterator last);
 
   dynamic(dynamic const&);
-  dynamic(dynamic&&);
-  ~dynamic();
+  dynamic(dynamic&&) noexcept;
+  ~dynamic() noexcept;
 
   /*
    * "Deep" equality comparison.  This will compare all the way down
@@ -217,7 +223,7 @@ public:
    * Basic guarantee only.
    */
   dynamic& operator=(dynamic const&);
-  dynamic& operator=(dynamic&&);
+  dynamic& operator=(dynamic&&) noexcept;
 
   /*
    * For simple dynamics (not arrays or objects), this prints the
@@ -272,6 +278,20 @@ public:
   int64_t  asInt() const;
   bool     asBool() const;
 
+  /*
+   * Extract the value stored in this dynamic without type conversion.
+   *
+   * 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();
+
   /*
    * It is occasionally useful to access a string's internal pointer
    * directly, without the type conversion of `asString()`.
@@ -280,6 +300,7 @@ public:
    */
   const char* data()  const;
   const char* c_str() const;
+  StringPiece stringPiece() const;
 
   /*
    * Returns: true if this dynamic is null, an empty array, an empty
@@ -325,7 +346,6 @@ public:
    */
   const_item_iterator find(dynamic const&) const;
 
-
   /*
    * If this is an object, returns whether it contains a field with
    * the given name.  Otherwise throws TypeError.
@@ -474,15 +494,15 @@ private:
 
   template<class T> T const& get() const;
   template<class T> T&       get();
-  template<class T> T*       get_nothrow();
-  template<class T> T const* get_nothrow() const;
-  template<class T> T*       getAddress();
-  template<class T> T const* getAddress() const;
+  template<class T> T*       get_nothrow() noexcept;
+  template<class T> T const* get_nothrow() const noexcept;
+  template<class T> T*       getAddress() noexcept;
+  template<class T> T const* getAddress() const noexcept;
 
   template<class T> T asImpl() const;
 
   static char const* typeName(Type);
-  void destroy();
+  void destroy() noexcept;
   void print(std::ostream&) const;
   void print_as_pseudo_json(std::ostream&) const; // see json.cpp
 
@@ -519,6 +539,6 @@ private:
 
 }
 
-#include "folly/dynamic-inl.h"
+#include <folly/dynamic-inl.h>
 
 #endif