EMANE  1.2.1
any.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2015 - Adjacent Link LLC, Bridgewater, New Jersey
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * * Neither the name of Adjacent Link LLC nor the names of its
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef EMANEANY_HEADER_
34 #define EMANEANY_HEADER_
35 
36 #include "emane/anyexception.h"
37 #include "emane/inetaddr.h"
38 
39 #include <cstdint>
40 
41 namespace EMANE
42 {
49  class Any
50  {
51  public:
52  enum class Type
53  {
54  TYPE_INT64,
56  TYPE_INT32,
58  TYPE_INT16,
60  TYPE_INT8,
61  TYPE_UINT8,
62  TYPE_FLOAT,
65  TYPE_BOOL,
67  };
68 
72  explicit Any(std::int64_t i64Value);
73 
77  explicit Any(std::uint64_t u64Value);
78 
82  explicit Any(std::int32_t i32Value);
83 
87  explicit Any(std::uint32_t u32Value);
88 
92  explicit Any(std::int16_t i16Value);
93 
97  explicit Any(std::uint16_t u16Value);
98 
102  explicit Any(std::int8_t i8Value);
103 
107  explicit Any(std::uint8_t u8Value);
108 
112  explicit Any(float fValue);
113 
117  explicit Any(double dValue);
118 
122  explicit Any(const INETAddr & addrValue);
123 
127  explicit Any(const char * pzValue);
128 
132  explicit Any(const std::string & sValue);
133 
137  explicit Any(const bool & bValue);
138 
142  Any(const Any & rhs);
143 
147  Any & operator=(const Any & rhs);
148 
152  ~Any();
153 
161  std::int64_t asINT64() const;
162 
170  std::uint64_t asUINT64() const;
171 
179  std::int32_t asINT32() const;
180 
188  std::uint32_t asUINT32() const;
189 
197  std::int16_t asINT16() const;
198 
206  std::uint16_t asUINT16() const;
207 
215  std::int8_t asINT8() const;
216 
224  std::uint8_t asUINT8() const;
225 
233  float asFloat() const;
234 
242  double asDouble() const;
243 
244 
252  INETAddr asINETAddr() const;
253 
261  bool asBool() const;
262 
270  std::string asString() const;
271 
277  Type getType() const;
278 
286  bool operator<(const EMANE::Any & rhs) const;
287 
295  bool operator>(const EMANE::Any & rhs) const;
296 
304  bool operator<=(const EMANE::Any & rhs) const;
305 
313  bool operator>=(const EMANE::Any & rhs) const;
314 
320  std::string toString() const;
321 
328  static Any create(std::string sValue, Type type);
329 
330  private:
331  Type type_;
332  union
333  {
334  std::int64_t i64Value_;
335  std::uint64_t u64Value_;
336  double dValue_;
337  std::string sValue_;
339  };
340  };
341 
342  template<typename T>
344  {
345  static Any::Type type();
346  };
347 
348  template<typename T>
350  : public std::false_type{};
351 
352  template<>
354  : public std::true_type{};
355 
356  template<>
358  : public std::true_type{};
359 
360  std::string anyTypeAsString(const Any::Type & type);
361 }
362 
363 #endif // EMANEANY_HEADER_
INETAddr addrValue_
Definition: any.h:338
std::uint16_t asUINT16() const
Definition: any.cc:199
Any(std::int64_t i64Value)
Definition: any.cc:36
std::int64_t i64Value_
Definition: any.h:334
float asFloat() const
Definition: any.cc:229
std::uint8_t asUINT8() const
Definition: any.cc:219
std::uint64_t u64Value_
Definition: any.h:335
std::string sValue_
Definition: any.h:337
Type
Definition: any.h:52
std::string toString() const
Definition: any.cc:292
bool operator<=(const EMANE::Any &rhs) const
Definition: any.cc:400
bool operator>(const EMANE::Any &rhs) const
Definition: any.cc:513
std::int32_t asINT32() const
Definition: any.cc:169
INETAddr asINETAddr() const
Definition: any.cc:249
std::string anyTypeAsString(const Any::Type &type)
Definition: any.cc:551
double dValue_
Definition: any.h:336
Any & operator=(const Any &rhs)
Definition: any.cc:110
std::string asString() const
Definition: any.cc:271
~Any()
Definition: any.cc:136
std::uint64_t asUINT64() const
Definition: any.cc:159
double asDouble() const
Definition: any.cc:239
std::uint32_t asUINT32() const
Definition: any.cc:179
std::int64_t asINT64() const
Definition: any.cc:149
bool operator>=(const EMANE::Any &rhs) const
Definition: any.cc:438
bool asBool() const
Definition: any.cc:260
static Any create(std::string sValue, Type type)
Definition: any.cc:343
std::int8_t asINT8() const
Definition: any.cc:209
std::int16_t asINT16() const
Definition: any.cc:189
The Any class can contain an instance of one of any type in its support type set. ...
Definition: any.h:49
bool operator<(const EMANE::Any &rhs) const
Definition: any.cc:476
Type getType() const
Definition: any.cc:281
Definition: agent.h:43