Apache Ignite C++
binary_type.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 
24 #ifndef _IGNITE_BINARY_BINARY_TYPE
25 #define _IGNITE_BINARY_BINARY_TYPE
26 
27 #include <stdint.h>
28 
29 #include <ignite/common/common.h>
30 
31 #include <ignite/impl/binary/binary_type_impl.h>
32 
37 #define IGNITE_BINARY_TYPE_START(T) \
38 template<> \
39 struct BinaryType<T> \
40 {
41 
46 #define IGNITE_BINARY_TYPE_END \
47 };
48 
53 #define IGNITE_BINARY_GET_TYPE_ID_AS_CONST(id) \
54 static int32_t GetTypeId() \
55 { \
56  return id; \
57 }
58 
63 #define IGNITE_BINARY_GET_TYPE_ID_AS_HASH(typeName) \
64 static int32_t GetTypeId() \
65 { \
66  return GetBinaryStringHashCode(#typeName); \
67 }
68 
73 #define IGNITE_BINARY_GET_TYPE_NAME_AS_IS(typeName) \
74 static void GetTypeName(std::string& dst) \
75 { \
76  dst = #typeName; \
77 }
78 
83 #define IGNITE_BINARY_GET_FIELD_ID_AS_HASH \
84 static int32_t GetFieldId(const char* name) \
85 { \
86  return GetBinaryStringHashCode(name); \
87 }
88 
93 #define IGNITE_BINARY_IS_NULL_FALSE(T) \
94 static bool IsNull(const T& obj) \
95 { \
96  return false; \
97 }
98 
103 #define IGNITE_BINARY_IS_NULL_IF_NULLPTR(T) \
104 static bool IsNull(const T& obj) \
105 { \
106  return obj; \
107 }
108 
113 #define IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(T) \
114 static void GetNull(T& dst) \
115 { \
116  dst = T(); \
117 }
118 
123 #define IGNITE_BINARY_GET_NULL_NULLPTR(T) \
124 static void GetNull(T& dst) \
125 { \
126  dst = 0; \
127 }
128 
129 
130 namespace ignite
131 {
132  namespace binary
133  {
134  class BinaryWriter;
135  class BinaryReader;
136 
143  IGNITE_IMPORT_EXPORT int32_t GetBinaryStringHashCode(const char* val);
144 
148  template<typename T>
149  struct IGNITE_IMPORT_EXPORT BinaryType { };
150 
154  template <typename T>
155  struct IGNITE_IMPORT_EXPORT BinaryType<T*>
156  {
159 
165  static int32_t GetTypeId()
166  {
167  return BinaryTypeDereferenced::GetTypeId();
168  }
169 
175  static void GetTypeName(std::string& dst)
176  {
177  BinaryTypeDereferenced::GetTypeName(dst);
178  }
179 
186  static int32_t GetFieldId(const char* name)
187  {
188  return BinaryTypeDereferenced::GetFieldId(name);
189  }
190 
197  static void Write(BinaryWriter& writer, T* const& obj)
198  {
199  BinaryTypeDereferenced::Write(writer, *obj);
200  }
201 
208  static void Read(BinaryReader& reader, T*& dst)
209  {
210  dst = new T();
211 
212  BinaryTypeDereferenced::Read(reader, *dst);
213  }
214 
221  static bool IsNull(T* const& obj)
222  {
223  return !obj || BinaryTypeDereferenced::IsNull(*obj);
224  }
225 
231  static void GetNull(T*& dst)
232  {
233  dst = 0;
234  }
235  };
236  }
237 }
238 
239 #endif //_IGNITE_BINARY_BINARY_TYPE
static void GetNull(T *&dst)
Get NULL value for the given binary type.
Definition: binary_type.h:231
IGNITE_IMPORT_EXPORT int32_t GetBinaryStringHashCode(const char *val)
Get binary string hash code.
Definition: binary_type.cpp:24
static int32_t GetTypeId()
Get binary object type ID.
Definition: binary_type.h:165
BinaryType< T > BinaryTypeDereferenced
Actual type.
Definition: binary_type.h:158
static int32_t GetFieldId(const char *name)
Get binary object field ID.
Definition: binary_type.h:186
static bool IsNull(T *const &obj)
Check whether passed binary object should be interpreted as NULL.
Definition: binary_type.h:221
Binary writer.
Definition: binary_writer.h:51
static void GetTypeName(std::string &dst)
Get binary object type name.
Definition: binary_type.h:175
Binary type structure.
Definition: binary_type.h:149
static void Read(BinaryReader &reader, T *&dst)
Read binary object.
Definition: binary_type.h:208
static void Write(BinaryWriter &writer, T *const &obj)
Write binary object.
Definition: binary_type.h:197
Apache Ignite API.
Definition: cache.h:48
Binary reader.
Definition: binary_reader.h:54