Blame view

Pods/Realm/include/core/realm/util/serializer.hpp 3.18 KB
75d24c15   yangbin   123
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  /*************************************************************************
   *
   * 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_SERIALIZER_HPP
  #define REALM_UTIL_SERIALIZER_HPP
  
  #include <realm/table_ref.hpp>
  #include <realm/util/optional.hpp>
  
  #include <string>
  #include <sstream>
  #include <vector>
  
  namespace realm {
  
  class BinaryData;
  struct ColKey;
  struct null;
  class ObjectId;
  struct ObjKey;
  struct ObjLink;
  class StringData;
  class Timestamp;
  class LinkMap;
  class UUID;
  class TypeOfValue;
  enum class ExpressionComparisonType : unsigned char;
  
  namespace util {
  namespace serializer {
  
  
  // Definitions
  template <typename T>
  std::string print_value(T value);
  
  template <typename T>
  std::string print_value(Optional<T> value);
  
  const static std::string value_separator = ".";
  
  // Specializations declared here to be defined in the cpp file
  template <> std::string print_value<>(BinaryData);
  template <> std::string print_value<>(bool);
  template <>
  std::string print_value<>(float);
  template <>
  std::string print_value<>(double);
  template <> std::string print_value<>(realm::null);
  template <> std::string print_value<>(StringData);
  template <> std::string print_value<>(realm::Timestamp);
  template <>
  std::string print_value<>(realm::ObjectId);
  template <>
  std::string print_value<>(realm::ObjKey);
  template <>
  std::string print_value<>(realm::ObjLink);
  template <>
  std::string print_value<>(realm::UUID);
  template <>
  std::string print_value<>(realm::TypeOfValue);
  
  // General implementation for most types
  template <typename T>
  std::string print_value(T value)
  {
      std::stringstream ss;
      ss << value;
      return ss.str();
  }
  
  template <typename T>
  std::string print_value(Optional<T> value)
  {
      if (bool(value)) {
          return print_value(*value);
      } else {
          return "NULL";
      }
  }
  
  StringData get_printable_table_name(StringData name, const std::string& prefix);
  
  struct SerialisationState {
      SerialisationState(const std::string& prefix)
          : class_prefix(prefix)
      {
      }
      std::string describe_column(ConstTableRef table, ColKey col_key);
      std::string describe_columns(const LinkMap& link_map, ColKey target_col_key);
      std::string describe_expression_type(ExpressionComparisonType type);
      std::string get_column_name(ConstTableRef table, ColKey col_key);
      std::string get_backlink_column_name(ConstTableRef from, ColKey col_key);
      std::string get_variable_name(ConstTableRef table);
      std::vector<std::string> subquery_prefix_list;
      std::string class_prefix;
  };
  
  } // namespace serializer
  } // namespace util
  } // namespace realm
  
  #endif // REALM_UTIL_SERIALIZER_HPP