Qpid Proton C++  0.13.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
scalar.hpp
1 #ifndef PROTON_SCALAR_HPP
2 #define PROTON_SCALAR_HPP
3 
4 /*
5  * Licensed to the Apache Software Foundation (ASF) under one
6  * or more contributor license agreements. See the NOTICE file
7  * distributed with this work for additional information
8  * regarding copyright ownership. The ASF licenses this file
9  * to you under the Apache License, Version 2.0 (the
10  * "License"); you may not use this file except in compliance
11  * with the License. You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing,
16  * software distributed under the License is distributed on an
17  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18  * KIND, either express or implied. See the License for the
19  * specific language governing permissions and limitations
20  * under the License.
21  */
22 
23 #include "./internal/scalar_base.hpp"
24 
25 namespace proton {
26 
27 namespace codec {
28 class decoder;
29 class encoder;
30 }
31 
35 class scalar : public internal::scalar_base {
36  public:
38  PN_CPP_EXTERN scalar() {}
39 
41  template <class T> scalar(const T& x) { *this = x; }
42 
44  template <class T> scalar& operator=(const T& x) { put(x); return *this; }
45 
47  bool empty() const { return type() == NULL_TYPE; }
48 
50  void clear() { *this = null(); }
51 };
52 
61 template<class T> T get(const scalar& s) { return internal::get<T>(s); }
62 
73 template<class T> T coerce(const scalar& x) { return internal::coerce<T>(x); }
74 
75 
86 template<class T> T coerce(scalar& x) { return internal::coerce<T>(x); }
87 
88 } // proton
89 
90 #endif // PROTON_SCALAR_HPP
A holder for an instance of any scalar AMQP type.
Definition: scalar.hpp:35
T coerce(const scalar &x)
Coerce the contained value to type T.
Definition: scalar.hpp:73
The null type, contains no data.
Definition: type_id.hpp:39
T coerce(scalar &x)
Coerce the contained value to type T.
Definition: scalar.hpp:86
bool empty() const
True if type() == NULL_TYPE.
Definition: scalar.hpp:47
scalar & operator=(const T &x)
Assign from any scalar type.
Definition: scalar.hpp:44
void clear()
Clear the scalar, making it empty().
Definition: scalar.hpp:50
scalar(const T &x)
Construct from any scalar type.
Definition: scalar.hpp:41
scalar()
Create an empty scalar.
Definition: scalar.hpp:38