Ignore:
Timestamp:
10/07/10 10:29:38 (14 years ago)
Author:
hozdoba
Message:

Amélioration de quelques portions de code.
Ajout de contructeurs par copie.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XMLIO_V2/dev/dev_rv/src/XMLIO/attribut.hpp

    r122 r126  
    1515   { 
    1616      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 
    1737         operator Ctype() const 
    1838         { 
     
    2141         } 
    2242 
    23          Ctype* operator ->() { return (&value) ; } 
    24          Ctype& operator *() { return (value) ; } 
     43         Ctype* operator ->(void) { return (&value); } 
     44         Ctype& operator * (void) { return (value) ; } 
    2545 
    26          virtual bool hasValue() const { return (_hasValue); } 
     46      public : /* virtual */ 
     47 
     48         virtual bool hasValue(void) const { return (_hasValue); } 
    2749         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          } 
    4150 
    4251         virtual void setFromString(const std::string& str) 
     
    5059         { value = ((Attribut*)_ba) -> value; _hasValue = true; } 
    5160 
    52          virtual ostream& print(ostream & o) const 
    53          { 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) ; } 
    5463 
    5564         virtual void setValue(const Ctype & value_) 
     
    6271         } 
    6372 
     73         virtual ~Attribut() 
     74         { /* Ne rien faire de plus */ } 
     75 
    6476      private : 
    6577 
     
    6981   }; // class Attribut 
    7082 
    71 #define SET_ARRAY_DIM(type,dim)                                              \ 
     83#define SET_ARRAY_DIM(type, dim)                                             \ 
    7284   template<>                                                                \ 
    7385      void Attribut<Array<type,dim> >::setValue (const Array<type,dim>& val) \ 
     
    88100   { 
    89101      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); 
    91105      o << "\"" ; 
    92106      return (o) ; 
     
    94108 
    95109   template <> 
    96       void Attribut<Array<double,1> >::setFromString(const std::string& str) 
     110      void Attribut<Array<double,1> >::setFromString(const std::string& _str) 
    97111   { 
    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; 
    102116 
    103117      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      } 
    105151 
    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]; 
    108155 
    109156      this->setValue(arr); 
     
    114161   { 
    115162      istringstream iss(str) ; 
    116       bool val = (! iss.str().compare(string(".TRUE."))) ? true : false; 
     163      const bool val = (! iss.str().compare(string(".TRUE."))) ? true : false; 
    117164      this->setValue(val); 
    118165   } 
Note: See TracChangeset for help on using the changeset viewer.