source: XMLIO_V2/dev/dev_rv/attribut.hpp @ 88

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

Version expérimentale, commit pour sauvegarde.

File size: 3.0 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 const char * getName(void) const = 0 ;
42     
43         Attribut(void) : hasValue(false) {} ;
44         Attribut(const Ctype& value_) : value(value_), hasValue(true) {} ;
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()
66         {
67            if (!hasValue)
68            {
69               ostringstream oss;
70               oss << "CAttribut& CAttribut<Ctype>::operator Ctype , access to undefined value of attribut <<" << this->getName() <<">>";
71                                                                         
72               throw XMLIOUndefinedValueException(oss.str());
73            }
74            return value ;
75         }
76
77         virtual ostream& print(ostream & o) const
78         {
79            o<<"Attribut : "<<getName()<<"  ---->" ;
80            if (hasValue) o<< boolalpha <<" value = "<< value ;
81            else o<< "/" ;
82            return o ;
83         }
84
85         virtual void setValue(const Ctype & value_)
86         { hasValue=true ; value=value_ ; }
87
88         virtual void getValue(Ctype & value_) const
89         {
90            if (!hasValue)
91            {
92               ostringstream oss;
93               oss << "CAttribut& CAttribut<Ctype>::operator Ctype , access to undefined value of attribut <<" << this->getName() <<">>";
94                                                                         
95               throw XMLIOUndefinedValueException(oss.str());
96            }
97            value_=value ;
98         }
99
100   }; // class Attribut
101}; // namespace XMLIOSERVER
102 
103#endif //__ATTRIBUT__
Note: See TracBrowser for help on using the repository browser.