7 #ifndef ATLAS_MESSAGE_ELEMENT_H
8 #define ATLAS_MESSAGE_ELEMENT_H
10 #include <Atlas/Exception.h>
16 namespace Atlas {
namespace Message {
28 typedef double FloatType;
29 typedef void * PtrType;
30 typedef std::string StringType;
31 typedef std::map<std::string, Element> MapType;
32 typedef std::vector<Element> ListType;
75 typedef Atlas::Message::IntType IntType;
76 typedef Atlas::Message::FloatType FloatType;
77 typedef Atlas::Message::PtrType PtrType;
78 typedef Atlas::Message::StringType StringType;
79 typedef Atlas::Message::MapType MapType;
80 typedef Atlas::Message::ListType ListType;
83 void clear(Type new_type = TYPE_NONE);
121 : t(TYPE_FLOAT), f(v)
127 : t(TYPE_FLOAT), f(v)
231 if (TYPE_STRING != t || !s->unique())
234 s =
new DataType<StringType>(v);
243 if (TYPE_STRING != t || !s->unique())
246 s =
new DataType<StringType>(v);
255 if (TYPE_MAP != t || !m->unique())
258 m =
new DataType<MapType>(v);
267 if (TYPE_LIST != t || !l->unique())
270 l =
new DataType<ListType>(v);
280 #if defined(__GNUC__) && __GNUC__ < 3
283 return !(*
this == o);
285 #endif // defined(__GNUC__) && __GNUC__ < 3
291 return !(*
this == c);
297 return (t == TYPE_INT && i == v);
303 return t == TYPE_FLOAT && f == v;
309 return t == TYPE_PTR && p == v;
347 bool isNone()
const {
return (t == TYPE_NONE); }
349 bool isInt()
const {
return (t == TYPE_INT); }
351 bool isFloat()
const {
return (t == TYPE_FLOAT); }
353 bool isPtr()
const {
return (t == TYPE_PTR); }
355 bool isNum()
const {
return ((t == TYPE_FLOAT) || (t == TYPE_INT)); }
357 bool isString()
const {
return (t == TYPE_STRING); }
359 bool isMap()
const {
return (t == TYPE_MAP); }
361 bool isList()
const {
return (t == TYPE_LIST); }
366 if (t == TYPE_INT)
return i;
367 throw WrongTypeException();
376 if (t == TYPE_FLOAT)
return f;
377 throw WrongTypeException();
379 FloatType Float()
const
386 if (t == TYPE_PTR)
return p;
387 throw WrongTypeException();
396 if (t == TYPE_FLOAT)
return f;
397 if (t == TYPE_INT)
return FloatType(i);
398 throw WrongTypeException();
403 if (t == TYPE_STRING)
return *s;
404 throw WrongTypeException();
409 if (t == TYPE_STRING)
return *(s = s->makeUnique());
410 throw WrongTypeException();
412 const StringType& String()
const
418 return *(s = s->makeUnique());
423 if (t == TYPE_MAP)
return *m;
424 throw WrongTypeException();
429 if (t == TYPE_MAP)
return *(m = m->makeUnique());
430 throw WrongTypeException();
432 const MapType& Map()
const
438 return *(m = m->makeUnique());
443 if (t == TYPE_LIST)
return *l;
444 throw WrongTypeException();
449 if (t == TYPE_LIST)
return *(l = l->makeUnique());
450 throw WrongTypeException();
452 const ListType& List()
const
458 return *(l = l->makeUnique());
461 static const char * typeName(Type);
469 DataType() : _refcount(1), _data(0) {}
470 DataType(
const C& c) : _refcount(1), _data(c) {}
472 DataType& operator=(
const C& c) {_data = c;
return *
this;}
474 bool operator==(
const C& c)
const {
return _data == c;}
476 void ref() {++_refcount;}
477 void unref() {
if(--_refcount == 0)
delete this;}
479 bool unique()
const {
return _refcount == 1;}
488 operator C&() {
return _data;}
495 unsigned long _refcount;
513 #endif // ATLAS_MESSAGE_ELEMENT_H
MapType & asMap()
Retrieve the current value as a non-const MapType reference.
Definition: Element.h:427
Element(const ListType &v)
Set type to ListType, and value to v.
Definition: Element.h:160
FloatType asFloat() const
Retrieve the current value as a double.
Definition: Element.h:374
const MapType & asMap() const
Retrieve the current value as a const MapType reference.
Definition: Element.h:421
bool operator==(FloatType v) const
Check for equality with a double.
Definition: Element.h:301
bool operator!=(C c) const
Check for inequality with anything we can check equality with.
Definition: Element.h:289
bool operator==(PtrType v) const
Check for equality with a pointer.
Definition: Element.h:307
bool operator==(IntType v) const
Check for equality with a int.
Definition: Element.h:295
bool operator==(const char *v) const
Check for equality with a const char *.
Definition: Element.h:313
bool isNum() const
Check whether the current type is numeric.
Definition: Element.h:355
Element(const MapType &v)
Set type to MapType, and value to v.
Definition: Element.h:154
Element(IntType v)
Set type to int, and value to v.
Definition: Element.h:114
const std::string & asString() const
Retrieve the current value as a const std::string reference.
Definition: Element.h:401
Element(const StringType &v)
Set type to std::string, and value to v.
Definition: Element.h:148
Multi-type container.
Definition: Element.h:59
Element()
Construct an empty object.
Definition: Element.h:87
bool isFloat() const
Check whether the current type is double.
Definition: Element.h:351
IntType asInt() const
Retrieve the current value as a int.
Definition: Element.h:364
bool operator==(const StringType &v) const
Check for equality with a std::string.
Definition: Element.h:321
The Atlas namespace.
Definition: Bridge.h:20
bool isPtr() const
Check whether the current type is pointer.
Definition: Element.h:353
bool isNone() const
Check whether the current type is nothing.
Definition: Element.h:347
Element(bool v)
Set type to int, and value to v.
Definition: Element.h:108
const ListType & asList() const
Retrieve the current value as a const ListType reference.
Definition: Element.h:441
FloatType asNum() const
Retrieve the current value as a number.
Definition: Element.h:394
Element(FloatType v)
Set type to double, and value to v.
Definition: Element.h:126
bool operator==(const ListType &v) const
Check for equality with a ListType.
Definition: Element.h:337
An exception class issued when the wrong type is requested in as().
Definition: Element.h:19
bool isList() const
Check whether the current type is ListType.
Definition: Element.h:361
bool isMap() const
Check whether the current type is MapType.
Definition: Element.h:359
ListType & asList()
Retrieve the current value as a non-const ListType reference.
Definition: Element.h:447
bool operator==(const Element &o) const
Check for equality with another Element.
Element & operator=(const Element &obj)
overload assignment operator !
bool operator==(const MapType &v) const
Check for equality with a MapType.
Definition: Element.h:329
Element(PtrType v)
Set type to PtrType, and value to v.
Definition: Element.h:132
Element(float v)
Set type to double, and value to v.
Definition: Element.h:120
bool isInt() const
Check whether the current type is int.
Definition: Element.h:349
Type getType() const
Get the current type.
Definition: Element.h:345
Element(int v)
Set type to int, and value to v.
Definition: Element.h:102
Base class for all exceptions thrown by Atlas-C++.
Definition: Exception.h:17
bool isString() const
Check whether the current type is std::string.
Definition: Element.h:357
Element(const char *v)
Set type to std::string, and value to v.
Definition: Element.h:138
PtrType asPtr() const
Retrieve the current value as a pointer.
Definition: Element.h:384
std::string & asString()
Retrieve the current value as a non-const std::string reference.
Definition: Element.h:407