1 | #ifndef __ATTRIBUT__ |
---|
2 | #define __ATTRIBUT__ |
---|
3 | |
---|
4 | #include "base_attribut.hpp" |
---|
5 | |
---|
6 | using XMLIOSERVER::BaseAttribut; |
---|
7 | using XMLIOSERVER::XMLIOUndefinedValueException; |
---|
8 | using std::ostringstream; |
---|
9 | |
---|
10 | namespace XMLIOSERVER |
---|
11 | { |
---|
12 | class IStringStream_alt |
---|
13 | { |
---|
14 | public : |
---|
15 | IStringStream_alt(const std::string& str) : iss(str) |
---|
16 | { /* Ne rien faire de plus */} |
---|
17 | |
---|
18 | istream& operator>> (std::string& s) |
---|
19 | {s.assign(this->iss.str()); return (this->iss);} |
---|
20 | istream& operator>> (int& s) { return (iss>>s); } |
---|
21 | istream& operator>> (bool& s) |
---|
22 | { |
---|
23 | if(!this->iss.str().compare(string(".TRUE."))) s = true; |
---|
24 | else s = false; |
---|
25 | return (this->iss); |
---|
26 | } |
---|
27 | |
---|
28 | private : |
---|
29 | istringstream iss; |
---|
30 | |
---|
31 | }; // class IStringStream_alt |
---|
32 | |
---|
33 | |
---|
34 | template <class Ctype> |
---|
35 | class Attribut : public BaseAttribut |
---|
36 | { |
---|
37 | public : |
---|
38 | |
---|
39 | operator Ctype() const |
---|
40 | { |
---|
41 | if (!hasValue) throw XMLIOUndefinedValueException("L'attribut \"" + this->getName() + "\" est invalide !"); |
---|
42 | return (value) ; |
---|
43 | } |
---|
44 | |
---|
45 | virtual bool _hasValue() const { return (hasValue); } |
---|
46 | |
---|
47 | protected : |
---|
48 | |
---|
49 | Attribut(void) : hasValue(false) {} ; |
---|
50 | Attribut(const Ctype& value_) : hasValue(true), value(value_) {} ; |
---|
51 | |
---|
52 | Attribut(const Attribut& attr) : hasValue(attr.hasValue) |
---|
53 | { if (hasValue) value=attr.value ; } |
---|
54 | |
---|
55 | Attribut& operator = (const Attribut & attr) |
---|
56 | { |
---|
57 | hasValue=attr.hasValue ; |
---|
58 | if (hasValue) value=attr.value ; |
---|
59 | return *this ; |
---|
60 | } |
---|
61 | |
---|
62 | virtual const char * getType(void) const = 0; |
---|
63 | |
---|
64 | virtual void setFromString(const std::string str) |
---|
65 | { |
---|
66 | IStringStream_alt iss(str); Ctype val; |
---|
67 | iss >> val; |
---|
68 | this->setValue(val); |
---|
69 | } |
---|
70 | |
---|
71 | virtual void assignValue(const BaseAttribut* _ba) |
---|
72 | { value = ((Attribut*)_ba) -> value; hasValue = true; } |
---|
73 | |
---|
74 | virtual ostream& print(ostream & o) const |
---|
75 | { if (hasValue) o << " " << getName() << "=\"" << boolalpha << value << "\"" ; return o ; } |
---|
76 | |
---|
77 | virtual void setValue(const Ctype & value_) |
---|
78 | { hasValue=true ; value=value_ ; } |
---|
79 | |
---|
80 | virtual void getValue(Ctype & value_) const |
---|
81 | { |
---|
82 | if (!hasValue) throw XMLIOUndefinedValueException("L'attribut \"" + this->getName() + "\" est invalide !"); |
---|
83 | value_=value ; |
---|
84 | } |
---|
85 | |
---|
86 | private : |
---|
87 | |
---|
88 | bool hasValue ; |
---|
89 | Ctype value ; |
---|
90 | |
---|
91 | }; // class Attribut |
---|
92 | } // namespace XMLIOSERVER |
---|
93 | |
---|
94 | #endif //__ATTRIBUT__ |
---|
95 | |
---|
96 | |
---|