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 | #include "base_type.hpp" |
---|
11 | #include "message.hpp" |
---|
12 | #include "buffer_in.hpp" |
---|
13 | #include "buffer_out.hpp" |
---|
14 | |
---|
15 | namespace xmlioserver |
---|
16 | { |
---|
17 | namespace tree |
---|
18 | { |
---|
19 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
20 | class CAttribute : public CObject, public CBaseType |
---|
21 | { |
---|
22 | typedef CObject SuperClass; |
---|
23 | |
---|
24 | public : |
---|
25 | |
---|
26 | /// Constructeurs /// |
---|
27 | explicit CAttribute(const StdString & id); |
---|
28 | CAttribute(const CAttribute & attribut); |
---|
29 | CAttribute(const CAttribute * const attribut); // Not implemented. |
---|
30 | |
---|
31 | /// Accesseurs /// |
---|
32 | const StdString & getName(void) const; |
---|
33 | const boost::any & getAnyValue(void) const; |
---|
34 | template <typename T> inline T getValue(void) const; |
---|
35 | template <typename T> inline T* getRef(void); |
---|
36 | |
---|
37 | /// Mutateurs /// |
---|
38 | template <typename T> inline void setValue(const T & value); |
---|
39 | void setAnyValue(const boost::any & value); |
---|
40 | void clear(void); |
---|
41 | |
---|
42 | /// Test /// |
---|
43 | bool isEmpty(void) const; |
---|
44 | template <typename T> inline bool isType(void); |
---|
45 | |
---|
46 | /// Destructeur /// |
---|
47 | virtual ~CAttribute(void); |
---|
48 | |
---|
49 | /// Autres /// |
---|
50 | virtual StdString toString(void) const = 0; |
---|
51 | virtual void fromString(const StdString & str) = 0; |
---|
52 | |
---|
53 | virtual void toBinary (StdOStream & os) const = 0; |
---|
54 | virtual void fromBinary(StdIStream & is) = 0; |
---|
55 | |
---|
56 | protected : |
---|
57 | |
---|
58 | /// Constructeurs /// |
---|
59 | CAttribute(void); // Not implemented. |
---|
60 | |
---|
61 | /// Propriété /// |
---|
62 | boost::any value; |
---|
63 | |
---|
64 | }; // class CAttribute |
---|
65 | |
---|
66 | /// ////////////////////// Définitions ////////////////////// /// |
---|
67 | template <typename T> |
---|
68 | T CAttribute::getValue(void) const |
---|
69 | { |
---|
70 | return (boost::any_cast<T>(this->value)); |
---|
71 | } |
---|
72 | |
---|
73 | template <typename T> |
---|
74 | T* CAttribute::getRef(void) |
---|
75 | { |
---|
76 | return (boost::any_cast<T>(&value)); |
---|
77 | } |
---|
78 | |
---|
79 | template <typename T> |
---|
80 | void CAttribute::setValue(const T & value) |
---|
81 | { |
---|
82 | this->value = value; |
---|
83 | } |
---|
84 | |
---|
85 | template<typename T> |
---|
86 | bool CAttribute::isType(void) |
---|
87 | { |
---|
88 | return (this->value.type() == typeid(T)); |
---|
89 | } |
---|
90 | |
---|
91 | } // namespace tree |
---|
92 | |
---|
93 | CMessage& operator<<(CMessage& msg,tree::CAttribute& type) ; |
---|
94 | CMessage& operator<<(CMessage& msg, const tree::CAttribute& type) ; |
---|
95 | |
---|
96 | CBufferOut& operator<<(CBufferOut& buffer,tree::CAttribute& type) ; |
---|
97 | CBufferIn& operator>>(CBufferIn& buffer, tree::CAttribute& type) ; |
---|
98 | } |
---|
99 | // namespace xmlioserver |
---|
100 | |
---|
101 | #endif // __XMLIO_CAttribute__ |
---|