added iOS source code
[wl-app.git] / iOS / Pods / Realm / include / core / realm / util / to_string.hpp
diff --git a/iOS/Pods/Realm/include/core/realm/util/to_string.hpp b/iOS/Pods/Realm/include/core/realm/util/to_string.hpp
new file mode 100644 (file)
index 0000000..c3fac65
--- /dev/null
@@ -0,0 +1,126 @@
+/*************************************************************************
+ *
+ * Copyright 2016 Realm Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ **************************************************************************/
+
+#ifndef REALM_UTIL_TO_STRING_HPP
+#define REALM_UTIL_TO_STRING_HPP
+
+#include <iosfwd>
+#include <string>
+
+namespace realm {
+namespace util {
+
+class Printable {
+public:
+    Printable(bool value)
+        : m_type(Type::Bool)
+        , m_uint(value)
+    {
+    }
+    Printable(unsigned char value)
+        : m_type(Type::Uint)
+        , m_uint(value)
+    {
+    }
+    Printable(unsigned int value)
+        : m_type(Type::Uint)
+        , m_uint(value)
+    {
+    }
+    Printable(unsigned long value)
+        : m_type(Type::Uint)
+        , m_uint(value)
+    {
+    }
+    Printable(unsigned long long value)
+        : m_type(Type::Uint)
+        , m_uint(value)
+    {
+    }
+    Printable(char value)
+        : m_type(Type::Int)
+        , m_int(value)
+    {
+    }
+    Printable(int value)
+        : m_type(Type::Int)
+        , m_int(value)
+    {
+    }
+    Printable(long value)
+        : m_type(Type::Int)
+        , m_int(value)
+    {
+    }
+    Printable(long long value)
+        : m_type(Type::Int)
+        , m_int(value)
+    {
+    }
+    Printable(const char* value)
+        : m_type(Type::String)
+        , m_string(value)
+    {
+    }
+    Printable(std::string const& value)
+        : m_type(Type::String)
+        , m_string(value.c_str())
+    {
+    }
+
+
+    void print(std::ostream& out, bool quote) const;
+    std::string str() const;
+
+    static void print_all(std::ostream& out, const std::initializer_list<Printable>& values, bool quote);
+
+private:
+    enum class Type {
+        Bool,
+        Int,
+        Uint,
+        String,
+    } m_type;
+
+    union {
+        uintmax_t m_uint;
+        intmax_t m_int;
+        const char* m_string;
+    };
+};
+
+
+template <class T>
+std::string to_string(const T& v)
+{
+    return Printable(v).str();
+}
+
+std::string format(const char* fmt, std::initializer_list<Printable>);
+
+template<typename... Args>
+std::string format(const char* fmt, Args&&... args)
+{
+    return format(fmt, {Printable(args)...});
+}
+
+
+} // namespace util
+} // namespace realm
+
+#endif // REALM_UTIL_TO_STRING_HPP