1 /*************************************************************************
3 * Copyright 2016 Realm Inc.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 **************************************************************************/
19 #ifndef REALM_UTIL_TO_STRING_HPP
20 #define REALM_UTIL_TO_STRING_HPP
35 Printable(unsigned char value)
40 Printable(unsigned int value)
45 Printable(unsigned long value)
50 Printable(unsigned long long value)
70 Printable(long long value)
75 Printable(const char* value)
76 : m_type(Type::String)
80 Printable(std::string const& value)
81 : m_type(Type::String)
82 , m_string(value.c_str())
87 void print(std::ostream& out, bool quote) const;
88 std::string str() const;
90 static void print_all(std::ostream& out, const std::initializer_list<Printable>& values, bool quote);
103 const char* m_string;
109 std::string to_string(const T& v)
111 return Printable(v).str();
114 std::string format(const char* fmt, std::initializer_list<Printable>);
116 template<typename... Args>
117 std::string format(const char* fmt, Args&&... args)
119 return format(fmt, {Printable(args)...});
126 #endif // REALM_UTIL_TO_STRING_HPP