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

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

Insensibitilité à la casse des noms de balises et d'attributs (ex : field_definition <=> FieLd_DefiNition, id <=> ID, etc .) .
Traitement sur les attributs, les chaînes de caractÚres sont désormais dépourvues d'espaces en début et fin.

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)
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         bool hasValue ;
40         Ctype value ;
41
42         virtual bool _hasValue() const { return hasValue; }
43
44         Attribut(void) : hasValue(false) {} ;
45         Attribut(const Ctype& value_) : hasValue(true), value(value_) {} ;
46
47         Attribut(const Attribut& attr) : hasValue(attr.hasValue)
48         {  if (hasValue) value=attr.value ; }
49
50         Attribut& operator = (const Attribut & attr)
51         {
52            hasValue=attr.hasValue ;
53            if (hasValue) value=attr.value ;
54            return *this ;
55         }
56
57         virtual const char * getType(void) const = 0;
58
59         virtual void setFromString(const std::string str)
60         {
61            IStringStream_alt iss(str); Ctype val;
62            iss >> val;
63            this->setValue(val);
64         }
65
66         operator Ctype() const
67         {
68            if (!hasValue) throw XMLIOUndefinedValueException("L'attribut \"" + this->getName() + "\" est invalide !");
69            return value ;
70         }
71
72         virtual void assignValue(const BaseAttribut* _ba)
73         { value = ((Attribut*)_ba) -> value; hasValue = true; }
74
75         virtual ostream& print(ostream & o) const
76         { if (hasValue) o << " " << getName() << "=\"" << boolalpha << value << "\"" ; return o ; }
77
78         virtual void setValue(const Ctype & value_)
79         { hasValue=true ; value=value_ ; }
80
81         virtual void getValue(Ctype & value_) const
82         {
83            if (!hasValue) throw XMLIOUndefinedValueException("L'attribut \"" + this->getName() + "\" est invalide !");
84            value_=value ;
85         }
86
87   }; // class Attribut
88}; // namespace XMLIOSERVER
89
90#endif //__ATTRIBUT__
Note: See TracBrowser for help on using the repository browser.