source: XMLIO_V2/dev/dev_rv/old/attribut.hpp @ 90

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

Ancienne Version de parsing.

File size: 2.1 KB
Line 
1#ifndef ATTRIBUT_HPP
2#define ATTRIBUT_HPP
3
4#include "base_attribut.hpp"
5#include "xmlio_std.hpp"
6
7class IStringStream_alt
8{
9        public : 
10                IStringStream_alt(const std::string& str):iss(str)
11                { /* Ne rien faire de plus */}
12               
13                istream& operator>> (std::string& s) {s.assign(this->iss.str()); return (this->iss);}
14                istream& operator>> (int& s) { return (iss>>s); }
15                istream& operator>> (bool& s)
16                {
17                        if(!this->iss.str().compare(string(".TRUE."))) s =  true;
18                        else s = false;
19                        return (this->iss);
20                }
21               
22        private : 
23                istringstream iss;
24};
25
26
27template <class Ctype>
28   class CAttribut : public CBaseAttribut
29{
30  public :
31 
32  bool hasValue ;
33  Ctype value ;
34
35  virtual const char * getName(void) const = 0 ;
36  CAttribut(void) : hasValue(false) {} ;
37  CAttribut(const Ctype& value_) : value(value_), hasValue(true) {} ;
38  CAttribut(const CAttribut& attr) : hasValue(attr.hasValue) 
39  {
40     if (hasValue) value=attr.value ;
41  } ;
42
43  CAttribut& operator = (const CAttribut & attr)
44  { 
45     hasValue=attr.hasValue ;
46     if (hasValue) value=attr.value ;
47     return *this ; 
48  } ;
49 
50  virtual const char * getType(void) const = 0;
51 
52   virtual void setFromString(const std::string str) 
53   {   
54           IStringStream_alt iss(str); Ctype val;
55           iss >> val;
56       this->setValue(val);
57   }   
58
59  operator Ctype()
60  {
61    if (!hasValue) error("CAttribut& CAttribut<Ctype>::operator Ctype")<<"access to undefined value of attribut <<"
62                                                                       <<this->getName()<<">>"<<endl;
63    return value ;
64  } ;
65
66  virtual ostream& print(ostream & o) const
67  {
68    //o<<"Attribut : "<<getName()<<"  ---->" ;
69    if (hasValue) o<< boolalpha <</*" value = "<<*/value ;
70    else o<< "/" ;
71    return o ;
72  }
73
74  virtual void setValue(const Ctype & value_)
75  {
76     hasValue=true ;
77     value=value_ ;
78  }
79
80  virtual void getValue(Ctype & value_) const
81  {
82    if (!hasValue)  error("void CAttribut<Ctype>::getValue")<<"access to undefined value of attribut <<"
83                                                               <<this->getName()<<">>"<<endl;
84    value_=value ;
85  }
86
87} ;
88
89
90 
91#endif
Note: See TracBrowser for help on using the repository browser.