source: XMLIO_V2/dev/dev_rv/src/XMLIO/attribut.hpp @ 118

Last change on this file since 118 was 114, checked in by hozdoba, 14 years ago

Le code respecte davantage la norme C++ 98 pour le portage sur les différentes plate-formes,

Une compilation plus restrictive passe sans problÚme sous gcc avec les options de compilation suivantes :
"-W -Wall -Wextra -Werror -ansi -pedantic "
et le retrait de certain avertissements :
-Wno-ignored-qualifiers < plusieurs avertissements dans Blitz.
-Wno-unused-parameter < des paramÚtres ne sont pas utilisés dans la classe BaseAttribut? (voir les get/set)
-Wno-long-long < besoin des long long pour le calendrier.

File size: 2.5 KB
RevLine 
[98]1#ifndef __ATTRIBUT__
2#define __ATTRIBUT__
[79]3
4#include "base_attribut.hpp"
5
[98]6using XMLIOSERVER::BaseAttribut;
7using XMLIOSERVER::XMLIOUndefinedValueException;
8using std::ostringstream;
9
10namespace XMLIOSERVER
[79]11{
[98]12   class IStringStream_alt
13   {
[108]14      public :
[98]15         IStringStream_alt(const std::string& str) : iss(str)
16         { /* Ne rien faire de plus */}
[108]17
[111]18         istream& operator>> (std::string& s)
19         {s.assign(this->iss.str()); return (this->iss);}
[98]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         }
[108]27
28      private :
[98]29         istringstream iss;
[108]30
[98]31   }; // class IStringStream_alt
[79]32
33
[98]34   template <class Ctype>
35      class Attribut : public BaseAttribut
36   {
37      public :
[108]38
[113]39         operator Ctype() const
40         {
41            if (!hasValue) throw XMLIOUndefinedValueException("L'attribut \"" + this->getName() + "\" est invalide !");
42            return (value) ;
43         }
[79]44
[113]45         virtual bool _hasValue() const { return (hasValue); }
[108]46
[113]47      protected :
48
[98]49         Attribut(void) : hasValue(false) {} ;
50         Attribut(const Ctype& value_) : hasValue(true), value(value_) {} ;
[108]51
52         Attribut(const Attribut& attr) : hasValue(attr.hasValue)
[98]53         {  if (hasValue) value=attr.value ; }
[79]54
[98]55         Attribut& operator = (const Attribut & attr)
[108]56         {
[98]57            hasValue=attr.hasValue ;
58            if (hasValue) value=attr.value ;
[108]59            return *this ;
[98]60         }
[108]61
[98]62         virtual const char * getType(void) const = 0;
[108]63
64         virtual void setFromString(const std::string str)
65         {
[98]66            IStringStream_alt iss(str); Ctype val;
67            iss >> val;
68            this->setValue(val);
[108]69         }
[79]70
[104]71         virtual void assignValue(const BaseAttribut* _ba)
72         { value = ((Attribut*)_ba) -> value; hasValue = true; }
[79]73
[98]74         virtual ostream& print(ostream & o) const
[104]75         { if (hasValue) o << " " << getName() << "=\"" << boolalpha << value << "\"" ; return o ; }
[79]76
[98]77         virtual void setValue(const Ctype & value_)
78         { hasValue=true ; value=value_ ; }
[108]79
[98]80         virtual void getValue(Ctype & value_) const
81         {
[108]82            if (!hasValue) throw XMLIOUndefinedValueException("L'attribut \"" + this->getName() + "\" est invalide !");
[98]83            value_=value ;
84         }
[79]85
[113]86      private :
87
88         bool hasValue ;
89         Ctype value ;
90
[108]91   }; // class Attribut
[114]92} // namespace XMLIOSERVER
[108]93
[98]94#endif //__ATTRIBUT__
Note: See TracBrowser for help on using the repository browser.