Debian Codegraph @

cpp/include/proton/annotation_key.hpp

raw
1 #ifndef PROTON_ANNOTATION_KEY_HPP
2 #define PROTON_ANNOTATION_KEY_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 #include "./scalar_base.hpp"
26 #include "./symbol.hpp"
27
28 #include <proton/type_compat.h>
29
30 /// @file
31 /// @copybrief proton::annotation_key
32
33 namespace proton {
34
35 /// A key for use with AMQP annotation maps.
36 ///
37 /// An annotation_key can contain either a uint64_t or a proton::symbol.
38 class annotation_key : public scalar_base {
39 public:
40 /// An empty annotation key.
41 annotation_key() = default;
42
43 /// Construct from any type that can be assigned.
44 template <class T> annotation_key(const T& x) { *this = x; }
45
46 /// @name Assign from a uint64_t or symbol.
47 /// @{
48 annotation_key& operator=(uint64_t x) { put_(x); return *this; }
49 annotation_key& operator=(const symbol& x) { put_(x); return *this; }
50 /// @}
51
52 /// @name Extra conversions for strings, treated as codec::SYMBOL.
53 /// @{
54 annotation_key& operator=(const std::string& x) { put_(symbol(x)); return *this; }
55 annotation_key& operator=(const char *x) { put_(symbol(x)); return *this; }
56 /// @}
57
58 /// @cond INTERNAL
59 friend class message;
60 friend class codec::decoder;
61 /// @endcond
62 };
63
64 /// @cond INTERNAL
65 /// Primary template for get<T>(message_id), specialized for legal types.
66 template <class T> T get(const annotation_key& x);
67 /// @endcond
68
69 /// Get the uint64_t value or throw conversion_error.
70 ///
71 /// @relatedalso annotation_key
72 template<> inline uint64_t get<uint64_t>(const annotation_key& x) { return internal::get<uint64_t>(x); }
73
74 /// Get the @ref symbol value or throw conversion_error.
75 ///
76 /// @relatedalso annotation_key
77 template<> inline symbol get<symbol>(const annotation_key& x) { return internal::get<symbol>(x); }
78
79 /// Get the @ref binary value or throw conversion_error.
80 ///
81 /// @copydoc scalar::coerce
82 /// @relatedalso annotation_key
83 template<class T> T coerce(const annotation_key& x) { return internal::coerce<T>(x); }
84
85 } // proton
86
87 #endif // PROTON_ANNOTATION_KEY_HPP