added iOS source code
[wl-app.git] / iOS / Pods / Realm / include / core / realm / util / serializer.hpp
1 /*************************************************************************
2  *
3  * Copyright 2016 Realm Inc.
4  *
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
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  **************************************************************************/
18
19 #ifndef REALM_UTIL_SERIALIZER_HPP
20 #define REALM_UTIL_SERIALIZER_HPP
21
22 #include <realm/util/optional.hpp>
23
24 #include <string>
25 #include <sstream>
26
27 namespace realm {
28
29 class BinaryData;
30 struct null;
31 class StringData;
32 class Timestamp;
33
34 namespace util {
35 namespace serializer {
36
37
38 // Definitions
39 template <typename T>
40 std::string print_value(T value);
41
42 template <typename T>
43 std::string print_value(Optional<T> value);
44
45 const static std::string value_separator = ".";
46
47 // Specializations declared here to be defined in the cpp file
48 template <> std::string print_value<>(BinaryData);
49 template <> std::string print_value<>(bool);
50 template <> std::string print_value<>(realm::null);
51 template <> std::string print_value<>(StringData);
52 template <> std::string print_value<>(realm::Timestamp);
53
54 // General implementation for most types
55 template <typename T>
56 std::string print_value(T value)
57 {
58     std::stringstream ss;
59     ss << value;
60     return ss.str();
61 }
62
63 template <typename T>
64 std::string print_value(Optional<T> value)
65 {
66     if (bool(value)) {
67         return print_value(*value);
68     } else {
69         return "NULL";
70     }
71 }
72
73 } // namespace serializer
74 } // namespace util
75 } // namespace realm
76
77 #endif // REALM_UTIL_SERIALIZER_HPP