source: XMLIO_V2/dev/dev_rv/src/XMLIO/attribut.hpp @ 108

Last change on this file since 108 was 108, checked in by hozdoba, 14 years ago

Début de prise en charge des références (sans contrÎle ni transmission d'attribut pour le moment).

File size: 2.5 KB
Line 
1#ifndef __ATTRIBUT__
2#define __ATTRIBUT__
3
4#include "base_attribut.hpp"
5
6using XMLIOSERVER::BaseAttribut;
7using XMLIOSERVER::XMLIOUndefinedValueException;
8using std::ostringstream;
9
10namespace 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) {s.assign(this->iss.str()); return (this->iss);}
19         istream& operator>> (int& s) { return (iss>>s); }
20         istream& operator>> (bool& s)
21         {
22            if(!this->iss.str().compare(string(".TRUE."))) s =  true;
23            else s = false;
24            return (this->iss);
25         }
26
27      private :
28         istringstream iss;
29
30   }; // class IStringStream_alt
31
32
33   template <class Ctype>
34      class Attribut : public BaseAttribut
35   {
36      public :
37
38         bool hasValue ;
39         Ctype value ;
40
41         virtual bool _hasValue() const { return hasValue; }
42
43         Attribut(void) : hasValue(false) {} ;
44         Attribut(const Ctype& value_) : hasValue(true), value(value_) {} ;
45
46         Attribut(const Attribut& attr) : hasValue(attr.hasValue)
47         {  if (hasValue) value=attr.value ; }
48
49         Attribut& operator = (const Attribut & attr)
50         {
51            hasValue=attr.hasValue ;
52            if (hasValue) value=attr.value ;
53            return *this ;
54         }
55
56         virtual const char * getType(void) const = 0;
57
58         virtual void setFromString(const std::string str)
59         {
60            IStringStream_alt iss(str); Ctype val;
61            iss >> val;
62            this->setValue(val);
63         }
64
65         operator Ctype() const
66         {
67            if (!hasValue) throw XMLIOUndefinedValueException("L'attribut \"" + this->getName() + "\" est invalide !");
68            return value ;
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   }; // class Attribut
87}; // namespace XMLIOSERVER
88
89#endif //__ATTRIBUT__
Note: See TracBrowser for help on using the repository browser.