1 | #ifndef __XMLIO_OBJECT__ |
---|
2 | #define __XMLIO_OBJECT__ |
---|
3 | |
---|
4 | // Classes utilisées issues de la STL |
---|
5 | using std::pair; |
---|
6 | using std::string; |
---|
7 | using std::ostream; |
---|
8 | using std::ostringstream; |
---|
9 | |
---|
10 | // Classes XMLIOSERVER |
---|
11 | using XMLIOSERVER::XMLIOException; |
---|
12 | using XMLIOSERVER::XMLIOUndefinedValueException; |
---|
13 | |
---|
14 | namespace 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__ |
---|