source: XIOS/dev/dev_rv/src4/xmlio/object.cpp @ 1129

Last change on this file since 1129 was 240, checked in by hozdoba, 13 years ago
File size: 2.8 KB
Line 
1/* ************************************************************************** *
2 *      Copyright © IPSL/LSCE, XMLIOServer, Avril 2010 - Octobre 2011         *
3 * ************************************************************************** */
4
5/**
6 * \file    object.cpp
7 * \brief   Base de tous les objets du projet XMLIOSERVER (implémentation).
8 * \author  Hervé Ozdoba
9 * \version 0.4
10 * \date    1er Juin 2011
11 */
12
13#ifndef __XIOS_NO_EXTERN
14
15// Boost headers
16#include <boost/none.hpp>
17
18#endif // __XIOS_NO_EXTERN
19
20// XMLIOServer headers
21#include "xmlioserver_spl.hpp"
22#include "object.hpp"
23
24// /////////////////////////////// Définitions ////////////////////////////// //
25
26namespace xmlioserver {
27
28   // ------------------------------ Constructeurs -----------------------------
29
30   //- Constructeur simple d'un objet anonyme (ie sans identifiant).
31   CObject::CObject(void) : id()
32   { /* Ne rien faire de plus */ }
33
34   //- Constructeur simple d'un objet identifié.
35   CObject::CObject(const std::string & id) : id(id)
36   { /* Ne rien faire de plus */ }
37
38   //- Constructeur par copie.
39   CObject::CObject(const CObject & object)
40      : id(object.id)
41   { /* Ne rien faire de plus */ }
42
43   // ------------------------------- Destructeur ------------------------------
44
45   //- Destructeur de l'objet.
46   CObject::~CObject(void)
47   { /* Ne rien faire de plus */ }
48
49   // ------------------------------- Accesseurs -------------------------------
50
51   //- Retourne l'identifiant de l'objet.
52   const std::string & CObject::getId(void) const
53   {
54      return (this->id.get());
55   }
56
57   // --------------------------- Tests sur l'objet ----------------------------
58
59   //- Indique si l'objet est identifié.
60   bool CObject::hasId(void) const
61   {
62      return (this->id);
63   }
64
65   // ------------------------------- Mutateurs --------------------------------
66
67   //- Supprime l'identifiant de l'objet, rendant ce dernier anonyme.
68   void CObject::resetId(void)
69   {
70      this->id = boost::none;
71   }
72
73   //- Assigne un identifiant à l'objet courant.
74   void CObject::setId(const std::string & id)
75   {
76      this->id = id ;
77   }
78
79   // ----------------------- Opérateurs de comparaison ------------------------
80
81   //- Indique si deux objets sont identiques.
82   bool CObject::operator==(const CObject & other) const
83   {
84      if(!this->hasId() || !other.hasId()) return (false);
85      return (this->id.get().compare(other.id.get()) == 0);
86   }
87
88   //- Indique si deux objets sont différents.
89   bool CObject::operator!=(const CObject & other) const
90   {
91      return (!(*this == other));
92   }
93
94   // --------------------------- Flux de sortie -------------------------------
95
96   //- Opérateur de flux de sortie ascii.
97   std::ostream & operator << (std::ostream & _os, const CObject & _object)
98   {
99      _os << _object.toString();
100      return (_os);
101   }
102
103} // namespace xmlioserver
Note: See TracBrowser for help on using the repository browser.