Changeset 120 for XMLIO_V2/dev/dev_rv/src/XMLIO/attribut.hpp
- Timestamp:
- 09/08/10 15:02:31 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/dev_rv/src/XMLIO/attribut.hpp
r119 r120 7 7 using XMLIOSERVER::XMLIOUndefinedValueException; 8 8 using std::ostringstream; 9 using namespace blitz ; 9 10 10 11 namespace XMLIOSERVER 11 12 { 12 class IStringStream_alt13 {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_alt32 33 34 13 template <class Ctype> 35 14 class Attribut : public BaseAttribut 36 15 { 37 16 public : 38 39 17 operator Ctype() const 40 18 { 41 if (! hasValue) throw XMLIOUndefinedValueException("L'attribut \"" + this->getName() + "\" est invalide !");19 if (!_hasValue) throw XMLIOUndefinedValueException("L'attribut \"" + this->getName() + "\" est invalide !"); 42 20 return (value) ; 43 21 } 44 22 45 virtual bool _hasValue() const { return (hasValue); } 23 Ctype* operator ->() { return (&value) ; } 24 Ctype& operator *() { return (value) ; } 46 25 47 protected : 26 virtual bool hasValue() const { return (_hasValue); } 27 virtual const char * getType(void) const = 0; 48 28 49 Attribut(void) : hasValue(false) {} ;50 Attribut(const Ctype& value_) : hasValue(true), value(value_) {} ;29 Attribut(void) : _hasValue(false) {} ; 30 Attribut(const Ctype& value_) : _hasValue(true), value(value_) {} ; 51 31 52 Attribut(const Attribut& attr) : hasValue(attr.hasValue)53 { if ( hasValue) value=attr.value ; }32 Attribut(const Attribut& attr) : _hasValue(attr._hasValue) 33 { if (_hasValue) value = attr.value ; } 54 34 55 35 Attribut& operator = (const Attribut & attr) 56 36 { 57 hasValue=attr.hasValue ;58 if ( hasValue) value=attr.value;59 return *this;37 _hasValue = attr._hasValue ; 38 if (_hasValue) setValue(attr.value) ; 39 return (*this) ; 60 40 } 61 41 62 virtual const char * getType(void) const = 0; 63 64 virtual void setFromString(const std::string str) 42 virtual void setFromString(const std::string& str) 65 43 { 66 IStringStream_altiss(str); Ctype val;44 istringstream iss(str); Ctype val; 67 45 iss >> val; 68 46 this->setValue(val); … … 70 48 71 49 virtual void assignValue(const BaseAttribut* _ba) 72 { value = ((Attribut*)_ba) -> value; hasValue = true; }50 { value = ((Attribut*)_ba) -> value; _hasValue = true; } 73 51 74 52 virtual ostream& print(ostream & o) const 75 { if ( hasValue) o << " " << getName() << "=\"" << boolalpha << value << "\"" ; return o ; }53 { if (_hasValue) o << " " << getName() << "=\"" << boolalpha << value << "\"" ; return o ; } 76 54 77 55 virtual void setValue(const Ctype & value_) 78 { hasValue=true ; value=value_ ;}56 { _hasValue = true ; value = value_ ;} 79 57 80 58 virtual void getValue(Ctype & value_) const 81 59 { 82 if (! hasValue) throw XMLIOUndefinedValueException("L'attribut \"" + this->getName() + "\" est invalide !");83 value_ =value ;60 if (!_hasValue) throw XMLIOUndefinedValueException("L'attribut \"" + this->getName() + "\" est invalide !"); 61 value_ = value ; 84 62 } 85 63 86 64 private : 87 65 88 bool hasValue ;66 bool _hasValue ; 89 67 Ctype value ; 90 68 91 69 }; // class Attribut 70 71 #define SET_ARRAY_DIM(type,dim) \ 72 template<> \ 73 void Attribut<Array<type,dim> >::setValue (const Array<type,dim>& val) \ 74 { _hasValue = true ; value.resize(val.shape()); value = val ; } 75 76 #define SET_ARRAY_TYPE(type) \ 77 SET_ARRAY_DIM(type,1) \ 78 SET_ARRAY_DIM(type,2) \ 79 SET_ARRAY_DIM(type,3) \ 80 SET_ARRAY_DIM(type,4) 81 82 SET_ARRAY_TYPE(double) 83 SET_ARRAY_TYPE(int) 84 SET_ARRAY_TYPE(bool) 85 86 template <> 87 void Attribut<bool>::setFromString(const std::string& str) 88 { 89 istringstream iss(str) ; 90 bool val = (! iss.str().compare(string(".TRUE."))) ? true : false; 91 this->setValue(val); 92 } 93 94 template <> 95 void Attribut<string>::setFromString(const std::string& str) 96 { this->setValue(str); } 97 92 98 } // namespace XMLIOSERVER 93 99 94 100 #endif //__ATTRIBUT__ 95 96
Note: See TracChangeset
for help on using the changeset viewer.