Ignore:
Timestamp:
09/08/10 15:02:31 (14 years ago)
Author:
hozdoba
Message:

Mise à jour intermédiaire ...
A venir : commit d'une version stable intégrant l'écriture de fichiers NetCDF4.
(en cours de finalisation actuellement)

File:
1 edited

Legend:

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

    r119 r120  
    77using XMLIOSERVER::XMLIOUndefinedValueException; 
    88using std::ostringstream; 
     9using namespace blitz ; 
    910 
    1011namespace XMLIOSERVER 
    1112{ 
    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  
    3413   template <class Ctype> 
    3514      class Attribut : public BaseAttribut 
    3615   { 
    3716      public : 
    38  
    3917         operator Ctype() const 
    4018         { 
    41             if (!hasValue) throw XMLIOUndefinedValueException("L'attribut \"" + this->getName() + "\" est invalide !"); 
     19            if (!_hasValue) throw XMLIOUndefinedValueException("L'attribut \"" + this->getName() + "\" est invalide !"); 
    4220            return (value) ; 
    4321         } 
    4422 
    45          virtual bool _hasValue() const { return (hasValue); } 
     23         Ctype* operator ->() { return (&value) ; } 
     24         Ctype& operator *() { return (value) ; } 
    4625 
    47       protected : 
     26         virtual bool hasValue() const { return (_hasValue); } 
     27         virtual const char * getType(void) const = 0; 
    4828 
    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_) {} ; 
    5131 
    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 ; } 
    5434 
    5535         Attribut& operator = (const Attribut & attr) 
    5636         { 
    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) ; 
    6040         } 
    6141 
    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) 
    6543         { 
    66             IStringStream_alt iss(str); Ctype val; 
     44            istringstream iss(str); Ctype val; 
    6745            iss >> val; 
    6846            this->setValue(val); 
     
    7048 
    7149         virtual void assignValue(const BaseAttribut* _ba) 
    72          { value = ((Attribut*)_ba) -> value; hasValue = true; } 
     50         { value = ((Attribut*)_ba) -> value; _hasValue = true; } 
    7351 
    7452         virtual ostream& print(ostream & o) const 
    75          { if (hasValue) o << " " << getName() << "=\"" << boolalpha << value << "\"" ; return o ; } 
     53         { if (_hasValue) o << " " << getName() << "=\"" << boolalpha << value << "\"" ; return o ; } 
    7654 
    7755         virtual void setValue(const Ctype & value_) 
    78          { hasValue=true ; value=value_ ; } 
     56         { _hasValue = true ; value = value_ ;} 
    7957 
    8058         virtual void getValue(Ctype & value_) const 
    8159         { 
    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 ; 
    8462         } 
    8563 
    8664      private : 
    8765 
    88          bool hasValue ; 
     66         bool _hasValue ; 
    8967         Ctype value ; 
    9068 
    9169   }; // 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 
    9298} // namespace XMLIOSERVER 
    9399 
    94100#endif //__ATTRIBUT__ 
    95  
    96  
Note: See TracChangeset for help on using the changeset viewer.