Changeset 98 for XMLIO_V2/dev/trunk/src/XMLIO/attribut.hpp
- Timestamp:
- 06/04/10 16:18:34 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/trunk/src/XMLIO/attribut.hpp
r79 r98 1 #ifndef ATTRIBUT_HPP2 #define ATTRIBUT_HPP1 #ifndef __ATTRIBUT__ 2 #define __ATTRIBUT__ 3 3 4 4 #include "base_attribut.hpp" 5 #include "xmlio_std.hpp"6 5 7 template <class Ctype> 8 class CAttribut : public CBaseAttribut 6 using XMLIOSERVER::BaseAttribut; 7 using XMLIOSERVER::XMLIOUndefinedValueException; 8 using std::ostringstream; 9 10 namespace XMLIOSERVER 9 11 { 10 public : 11 12 bool hasValue ; 13 Ctype value ; 14 15 virtual const char * getName(void) const = 0 ; 16 CAttribut(void) : hasValue(false) {} ; 17 CAttribut(const Ctype& value_) : value(value_), hasValue(true) {} ; 18 CAttribut(const CAttribut& attr) : hasValue(attr.hasValue) 19 { 20 if (hasValue) value=attr.value ; 21 } ; 22 23 CAttribut& operator = (const CAttribut & attr) 24 { 25 hasValue=attr.hasValue ; 26 if (hasValue) value=attr.value ; 27 return *this ; 28 } ; 29 30 operator Ctype() 31 { 32 if (!hasValue) error("CAttribut& CAttribut<Ctype>::operator Ctype")<<"access to undefined value of attribut <<" 33 <<this->getName()<<">>"<<endl; 34 return value ; 35 } ; 36 37 virtual ostream& print(ostream & o) const 38 { 39 o<<"Attribut : "<<getName()<<" ---->" ; 40 if (hasValue) o<<" value = "<<value ; 41 else o<<" undefined value" ; 42 return o ; 43 } 44 45 virtual void setValue(const Ctype & value_) 46 { 47 hasValue=true ; 48 value=value_ ; 49 } 50 51 virtual void getValue(Ctype & value_) const 52 { 53 if (!hasValue) error("void CAttribut<Ctype>::getValue")<<"access to undefined value of attribut <<" 54 <<this->getName()<<">>"<<endl; 55 value_=value ; 56 } 57 58 } ; 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 59 31 60 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_) : 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() 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 61 102 62 #endif 103 #endif //__ATTRIBUT__
Note: See TracChangeset
for help on using the changeset viewer.