Otawa  0.10
Property.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * Copyright (c) 2003, IRIT UPS.
4  *
5  * otawa/prop/Property.h -- interface to Property class and derived.
6  */
7 #ifndef OTAWA_PROP_PROPERTY_H
8 #define OTAWA_PROP_PROPERTY_H
9 
10 #include <elm/assert.h>
11 #include <elm/string.h>
12 #include <elm/utility.h>
13 #include <elm/io.h>
14 #include <otawa/prop/PropList.h>
15 
16 namespace otawa {
17 
18 // GenericProperty class
19 template <class T>
20 class GenericProperty: public Property {
21 public:
22  inline GenericProperty(const AbstractIdentifier *id, const T& value)
23  : Property(id), _value(value) { };
24  inline GenericProperty(const AbstractIdentifier& id, const T& value)
25  : Property(id), _value(value) { };
27  : Property(name), _value(value) { };
28  virtual ~GenericProperty(void) { };
29  virtual Property *copy(void)
30  { return new GenericProperty<T>(id(), value()); };
31  static GenericProperty<T> *make(const AbstractIdentifier *id, const T& value)
32  { return new GenericProperty(id, value); };
33  inline const T& value(void) const { return _value; };
34  inline T& value(void) { return _value; };
35 
36 private:
37  T _value;
38 };
39 
40 
41 // LockedProperty class
42 template <class T>
43 class LockedProperty: public GenericProperty<T> {
44 protected:
45  virtual ~LockedProperty(void) {
46  GenericProperty<T>::value()->unlock();
47  };
48  virtual Property *copy(void) {
49  return new LockedProperty<T>(
52  };
53 public:
55  : GenericProperty<T>(id, value) { GenericProperty<T>::value()->lock(); };
57  : GenericProperty<T>(id, value) { GenericProperty<T>::value()->lock(); };
59  : GenericProperty<T>(name, value) { GenericProperty<T>::value()->lock(); };
60 };
61 
62 
63 // Property Inlines
64 template <class T>
65 inline const T& Property::get(void) const {
66  return ((const GenericProperty<T> *)this)->value();
67 }
68 
69 template <class T>
70 inline void Property::set(const T& value) {
71  ((GenericProperty<T> *)this)->value() = value;
72 }
73 
75  prop->print(out);
76  return out;
77 }
78 
79 } // otawa
80 
81 #endif // OTAWA_PROP_PROPERTY_H
const T & get(void) const
Definition: Property.h:65
virtual ~GenericProperty(void)
Definition: Property.h:28
GenericProperty(const AbstractIdentifier &id, const T &value)
Definition: Property.h:24
virtual void print(elm::io::Output &out) const
Print the given property, that is, the identifier and its value if any.
Definition: prop_PropList.cpp:289
const AbstractIdentifier * id(void) const
Get the identifier code of the property.
Definition: PropList.h:54
This generic class allows attaching any type of data to a property.
Definition: Property.h:20
elm::io::Output & operator<<(elm::io::Output &out, Address addr)
Definition: base.cpp:188
LockedProperty(const AbstractIdentifier &id, T value)
Build a new locked property with a static identifier.
Definition: Property.h:56
Represents a unique identifier used by the annotation system.
Definition: AbstractIdentifier.h:32
virtual Property * copy(void)
This method is called when a property is copied.
Definition: Property.h:29
LockedProperty(const AbstractIdentifier *id, T value)
Build a new locked property.
Definition: Property.h:54
LockedProperty(elm::CString name, T value)
Build a new locked property with a named identifier.
Definition: Property.h:58
sys::SystemOutStream & out
GenericProperty(elm::CString name, const T &value)
Definition: Property.h:26
void set(const T &value)
Definition: Property.h:70
cstring name
Definition: odisasm.cpp:107
virtual Property * copy(void)
This method is called when a property is copied.
Definition: Property.h:48
const T & value(void) const
Get the value of the property.
Definition: Property.h:33
This class is used for building a lock property, that is, for taking pointer values implementing the ...
Definition: Property.h:43
A property associates a data with an identifier.
Definition: PropList.h:42
static GenericProperty< T > * make(const AbstractIdentifier *id, const T &value)
Build a new generic property with the given data.
Definition: Property.h:31
T & value(void)
Get the value of the property.
Definition: Property.h:34
virtual ~LockedProperty(void)
Definition: Property.h:45
T _value
Definition: Property.h:34
GenericProperty(const AbstractIdentifier *id, const T &value)
Definition: Property.h:22