Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
rtti.h
1 /*
2  * RTTI module
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2007, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef ELM_RTTI_H
22 #define ELM_RTTI_H
23 
24 #include <elm/dyndata/AbstractCollection.h>
25 #include <elm/rtti/Class.h>
26 #include <elm/rtti/Enum.h>
27 #include <elm/rtti/Tuple.h>
28 
29 namespace elm {
30 
31 // Field class
32 template <class V>
33 class Field {
34  CString _name;
35  V& _value;
36 public:
37  inline Field(CString name, V& value): _name(name), _value(value) { }
38  inline CString name(void) const { return _name; };
39  inline V& value(void) const { return _value; };
40 };
41 template <class T>
42 inline Field<T> field(CString name, T& value) {
43  return Field<T>(name, value);
44 }
45 
46 
47 // DefaultField class
48 template <class T>
49 class DefaultField: public Field<T> {
50  const T& def;
51 public:
52  inline DefaultField(CString name, T& value, const T& _default)
53  : Field<T>(name, value), def(_default) { }
54  inline const T& defaultValue(void) const { return def; }
55 };
56 template <class T>
57 inline DefaultField<T> field(CString name, T& value, const T& def)
58  { return DefaultField<T>(name, value, def); }
59 template <class T>
60 inline DefaultField<T> field(CString name, const T& value, const T& def)
61  { return DefaultField<T>(name, const_cast<T&>(value), def); }
62 
63 
64 // _unqualify function
65 inline CString _unqualify(CString name) {
66  int pos = name.lastIndexOf(':');
67  if(pos < 0)
68  return name;
69  else
70  return name.substring(pos + 1);
71 }
72 
73 } // elm
74 
75 #endif // ELM_RTTI_H
elm::DefaultField::defaultValue
const T & defaultValue(void) const
Definition: rtti.h:54
elm::CString::substring
CString substring(int pos) const
Definition: string.h:20
elm::Field::value
V & value(void) const
Definition: rtti.h:39
value
elm::CString
Definition: CString.h:17
elm::Field
Definition: rtti.h:33
elm::_unqualify
CString _unqualify(CString name)
Definition: rtti.h:65
elm
Definition: adapter.h:26
elm::DefaultField::DefaultField
DefaultField(CString name, T &value, const T &_default)
Definition: rtti.h:52
elm::DefaultField
Definition: rtti.h:49
elm::field
Field< T > field(CString name, T &value)
Definition: rtti.h:42
elm::Field::name
CString name(void) const
Definition: rtti.h:38
elm::CString::lastIndexOf
int lastIndexOf(char chr) const
Definition: CString.h:44
elm::Field::Field
Field(CString name, V &value)
Definition: rtti.h:37