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);
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