bes  Updated for version 3.20.8
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  return new DmrppByte(n);
133 }
134 
135 Byte *
136 DmrppTypeFactory::NewChar(const string &n) const
137 {
138  Byte *b = new DmrppByte(n);
139  b->set_type(dods_char_c);
140  return b;
141 }
142 
143 Byte *
144 DmrppTypeFactory::NewUInt8(const string &n) const
145 {
146  Byte *b = new DmrppByte(n);
147  b->set_type(dods_uint8_c);
148  return b;
149 }
150 
151 Int8 *
152 DmrppTypeFactory::NewInt8(const string &n) const
153 {
154  return new DmrppInt8(n);
155 }
156 
157 Int16 *
158 DmrppTypeFactory::NewInt16(const string &n) const
159 {
160  return new DmrppInt16(n);
161 }
162 
163 UInt16 *
164 DmrppTypeFactory::NewUInt16(const string &n) const
165 {
166  return new DmrppUInt16(n);
167 }
168 
169 Int32 *
170 DmrppTypeFactory::NewInt32(const string &n) const
171 {
172  BESDEBUG(MODULE, prolog << "Making a new DmrppInt32 object named: " << n << endl);
173  return new DmrppInt32(n);
174 }
175 
176 UInt32 *
177 DmrppTypeFactory::NewUInt32(const string &n) const
178 {
179  return new DmrppUInt32(n);
180 }
181 
182 Int64 *
183 DmrppTypeFactory::NewInt64(const string &n) const
184 {
185  BESDEBUG(MODULE, prolog << "Making a new DmrppInt64 object named: " << n << endl);
186  return new DmrppInt64(n);
187 }
188 
189 UInt64 *
190 DmrppTypeFactory::NewUInt64(const string &n) const
191 {
192  return new DmrppUInt64(n);
193 }
194 
195 Float32 *
196 DmrppTypeFactory::NewFloat32(const string &n) const
197 {
198  return new DmrppFloat32(n);
199 }
200 
201 Float64 *
202 DmrppTypeFactory::NewFloat64(const string &n) const
203 {
204  return new DmrppFloat64(n);
205 }
206 
207 Str *
208 DmrppTypeFactory::NewStr(const string &n) const
209 {
210  return new DmrppStr(n);
211 }
212 
213 Url *
214 DmrppTypeFactory::NewUrl(const string &n) const
215 {
216  return new DmrppUrl(n);
217 }
218 
221 Url *
222 DmrppTypeFactory::NewURL(const string &n) const
223 {
224  return NewUrl(n);
225 }
226 
227 D4Opaque *
228 DmrppTypeFactory::NewOpaque(const string &n) const
229 {
230  return new DmrppD4Opaque(n);
231 }
232 
233 D4Enum *
234 DmrppTypeFactory::NewEnum(const string &name, Type type) const
235 {
236  return new DmrppD4Enum(name, type);
237 }
238 
239 Array *
240 DmrppTypeFactory::NewArray(const string &n, BaseType *v) const
241 {
242  return new DmrppArray(n, v);
243 }
244 
245 Structure *
246 DmrppTypeFactory::NewStructure(const string &n) const
247 {
248  return new DmrppStructure(n);
249 }
250 
251 D4Sequence *
252 DmrppTypeFactory::NewD4Sequence(const string &n) const
253 {
254  return new DmrppD4Sequence(n);
255 }
256 
257 D4Group *
258 DmrppTypeFactory::NewGroup(const string &n) const
259 {
260  return new DmrppD4Group(n);
261 }
262 
263 } // 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