source: vendor/nemo/current/NEMOGCM/EXTERNAL/XIOS/src/type/type_specialisation.hpp @ 44

Last change on this file since 44 was 44, checked in by cholod, 12 years ago

Load NEMO_TMP into vendor/nemo/current.

File size: 4.6 KB
Line 
1#ifndef __XIOS_TYPE_SPECIALISATION_HPP__
2#define __XIOS_TYPE_SPECIALISATION_HPP__
3
4#include "xmlioserver_spl.hpp"
5#include "exception.hpp"
6#include "buffer_in.hpp"
7#include "buffer_out.hpp"
8#include "array.hpp"
9
10namespace xios
11{
12
13
14// template specialisation for string
15
16  template <>
17  size_t CType<string>::size() const
18  {
19    size_t typeSize=0 ;
20    typeSize+=sizeof(size_t) ;
21    typeSize+=ptrValue->size() ;
22    return typeSize ;
23  }
24 
25  template <>
26  bool CType<string>::toBuffer(CBufferOut& buffer) const
27  {
28    if (buffer.remain()<size()) return false ;
29    else
30    {
31      bool ret=true ;
32      if (ret) ret&=buffer.put(ptrValue->size()) ;
33      if (ret) ret&=buffer.put(ptrValue->data(),ptrValue->size()) ;
34      return ret ;
35    }
36  }
37
38  template <>
39  bool CType<string>::fromBuffer(CBufferIn& buffer)
40  {
41    bool ret=true ;
42    size_t typeSize ;
43    if (ret) ret&=buffer.get(typeSize) ;
44   
45    char* str;
46    str= (char*) buffer.ptr() ;
47    if (ret) buffer.advance(typeSize) ;
48    if (ret) *ptrValue=string(str,typeSize) ;
49   
50    return ret ;
51  } 
52 
53 
54  // template specialisation for CArray
55/*
56  template<>
57  size_t CType< ARRAY(int, 1)>::size() const
58  {
59     return (*(this->ptrValue))->getSize() ;
60  }
61 
62  template <>
63  bool CType<ARRAY(int, 1)>::toBuffer(CBufferOut& buffer) const
64  {
65      return (*(this->ptrValue))->toBuffer(buffer) ;
66  }
67
68  template <>
69  bool CType<ARRAY(int, 1)>::fromBuffer(CBufferIn& buffer) const
70  {
71    return (*(this->ptrValue))->fromBuffer(buffer) ;
72  }
73
74  template <>
75  void CType<ARRAY(int, 1)>::fromString(const string& str) const
76  {
77 // to implement
78  }
79
80  template <>
81  string CType<ARRAY(int, 1)>::toString(void) const
82  {
83 // to implement
84   return string("") ;
85 
86  }
87*/
88
89
90/*
91template<size_t numDim>
92boost::detail::multi_array::extent_gen<numDim> getExtentNull(void) { return getExtentNull<numDim-1>()[0];}
93
94template<>
95boost::detail::multi_array::extent_gen<1> getExtentNull<1>(void) { return extents[0]; }
96*/
97
98#define CTYPE_ARRAY(ValueType,NumsDims)                                \ 
99  template<>                                                           \
100  size_t CType< ARRAY(ValueType,NumsDims)>::size() const                           \
101  {                                                                    \
102     return (*(this->ptrValue))->getSize() ;                           \
103  }                                                                    \
104                                                                       \
105  template <>                                                          \
106  bool CType<ARRAY(ValueType,NumsDims)>::toBuffer(CBufferOut& buffer) const        \
107  {                                                                    \
108      return (*(this->ptrValue))->toBuffer(buffer) ;                   \
109  }                                                                    \
110                                                                       \
111  template <>                                                          \
112  bool CType<ARRAY(ValueType,NumsDims)>::fromBuffer(CBufferIn& buffer)       \
113  {                                                                    \
114    shared_ptr<CArray<ValueType, NumsDims> > tmp(new CArray<ValueType, NumsDims>() ) ; \
115    *(this->ptrValue)=tmp ;\
116    return (*(this->ptrValue))->fromBuffer(buffer) ;                   \
117  }                                                                    \
118                                                                       \
119  template <>                                                          \
120  void CType<ARRAY(ValueType,NumsDims)>::fromString(const string& str)       \
121  {                                                                    \
122 /* to implement */                                                    \
123  }                                                                    \
124                                                                       \
125  template <>                                                          \
126  string CType<ARRAY(ValueType,NumsDims)>::toString(void) const                    \
127  {                                                                    \
128 /* to implement */                                                    \
129   return string("") ;                                                 \
130  }
131
132//CTYPE_ARRAY(double,1)
133
134//CTYPE_ARRAY(double,2)
135
136
137CTYPE_ARRAY(int,1)
138CTYPE_ARRAY(int,2)
139CTYPE_ARRAY(int,3)
140CTYPE_ARRAY(bool,1) 
141CTYPE_ARRAY(bool,2) 
142CTYPE_ARRAY(bool,3) 
143CTYPE_ARRAY(double,1) 
144CTYPE_ARRAY(double,2) 
145CTYPE_ARRAY(double,3) 
146CTYPE_ARRAY(float,1) 
147CTYPE_ARRAY(float,2) 
148CTYPE_ARRAY(float,3) 
149
150} 
151
152#endif 
Note: See TracBrowser for help on using the repository browser.