1 | #ifndef __XMLIO_CAttribute__ |
---|
2 | #define __XMLIO_CAttribute__ |
---|
3 | |
---|
4 | /// boost headers /// |
---|
5 | #include <boost/any.hpp> |
---|
6 | |
---|
7 | /// xmlioserver headers /// |
---|
8 | #include "xmlioserver_spl.hpp" |
---|
9 | #include "object.hpp" |
---|
10 | |
---|
11 | namespace xmlioserver |
---|
12 | { |
---|
13 | namespace tree |
---|
14 | { |
---|
15 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
16 | class CAttribute : public CObject |
---|
17 | { |
---|
18 | typedef CObject SuperClass; |
---|
19 | |
---|
20 | public : |
---|
21 | |
---|
22 | /// Constructeurs /// |
---|
23 | explicit CAttribute(const StdString & id); |
---|
24 | CAttribute(const CAttribute & attribut); |
---|
25 | CAttribute(const CAttribute * const attribut); // Not implemented. |
---|
26 | |
---|
27 | /// Accesseurs /// |
---|
28 | const StdString & getName(void) const; |
---|
29 | const boost::any & getAnyValue(void) const; |
---|
30 | template <typename T> inline T getValue(void) const; |
---|
31 | |
---|
32 | /// Mutateurs /// |
---|
33 | template <typename T> inline void setValue(const T & value); |
---|
34 | void setAnyValue(const boost::any & value); |
---|
35 | void clear(void); |
---|
36 | |
---|
37 | /// Test /// |
---|
38 | bool isEmpty(void) const; |
---|
39 | template <typename T> inline bool isType(void); |
---|
40 | |
---|
41 | /// Destructeur /// |
---|
42 | virtual ~CAttribute(void); |
---|
43 | |
---|
44 | /// Autres /// |
---|
45 | virtual StdString toString(void) const = 0; |
---|
46 | virtual void fromString(const StdString & str) = 0; |
---|
47 | |
---|
48 | virtual void toBinary (StdOStream & os) const = 0; |
---|
49 | virtual void fromBinary(StdIStream & is) = 0; |
---|
50 | |
---|
51 | protected : |
---|
52 | |
---|
53 | /// Constructeurs /// |
---|
54 | CAttribute(void); // Not implemented. |
---|
55 | |
---|
56 | private : |
---|
57 | |
---|
58 | /// Propriété /// |
---|
59 | boost::any value; |
---|
60 | |
---|
61 | }; // class CAttribute |
---|
62 | |
---|
63 | /// ////////////////////// Définitions ////////////////////// /// |
---|
64 | template <typename T> |
---|
65 | T CAttribute::getValue(void) const |
---|
66 | { |
---|
67 | return (boost::any_cast<T>(this->value)); |
---|
68 | } |
---|
69 | |
---|
70 | template <typename T> |
---|
71 | void CAttribute::setValue(const T & value) |
---|
72 | { |
---|
73 | this->value = value; |
---|
74 | } |
---|
75 | |
---|
76 | template<typename T> |
---|
77 | bool CAttribute::isType(void) |
---|
78 | { |
---|
79 | return (this->value.type() == typeid(T)); |
---|
80 | } |
---|
81 | |
---|
82 | } // namespace tree |
---|
83 | } // namespace xmlioserver |
---|
84 | |
---|
85 | #endif // __XMLIO_CAttribute__ |
---|