Changeset 126 for XMLIO_V2/dev/dev_rv/src/XMLIO/attribut.hpp
- Timestamp:
- 10/07/10 10:29:38 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/dev_rv/src/XMLIO/attribut.hpp
r122 r126 15 15 { 16 16 public : 17 18 Attribut(void) 19 : BaseAttribut(), _hasValue(false) 20 { /* Ne rien faire de plus */ } 21 22 Attribut(const Ctype& value_) 23 : BaseAttribut(), _hasValue(true), value(value_) 24 { /* Ne rien faire de plus */ } 25 26 Attribut(const Attribut& attr) 27 : BaseAttribut(attr), _hasValue(attr._hasValue) 28 { if (_hasValue) value = attr.value ; } 29 30 Attribut& operator = (const Attribut & attr) 31 { 32 _hasValue = attr._hasValue ; 33 if (_hasValue) this->setValue(attr.value) ; 34 return (*this) ; 35 } 36 17 37 operator Ctype() const 18 38 { … … 21 41 } 22 42 23 Ctype* operator ->( ) { return (&value); }24 Ctype& operator * () { return (value) ; }43 Ctype* operator ->(void) { return (&value); } 44 Ctype& operator * (void) { return (value) ; } 25 45 26 virtual bool hasValue() const { return (_hasValue); } 46 public : /* virtual */ 47 48 virtual bool hasValue(void) const { return (_hasValue); } 27 49 virtual const char * getType(void) const = 0; 28 29 Attribut(void) : _hasValue(false) {} ;30 Attribut(const Ctype& value_) : _hasValue(true), value(value_) {} ;31 32 Attribut(const Attribut& attr) : _hasValue(attr._hasValue)33 { if (_hasValue) value = attr.value ; }34 35 Attribut& operator = (const Attribut & attr)36 {37 _hasValue = attr._hasValue ;38 if (_hasValue) setValue(attr.value) ;39 return (*this) ;40 }41 50 42 51 virtual void setFromString(const std::string& str) … … 50 59 { value = ((Attribut*)_ba) -> value; _hasValue = true; } 51 60 52 virtual ostream& print( ostream & o) const53 { if (_hasValue) o << " " << getName() << "=\"" << boolalpha << value << "\"" ; return o; }61 virtual ostream& print(std::ostream & _out) const 62 { if (_hasValue) _out << " " << getName() << "=\"" << boolalpha << value << "\"" ; return (_out) ; } 54 63 55 64 virtual void setValue(const Ctype & value_) … … 62 71 } 63 72 73 virtual ~Attribut() 74 { /* Ne rien faire de plus */ } 75 64 76 private : 65 77 … … 69 81 }; // class Attribut 70 82 71 #define SET_ARRAY_DIM(type, dim)\83 #define SET_ARRAY_DIM(type, dim) \ 72 84 template<> \ 73 85 void Attribut<Array<type,dim> >::setValue (const Array<type,dim>& val) \ … … 88 100 { 89 101 if (_hasValue) o << " " << getName() << "=\"" << value(0); 90 for (int i = 1; i < value.size(); i++) { o << "," << value(i); } 102 /*for (int i = 1; i < value.size(); i++) 103 { o << "," << value(i); }*/ 104 o << value(0) << "..." << value(value.size()-1); 91 105 o << "\"" ; 92 106 return (o) ; … … 94 108 95 109 template <> 96 void Attribut<Array<double,1> >::setFromString(const std::string& str)110 void Attribut<Array<double,1> >::setFromString(const std::string& _str) 97 111 { 98 istringstream iss( str) ;99 char c = '\0'; double d = 0.;100 vector<double> vect;101 Array<double, 1> arr;112 istringstream iss(_str) ; 113 char c = '\0'; int size = 0; 114 double d = 0.,valsup = 0., valinf = 0.; 115 std::vector<double> vect; Array<double, 1> arr; 102 116 103 117 iss >> d; vect.push_back(d); 104 while(!iss.eof ()) { iss >> c >> d; vect.push_back(d); } 118 if (!iss.eof ()) 119 { 120 iss >> c; 121 switch (c) 122 { 123 case ',' : // Le tableau est généré valeur par valeur. 124 iss.unget(); 125 while(!iss.eof ()) 126 { // On récupÚre chacune des valeurs une par une jusqu'à ce que le buffer soit vide. 127 iss >> c >> d; 128 if (c != ',') 129 throw XMLIOUndefinedValueException("Le tableau de valeur est mal défini !"); 130 vect.push_back(d); 131 } 132 size = vect.size(); 133 break; 134 case '(' : // Le tableau est généré automatiquement. 135 if (!iss.eof ()) 136 { // on récupÚre la borne supérieure 137 valinf = d; 138 iss >> size >> c >> d; 139 if ((c != ')') || (size <= 0)) 140 throw XMLIOUndefinedValueException("Le tableau de valeur est mal défini !"); 141 valsup = d; 142 } 143 d = (valsup - valinf) / (double)(size - 1); 144 for (int j = 1; j <= size; j++) 145 vect.push_back(valinf + j * d); 146 break; 147 default : 148 throw XMLIOUndefinedValueException("Le tableau de valeur est mal défini !"); 149 } 150 } 105 151 106 arr.resize(vect.size()); 107 for (unsigned int i = 0; i < vect.size(); i++) arr(i) = vect[i]; 152 arr.resize(size); 153 for (int i = 0; i < size; i++) 154 arr(i) = vect[i]; 108 155 109 156 this->setValue(arr); … … 114 161 { 115 162 istringstream iss(str) ; 116 bool val = (! iss.str().compare(string(".TRUE."))) ? true : false;163 const bool val = (! iss.str().compare(string(".TRUE."))) ? true : false; 117 164 this->setValue(val); 118 165 }
Note: See TracChangeset
for help on using the changeset viewer.