Avro C++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
AvroTraits.hh
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef avro_AvroTraits_hh__
20 #define avro_AvroTraits_hh__
21 
22 #include "Config.hh"
23 #include "Boost.hh"
24 #include "Types.hh"
25 
30 
31 namespace avro {
32 
33 template <typename T>
35 
36 template <typename T>
37 struct is_promotable : public boost::false_type{};
38 
39 template <typename T>
40 struct type_to_avro {
41  static const Type type = AVRO_NUM_TYPES;
42 };
43 
44 #define DEFINE_PRIMITIVE(CTYPE, AVROTYPE) \
45 template <> \
46 struct is_serializable<CTYPE> : public boost::true_type{}; \
47 \
48 template <> \
49 struct type_to_avro<CTYPE> { \
50  static const Type type = AVROTYPE; \
51 };
52 
53 #define DEFINE_PROMOTABLE_PRIMITIVE(CTYPE, AVROTYPE) \
54 template <> \
55 struct is_promotable<CTYPE> : public boost::true_type{}; \
56 \
57 DEFINE_PRIMITIVE(CTYPE, AVROTYPE)
58 
59 DEFINE_PROMOTABLE_PRIMITIVE(int32_t, AVRO_INT)
60 DEFINE_PROMOTABLE_PRIMITIVE(int64_t, AVRO_LONG)
61 DEFINE_PROMOTABLE_PRIMITIVE(float, AVRO_FLOAT)
62 DEFINE_PRIMITIVE(double, AVRO_DOUBLE)
63 DEFINE_PRIMITIVE(bool, AVRO_BOOL)
64 DEFINE_PRIMITIVE(Null, AVRO_NULL)
65 DEFINE_PRIMITIVE(std::string, AVRO_STRING)
66 DEFINE_PRIMITIVE(std::vector<uint8_t>, AVRO_BYTES)
67 
68 
69 } // namespace avro
70 
71 #endif
Definition: Types.hh:37
Definition: Types.hh:40
Type
The "type" for the schema.
Definition: Types.hh:31
Definition: Types.hh:49
A bunch of templates and specializations for encoding and decoding specific types.
Definition: AvroParse.hh:31
Definition: Node.hh:180
Definition: Types.hh:39
Definition: Types.hh:33
Definition: AvroTraits.hh:37
Definition: Types.hh:35
Definition: Types.hh:34
Definition: Types.hh:38
define a type to identify Null in template functions
Definition: Types.hh:102
Definition: Boost.hh:50
Definition: AvroTraits.hh:34
Definition: AvroTraits.hh:40
Definition: Types.hh:36