source: XMLIO_V2/dev/dev_rv/xmlio_object.hpp @ 88

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

Version expérimentale, commit pour sauvegarde.

File size: 2.0 KB
Line 
1#ifndef __XMLIO_OBJECT__
2#define __XMLIO_OBJECT__
3
4// Classes utilisées issues de la STL
5using std::pair;
6using std::string;
7using std::ostream;
8using std::ostringstream;
9
10// Classes XMLIOSERVER
11using XMLIOSERVER::XMLIOException;
12using XMLIOSERVER::XMLIOUndefinedValueException;
13
14namespace XMLIOSERVER
15{
16   class AbstractObject 
17   {
18      public :
19     
20         AbstractObject(void) : IdDefined(false)
21         {/* Ne rien faire de plus */}
22         
23         AbstractObject(const string& _id) : id(_id), IdDefined(true)
24         {/* Ne rien faire de plus */}     
25   
26         const string& getId(void) throw (XMLIOUndefinedValueException)
27         { if (!IdDefined) throw XMLIOUndefinedValueException("Appel de la méthode AbstractObject::getId invalide."); return (id); }   
28         
29         bool hasId(void) const { return(IdDefined); }
30         void resetId(void) { IdDefined = false ;}
31         void setId(const string& _id) { id = _id ; IdDefined = true ;}
32         
33         bool operator==(const AbstractObject& other)
34         {
35            // Si l'un ou l'autre des objets n'a pas d'identifiant, les objets de ne sont pas "égaux".
36            if(!this->hasId() or !other.hasId()) return false;
37            return (id.compare(other.id) == 0);
38         }
39         
40         friend ostream& operator<< (ostream& out, const AbstractObject& c) 
41         { out << c.toString(); return (out);}   
42         
43         virtual ~AbstractObject(void)
44         {/* Ne rien faire de plus */}
45     
46      protected :
47     
48         virtual string toString(void) const
49         {
50            ostringstream st("[");
51            st << "[" << this->getName();
52            if (hasId()) st << " id=\"" <<  id << "\"";
53            st << "]" ;
54            return (st.str());
55         }
56         
57         virtual const char* getName(void) const {return ("AbstractObject"); }
58           
59      private :
60     
61         string id ;
62         bool IdDefined ;
63     
64   };// class AbstractObject
65   
66}// namespace XMLIOSERVER
67
68#endif // __XMLIO_OBJECT__   
Note: See TracBrowser for help on using the repository browser.