bes  Updated for version 3.20.10
DmrppTypeFactory.cc
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of the BES
4 
5 // Copyright (c) 2016 OPeNDAP, Inc.
6 // Author: James Gallagher <jgallagher@opendap.org>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 //
22 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
23 
24 #include "config.h"
25 
26 #include <string>
27 
28 #include <BESError.h>
29 #include <BESDebug.h>
30 
31 #include "DmrppByte.h"
32 
33 #include "DmrppInt8.h"
34 
35 #include "DmrppInt16.h"
36 #include "DmrppUInt16.h"
37 #include "DmrppInt32.h"
38 #include "DmrppUInt32.h"
39 
40 #include "DmrppInt64.h"
41 #include "DmrppUInt64.h"
42 
43 #include "DmrppFloat32.h"
44 #include "DmrppFloat64.h"
45 
46 #include "DmrppStr.h"
47 #include "DmrppUrl.h"
48 
49 #include "DmrppD4Enum.h"
50 
51 #include "DmrppD4Opaque.h"
52 
53 #include "DmrppArray.h"
54 #include "DmrppStructure.h"
55 
56 #include "DmrppD4Sequence.h"
57 #include "DmrppD4Group.h"
58 
59 #include "DmrppTypeFactory.h"
60 
61 using namespace libdap;
62 using namespace std;
63 
64 #define prolog string("DmrppTypeFactory::").append(__func__).append("() - ")
65 #define MODULE "dmrpp"
66 
67 namespace dmrpp {
68 
69 BaseType *DmrppTypeFactory::NewVariable(Type t, const string &name) const
70 {
71  switch (t) {
72  case dods_byte_c:
73  return NewByte(name);
74  case dods_char_c:
75  return NewChar(name);
76 
77  case dods_uint8_c:
78  return NewUInt8(name);
79  case dods_int8_c:
80  return NewInt8(name);
81 
82  case dods_int16_c:
83  return NewInt16(name);
84  case dods_uint16_c:
85  return NewUInt16(name);
86  case dods_int32_c:
87  return NewInt32(name);
88  case dods_uint32_c:
89  return NewUInt32(name);
90 
91  case dods_int64_c:
92  return NewInt64(name);
93  case dods_uint64_c:
94  return NewUInt64(name);
95 
96  case dods_float32_c:
97  return NewFloat32(name);
98  case dods_float64_c:
99  return NewFloat64(name);
100 
101  case dods_str_c:
102  return NewStr(name);
103  case dods_url_c:
104  return NewURL(name);
105 
106  case dods_enum_c:
107  return NewEnum(name);
108 
109  case dods_opaque_c:
110  return NewOpaque(name);
111 
112  case dods_array_c:
113  return NewArray(name);
114 
115  case dods_structure_c:
116  return NewStructure(name);
117 
118  case dods_sequence_c:
119  return NewD4Sequence(name);
120 
121  case dods_group_c:
122  return NewGroup(name);
123 
124  default:
125  throw BESError("Unimplemented type in DAP4.", BES_INTERNAL_ERROR, __FILE__, __LINE__);
126  }
127 }
128 
129 Byte *
130 DmrppTypeFactory::NewByte(const string &n) const
131 {
132  BESDEBUG(MODULE, prolog << "Making a new DmrppByte object named: " << n << endl);
133  return new DmrppByte(n, d_dmz);
134 }
135 
136 Byte *
137 DmrppTypeFactory::NewChar(const string &n) const
138 {
139  BESDEBUG(MODULE, prolog << "Making a new DmrppByte object named: " << n << endl);
140  Byte *b = new DmrppByte(n, d_dmz);
141  b->set_type(dods_char_c);
142  return b;
143 }
144 
145 Byte *
146 DmrppTypeFactory::NewUInt8(const string &n) const
147 {
148  BESDEBUG(MODULE, prolog << "Making a new DmrppUInt8 object named: " << n << endl);
149  Byte *b = new DmrppByte(n, d_dmz);
150  b->set_type(dods_uint8_c);
151  return b;
152 }
153 
154 Int8 *
155 DmrppTypeFactory::NewInt8(const string &n) const
156 {
157  BESDEBUG(MODULE, prolog << "Making a new DmrppInt8 object named: " << n << endl);
158  return new DmrppInt8(n, d_dmz);
159 }
160 
161 Int16 *
162 DmrppTypeFactory::NewInt16(const string &n) const
163 {
164  BESDEBUG(MODULE, prolog << "Making a new DmrppInt16 object named: " << n << endl);
165  return new DmrppInt16(n, d_dmz);
166 }
167 
168 UInt16 *
169 DmrppTypeFactory::NewUInt16(const string &n) const
170 {
171  BESDEBUG(MODULE, prolog << "Making a new DmrppUInt16 object named: " << n << endl);
172  return new DmrppUInt16(n, d_dmz);
173 }
174 
175 Int32 *
176 DmrppTypeFactory::NewInt32(const string &n) const
177 {
178  BESDEBUG(MODULE, prolog << "Making a new DmrppInt32 object named: " << n << endl);
179  return new DmrppInt32(n, d_dmz);
180 }
181 
182 UInt32 *
183 DmrppTypeFactory::NewUInt32(const string &n) const
184 {
185  BESDEBUG(MODULE, prolog << "Making a new DmrppUInt32 object named: " << n << endl);
186  return new DmrppUInt32(n, d_dmz);
187 }
188 
189 Int64 *
190 DmrppTypeFactory::NewInt64(const string &n) const
191 {
192  BESDEBUG(MODULE, prolog << "Making a new DmrppInt64 object named: " << n << endl);
193  return new DmrppInt64(n, d_dmz);
194 }
195 
196 UInt64 *
197 DmrppTypeFactory::NewUInt64(const string &n) const
198 {
199  BESDEBUG(MODULE, prolog << "Making a new DmrppUInt64 object named: " << n << endl);
200  return new DmrppUInt64(n, d_dmz);
201 }
202 
203 Float32 *
204 DmrppTypeFactory::NewFloat32(const string &n) const
205 {
206  BESDEBUG(MODULE, prolog << "Making a new DmrppFloat32 object named: " << n << endl);
207  return new DmrppFloat32(n, d_dmz);
208 }
209 
210 Float64 *
211 DmrppTypeFactory::NewFloat64(const string &n) const
212 {
213  BESDEBUG(MODULE, prolog << "Making a new DmrppFloat64 object named: " << n << endl);
214  return new DmrppFloat64(n, d_dmz);
215 }
216 
217 Str *
218 DmrppTypeFactory::NewStr(const string &n) const
219 {
220  BESDEBUG(MODULE, prolog << "Making a new DmrppStr object named: " << n << endl);
221  return new DmrppStr(n, d_dmz);
222 }
223 
224 Url *
225 DmrppTypeFactory::NewUrl(const string &n) const
226 {
227  return new DmrppUrl(n, d_dmz);
228 }
229 
232 Url *
233 DmrppTypeFactory::NewURL(const string &n) const
234 {
235  return NewUrl(n);
236 }
237 
238 D4Opaque *
239 DmrppTypeFactory::NewOpaque(const string &n) const
240 {
241  return new DmrppD4Opaque(n, d_dmz);
242 }
243 
244 D4Enum *
245 DmrppTypeFactory::NewEnum(const string &name, Type type) const
246 {
247  return new DmrppD4Enum(name, type);
248 }
249 
250 Array *
251 DmrppTypeFactory::NewArray(const string &n, BaseType *v) const
252 {
253  return new DmrppArray(n, v, d_dmz);
254 }
255 
256 Structure *
257 DmrppTypeFactory::NewStructure(const string &n) const
258 {
259  return new DmrppStructure(n, d_dmz);
260 }
261 
262 D4Sequence *
263 DmrppTypeFactory::NewD4Sequence(const string &n) const
264 {
265  return new DmrppD4Sequence(n, d_dmz);
266 }
267 
268 D4Group *
269 DmrppTypeFactory::NewGroup(const string &n) const
270 {
271  return new DmrppD4Group(n, d_dmz);
272 }
273 
274 } // namespace dmrpp
Abstract exception class for the BES with basic string message.
Definition: BESError.h:58
Type
Type of JSON value.
Definition: rapidjson.h:664