source: XMLIO_V2/dev/trunk/src/XMLIO/attribut.hpp @ 79

Last change on this file since 79 was 79, checked in by ymipsl, 14 years ago

import dev/trunk

File size: 1.4 KB
Line 
1#ifndef ATTRIBUT_HPP
2#define ATTRIBUT_HPP
3
4#include "base_attribut.hpp"
5#include "xmlio_std.hpp"
6
7template <class Ctype>
8class CAttribut : public CBaseAttribut
9{
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} ;
59
60
61 
62#endif
Note: See TracBrowser for help on using the repository browser.