source: XMLIO_V2/dev/dev_rv/src/XMLIO/abstract_object.hpp @ 133

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

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

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