Apache Ignite C++
binary_enum.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_ENUM
25 #define _IGNITE_BINARY_BINARY_ENUM
26 
27 #include <stdint.h>
28 
29 #include <ignite/common/common.h>
30 
32 
33 namespace ignite
34 {
35  namespace binary
36  {
53  template<typename T>
54  struct BinaryEnum { };
55 
59  template<typename T>
61  {
67  static int32_t GetTypeId()
68  {
69  std::string typeName;
71 
72  return GetBinaryStringHashCode(typeName.c_str());
73  }
74 
80  static int32_t GetOrdinal(T value)
81  {
82  return static_cast<int32_t>(value);
83  }
84 
90  static T FromOrdinal(int32_t ordinal)
91  {
92  return static_cast<T>(ordinal);
93  }
94  };
95 
99  template<typename T>
101  {
107  static bool IsNull(const T& val)
108  {
109  return val == BinaryEnum<T>::FromOrdinal(INT32_MIN);
110  }
111 
117  static void GetNull(T& dst)
118  {
119  dst = BinaryEnum<T>::FromOrdinal(INT32_MIN);
120  }
121  };
122 
126  template<typename T>
129  BinaryEnumIntMinNull<T> { };
130 
134  template <typename T>
135  struct BinaryEnum<T*>
136  {
139 
145  static int32_t GetTypeId()
146  {
147  return BinaryEnumDereferenced::GetTypeId();
148  }
149 
155  static void GetTypeName(std::string& dst)
156  {
157  BinaryEnumDereferenced::GetTypeName(dst);
158  }
159 
165  static int32_t GetOrdinal(T* value)
166  {
167  return BinaryEnumDereferenced::GetOrdinal(*value);
168  }
169 
175  static T* FromOrdinal(int32_t ordinal)
176  {
177  return new T(BinaryEnumDereferenced::FromOrdinal(ordinal));
178  }
179 
186  static bool IsNull(T* const& obj)
187  {
188  return !obj || BinaryEnumDereferenced::IsNull(*obj);
189  }
190 
196  static void GetNull(T*& dst)
197  {
198  dst = 0;
199  }
200  };
201  }
202 }
203 
204 #endif //_IGNITE_BINARY_BINARY_ENUM
ignite
Apache Ignite API.
Definition: cache.h:48
ignite::binary::BinaryEnum
Binary enum structure.
Definition: binary_enum.h:54
ignite::binary::BinaryEnumIntMinNull::IsNull
static bool IsNull(const T &val)
Check whether passed binary object should be interpreted as NULL.
Definition: binary_enum.h:107
ignite::binary::BinaryEnum< T * >::GetOrdinal
static int32_t GetOrdinal(T *value)
Get enum type ordinal.
Definition: binary_enum.h:165
ignite::binary::BinaryEnumIntMinNull::GetNull
static void GetNull(T &dst)
Get NULL value for the given binary type.
Definition: binary_enum.h:117
ignite::binary::BinaryEnumDefault
Default implementations of BinaryEnum.
Definition: binary_enum.h:60
ignite::binary::BinaryEnumDefault::GetTypeId
static int32_t GetTypeId()
Get type ID for the enum type.
Definition: binary_enum.h:67
ignite::binary::BinaryEnumDefault::GetOrdinal
static int32_t GetOrdinal(T value)
Get enum type ordinal.
Definition: binary_enum.h:80
ignite::binary::BinaryEnumIntMinNull
Implementations of BinaryEnum nullability when INT32_MIN ordinal value used as a NULL indicator.
Definition: binary_enum.h:100
ignite::binary::BinaryEnum< T * >::IsNull
static bool IsNull(T *const &obj)
Check whether passed enum should be interpreted as NULL.
Definition: binary_enum.h:186
ignite::binary::BinaryEnum< T * >::BinaryEnumDereferenced
BinaryEnum< T > BinaryEnumDereferenced
Actual type.
Definition: binary_enum.h:138
ignite::binary::BinaryEnum< T * >::GetTypeId
static int32_t GetTypeId()
Get binary object type ID.
Definition: binary_enum.h:145
ignite::binary::GetBinaryStringHashCode
IGNITE_IMPORT_EXPORT int32_t GetBinaryStringHashCode(const char *val)
Get binary string hash code.
Definition: binary_type.cpp:25
ignite::binary::BinaryEnumDefault::FromOrdinal
static T FromOrdinal(int32_t ordinal)
Get enum value for the given ordinal value.
Definition: binary_enum.h:90
binary_type.h
ignite::binary::BinaryEnum< T * >::GetNull
static void GetNull(T *&dst)
Get NULL value for the enum type.
Definition: binary_enum.h:196
ignite::binary::BinaryEnum< T * >::FromOrdinal
static T * FromOrdinal(int32_t ordinal)
Get enum value for the given ordinal value.
Definition: binary_enum.h:175
ignite::binary::BinaryEnumDefaultAll
Default implementations of BinaryType hashing functions and non-null type behaviour.
Definition: binary_enum.h:127
ignite::binary::BinaryEnum< T * >::GetTypeName
static void GetTypeName(std::string &dst)
Get binary object type name.
Definition: binary_enum.h:155