source: XMLIO_V2/dev/dev_rv/src4/xmlio/attribute/attribute_template_impl.hpp @ 257

Last change on this file since 257 was 257, checked in by hozdoba, 13 years ago

Ajout de classes pour la version 4

File size: 4.4 KB
Line 
1/* ************************************************************************** *
2 *      Copyright © IPSL/LSCE, XMLIOServer, Avril 2010 - Octobre 2011         *
3 * ************************************************************************** */
4
5#ifndef __ATTRIBUTE_TEMPLATE_IMPL_HPP__
6#define __ATTRIBUTE_TEMPLATE_IMPL_HPP__
7
8/**
9 * \file    attribute_template_impl.hpp
10 * \brief   Gestion des attributs typés d'objet (implémentation template).
11 * \author  Hervé Ozdoba
12 * \version 0.4
13 * \date    1er Juin 2011
14 */
15
16// /////////////////////////////// Définitions ////////////////////////////// //
17
18namespace xmlioserver {
19namespace tree {
20 
21   // ------------------------------ Constructeurs -----------------------------
22   
23   template <class ValueType>
24      CAttributeTemplate<ValueType>::CAttributeTemplate(const std::string & _id)
25         : CAttribute(_id)
26   { /* Ne rien faire de plus */ }
27
28   template <class ValueType>
29      CAttributeTemplate<ValueType>::CAttributeTemplate(const std::string & _id, const ValueType & _value)
30         : CAttribute(_id)
31   {
32      this->setValue(_value);
33   }
34
35   template <class ValueType>
36      CAttributeTemplate<ValueType>::CAttributeTemplate(const CAttribute & _attribute_ref) throw (CException)
37         : CAttribute(_attribute_ref)
38   {
39      if (!_attribute_ref.isEmpty() && !_attribute_ref.isType<ValueType>())
40         XIOS_ERROR("CAttributeTemplate(_attribute_ref)", << "Invalid instantiation !");
41   }
42
43   template <class ValueType>
44      CAttributeTemplate<ValueType>::CAttributeTemplate
45        (const std::string & _id, xios_map<std::string, CAttribute*> & _umap)
46           : CAttribute(_id)
47   {
48      _umap.insert(_umap.end(), std::make_pair(_id, this));
49   }
50
51   template <class ValueType>
52      CAttributeTemplate<ValueType>::CAttributeTemplate
53         (const std::string & _id, const ValueType & _value, xios_map<std::string, CAttribute*> & _umap)
54            : CAttribute(_id)
55   {
56      this->setValue(_value);
57      _umap.insert(_umap.end(), std::make_pair(_id, this));
58   }
59   
60   // ------------------------------- Destructeur ------------------------------
61   
62   template <class ValueType>
63      CAttributeTemplate<ValueType>::~CAttributeTemplate(void)
64   { 
65      this->clear();
66   }
67 
68   // ------------------------------- Accesseur --------------------------------
69
70   template <class ValueType>
71      ValueType CAttributeTemplate<ValueType>::getValue(void) const  throw (CException)
72   {
73      if (SuperClass::isEmpty())
74         XIOS_ERROR("ValueType CAttributeTemplate<ValueType>::getValue(void) const",
75                     << "[ id = " << this->getId() << "]"
76                     << " L'attribut est requis mais n'est pas défini !");
77      return (SuperClass::getValue<ValueType>());
78   }
79     
80   // ------------------------------- Mutateur ---------------------------------
81   
82   template <class ValueType>
83      void CAttributeTemplate<ValueType>::setValue(const ValueType & _value)
84   {
85      SuperClass::setValue<ValueType>(_value);
86   }
87
88   // ------------------------------- Opérateur --------------------------------
89
90   template <class ValueType>
91      ValueType CAttributeTemplate<ValueType>::operator=(const ValueType & _value)
92   {
93      this->setValue(_value);  return (this->getValue());
94   }
95
96   // -------------------------- Conversion en chaîne --------------------------
97
98   template <class ValueType>
99      std::string CAttributeTemplate<ValueType>::toString(void) const
100   {
101      std::ostringstream oss;
102      if (!this->isEmpty() && this->hasId())
103         oss << this->getName() << "=\"" << this->getValue() << "\"";
104      return (oss.str());
105   }
106
107   template <class ValueType>
108      void CAttributeTemplate<ValueType>::fromString(const std::string & _str)
109   {
110      XIOS_ERROR("CAttributeTemplate<ValueType>::fromString(const std::string & str)",
111                  << "[ str = " << _str << " ] Not implemented yet !");
112   }
113
114   // -------------------------- Conversion binaire ----------------------------
115
116   template <class ValueType>
117     void CAttributeTemplate<ValueType>::toBinary (std::ostream & _os) const
118   {
119      this->getValue()->toBinary(_os);
120   }
121
122   template <class ValueType>
123      void CAttributeTemplate<ValueType>::fromBinary(std::istream & _is)
124   {
125      ValueType value;
126      FromBinary(_is, value);
127      this->setValue(value);
128   } 
129     
130} // namespace tree
131} // namespace xmlioserver
132
133#endif  // __ATTRIBUTE_TEMPLATE_IMPL_HPP__
Note: See TracBrowser for help on using the repository browser.