Debian Codegraph @

cpp/include/proton/type_id.hpp

raw
1 #ifndef PROTON_TYPE_ID_HPP
2 #define PROTON_TYPE_ID_HPP
3
4 /*
5 *
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements. See the NOTICE file
8 * distributed with this work for additional information
9 * regarding copyright ownership. The ASF licenses this file
10 * to you under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance
12 * with the License. You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations
21 * under the License.
22 *
23 */
24
25 /// @file
26 /// Type IDs for AMQP data types.
27
28 #include "./internal/export.hpp"
29
30 #include <proton/codec.h>
31
32 #include <string>
33
34 namespace proton {
35
36 /// An identifier for AMQP types.
37 enum type_id {
38 NULL_TYPE = PN_NULL, ///< The null type, contains no data.
39 BOOLEAN = PN_BOOL, ///< Boolean true or false.
40 UBYTE = PN_UBYTE, ///< Unsigned 8-bit integer.
41 BYTE = PN_BYTE, ///< Signed 8-bit integer.
42 USHORT = PN_USHORT, ///< Unsigned 16-bit integer.
43 SHORT = PN_SHORT, ///< Signed 16-bit integer.
44 UINT = PN_UINT, ///< Unsigned 32-bit integer.
45 INT = PN_INT, ///< Signed 32-bit integer.
46 CHAR = PN_CHAR, ///< 32-bit unicode character.
47 ULONG = PN_ULONG, ///< Unsigned 64-bit integer.
48 LONG = PN_LONG, ///< Signed 64-bit integer.
49 TIMESTAMP = PN_TIMESTAMP, ///< Signed 64-bit milliseconds since the epoch.
50 FLOAT = PN_FLOAT, ///< 32-bit binary floating point.
51 DOUBLE = PN_DOUBLE, ///< 64-bit binary floating point.
52 DECIMAL32 = PN_DECIMAL32, ///< 32-bit decimal floating point.
53 DECIMAL64 = PN_DECIMAL64, ///< 64-bit decimal floating point.
54 DECIMAL128 = PN_DECIMAL128, ///< 128-bit decimal floating point.
55 UUID = PN_UUID, ///< 16-byte UUID.
56 BINARY = PN_BINARY, ///< Variable-length sequence of bytes.
57 STRING = PN_STRING, ///< Variable-length utf8-encoded string.
58 SYMBOL = PN_SYMBOL, ///< Variable-length encoded string.
59 DESCRIBED = PN_DESCRIBED, ///< A descriptor and a value.
60 ARRAY = PN_ARRAY, ///< A sequence of values of the same type.
61 LIST = PN_LIST, ///< A sequence of values of mixed types.
62 MAP = PN_MAP ///< A sequence of key-value pairs.
63 };
64
65 /// Get the name of the AMQP type.
66 PN_CPP_EXTERN std::string type_name(type_id);
67
68 /// Print the type name.
69 PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, type_id);
70
71 /// Throw a conversion_error if want != got with a message including
72 /// the names of the types.
73 PN_CPP_EXTERN void assert_type_equal(type_id want, type_id got);
74
75 /// @name Functions to test the properties of a type ID
76 /// @{
77 inline bool type_id_is_signed_int(type_id t) { return t == BYTE || t == SHORT || t == INT || t == LONG; }
78 inline bool type_id_is_unsigned_int(type_id t) { return t == UBYTE || t == USHORT || t == UINT || t == ULONG; }
79 inline bool type_id_is_integral(type_id t) { return t == BOOLEAN || t == CHAR || t == TIMESTAMP || type_id_is_unsigned_int(t) || type_id_is_signed_int(t); }
80 inline bool type_id_is_floating_point(type_id t) { return t == FLOAT || t == DOUBLE; }
81 inline bool type_id_is_decimal(type_id t) { return t == DECIMAL32 || t == DECIMAL64 || t == DECIMAL128; }
82 inline bool type_id_is_signed(type_id t) { return type_id_is_signed_int(t) || type_id_is_floating_point(t) || type_id_is_decimal(t); }
83 inline bool type_id_is_string_like(type_id t) { return t == BINARY || t == STRING || t == SYMBOL; }
84 inline bool type_id_is_container(type_id t) { return t == LIST || t == MAP || t == ARRAY || t == DESCRIBED; }
85
86 inline bool type_id_is_null(type_id t) { return t == NULL_TYPE; }
87
88 inline bool type_id_is_scalar(type_id t) {
89 return type_id_is_integral(t) ||
90 type_id_is_floating_point(t) ||
91 type_id_is_decimal(t) ||
92 type_id_is_string_like(t) ||
93 type_id_is_null(t) ||
94 t == TIMESTAMP ||
95 t == UUID;
96 }
97
98 /// }
99
100 } // proton
101
102 #endif // PROTON_TYPE_ID_HPP