| 1 |
#ifndef PROTON_MESSAGE_ID_HPP |
| 2 |
#define PROTON_MESSAGE_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 |
#include "./binary.hpp" |
| 26 |
#include "./scalar_base.hpp" |
| 27 |
#include "./uuid.hpp" |
| 28 |
|
| 29 |
#include <proton/type_compat.h> |
| 30 |
|
| 31 |
#include <string> |
| 32 |
|
| 33 |
/// @file |
| 34 |
/// @copybrief proton::message_id |
| 35 |
|
| 36 |
namespace proton { |
| 37 |
|
| 38 |
/// An AMQP message ID. |
| 39 |
/// |
| 40 |
/// It can contain one of the following types: |
| 41 |
/// |
| 42 |
/// - uint64_t |
| 43 |
/// - std::string |
| 44 |
/// - proton::uuid |
| 45 |
/// - proton::binary |
| 46 |
/// |
| 47 |
class message_id : public scalar_base { |
| 48 |
public: |
| 49 |
/// An empty message_id. |
| 50 |
message_id() = default; |
| 51 |
|
| 52 |
/// Construct from any type that can be assigned. |
| 53 |
template <class T> message_id(const T& x) { *this = x; } |
| 54 |
|
| 55 |
/// @name Assignment operators |
| 56 |
/// Assign a C++ value, deduce the AMQP type() |
| 57 |
/// |
| 58 |
/// @{ |
| 59 |
message_id& operator=(uint64_t x) { put_(x); return *this; } |
| 60 |
message_id& operator=(const uuid& x) { put_(x); return *this; } |
| 61 |
message_id& operator=(const binary& x) { put_(x); return *this; } |
| 62 |
message_id& operator=(const std::string& x) { put_(x); return *this; } |
| 63 |
message_id& operator=(const char* x) { put_(x); return *this; } ///< Treated as amqp::STRING |
| 64 |
/// @} |
| 65 |
|
| 66 |
private: |
| 67 |
message_id(const pn_atom_t& a): scalar_base(a) {} |
| 68 |
|
| 69 |
///@cond INTERNAL |
| 70 |
friend class message; |
| 71 |
friend class codec::decoder; |
| 72 |
///@endcond |
| 73 |
}; |
| 74 |
|
| 75 |
/// @cond INTERNAL |
| 76 |
/// Base template for get(message_id), specialized for legal message_id types. |
| 77 |
template <class T> T get(const message_id& x); |
| 78 |
/// @endcond |
| 79 |
|
| 80 |
/// Get the uint64_t value or throw conversion_error. @relatedalso message_id |
| 81 |
template<> inline uint64_t get<uint64_t>(const message_id& x) { return internal::get<uint64_t>(x); } |
| 82 |
/// Get the @ref uuid value or throw conversion_error. @relatedalso message_id |
| 83 |
template<> inline uuid get<uuid>(const message_id& x) { return internal::get<uuid>(x); } |
| 84 |
/// Get the @ref binary value or throw conversion_error. @relatedalso message_id |
| 85 |
template<> inline binary get<binary>(const message_id& x) { return internal::get<binary>(x); } |
| 86 |
/// Get the std::string value or throw conversion_error. @relatedalso message_id |
| 87 |
template<> inline std::string get<std::string>(const message_id& x) { return internal::get<std::string>(x); } |
| 88 |
|
| 89 |
/// @copydoc scalar::coerce |
| 90 |
/// @relatedalso message_id |
| 91 |
template<class T> T coerce(const message_id& x) { return internal::coerce<T>(x); } |
| 92 |
|
| 93 |
} // proton |
| 94 |
|
| 95 |
#endif // PROTON_MESSAGE_ID_HPP |