libdap  Updated for version 3.20.6
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4BaseTypeFactory.cc
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
5 // Access Protocol.
6 
7 // Copyright (c) 2005 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 #include "config.h"
27 
28 #include <string>
29 
30 #include "BaseType.h"
31 #include "Type.h"
32 
33 #include "Byte.h"
34 #include "Int8.h"
35 #include "Int16.h"
36 #include "UInt16.h"
37 #include "Int32.h"
38 #include "UInt32.h"
39 
40 #include "Int64.h"
41 #include "UInt64.h"
42 
43 #include "Float32.h"
44 #include "Float64.h"
45 
46 #include "D4Enum.h"
47 
48 #include "Str.h"
49 #include "Url.h"
50 
51 #include "D4Opaque.h"
52 
53 #include "Array.h"
54 
55 #include "Structure.h"
56 #include "D4Sequence.h"
57 
58 #include "D4Group.h"
59 
60 #include "D4BaseTypeFactory.h"
61 #include "debug.h"
62 
63 namespace libdap {
64 
65 BaseType *D4BaseTypeFactory::NewVariable(Type t, const string &name) const
66 {
67  switch (t) {
68  case dods_byte_c:
69  return NewByte(name);
70  case dods_char_c:
71  return NewChar(name);
72  case dods_uint8_c:
73  return NewUInt8(name);
74  case dods_int8_c:
75  return NewInt8(name);
76 
77  case dods_int16_c:
78  return NewInt16(name);
79  case dods_uint16_c:
80  return NewUInt16(name);
81  case dods_int32_c:
82  return NewInt32(name);
83  case dods_uint32_c:
84  return NewUInt32(name);
85 
86  case dods_int64_c:
87  return NewInt64(name);
88  case dods_uint64_c:
89  return NewUInt64(name);
90 
91  case dods_float32_c:
92  return NewFloat32(name);
93  case dods_float64_c:
94  return NewFloat64(name);
95 
96  case dods_enum_c:
97  return NewEnum(name);
98 
99  case dods_str_c:
100  return NewStr(name);
101  case dods_url_c:
102  return NewURL(name);
103 
104  case dods_opaque_c:
105  return NewOpaque(name);
106 
107  case dods_structure_c:
108  return NewStructure(name);
109 
110  case dods_sequence_c:
111  return NewD4Sequence(name);
112 
113  case dods_array_c:
114  return NewArray(name);
115 
116  case dods_group_c:
117  return NewGroup(name);
118 
119  default:
120  throw InternalErr(__FILE__, __LINE__, "Unimplemented type in DAP4");
121  }
122 }
123 
124 Byte *
125 D4BaseTypeFactory::NewByte(const string &n) const
126 {
127  Byte *b = new Byte(n);
128  b->set_is_dap4(true);
129  return b;
130 }
131 
132 // Use the type constants specific to Char and UInt8 so the print reps will
133 // match the server's idea of the types.
134 Byte *
135 D4BaseTypeFactory::NewChar(const string &n) const
136 {
137  Byte *b = new Byte(n);
138  b->set_type(dods_char_c);
139  b->set_is_dap4(true);
140  return b;
141 }
142 
143 Byte *
144 D4BaseTypeFactory::NewUInt8(const string &n) const
145 {
146  Byte *b = new Byte(n);
147  b->set_type(dods_uint8_c);
148  b->set_is_dap4(true);
149  return b;
150 }
151 
152 Int8 *
153 D4BaseTypeFactory::NewInt8(const string &n) const
154 {
155  Int8 *b = new Int8(n);
156  b->set_is_dap4(true);
157  return b;
158 }
159 
160 Int16 *
161 D4BaseTypeFactory::NewInt16(const string &n) const
162 {
163  Int16 *b = new Int16(n);
164  b->set_is_dap4(true);
165  return b;
166 }
167 
168 UInt16 *
169 D4BaseTypeFactory::NewUInt16(const string &n) const
170 {
171  UInt16 *b = new UInt16(n);
172  b->set_is_dap4(true);
173  return b;
174 }
175 
176 Int32 *
177 D4BaseTypeFactory::NewInt32(const string &n) const
178 {
179  DBG(cerr << "Inside DAP4BaseTypeFactory::NewInt32" << endl);
180  Int32 *b = new Int32(n);
181  b->set_is_dap4(true);
182  return b;
183 }
184 
185 UInt32 *
186 D4BaseTypeFactory::NewUInt32(const string &n) const
187 {
188  UInt32 *b = new UInt32(n);
189  b->set_is_dap4(true);
190  return b;
191 }
192 
193 Int64 *
194 D4BaseTypeFactory::NewInt64(const string &n) const
195 {
196  DBG(cerr << "Inside DAP4BaseTypeFactory::NewInt64" << endl);
197  Int64 *b = new Int64(n);
198  b->set_is_dap4(true);
199  return b;
200 }
201 
202 UInt64 *
203 D4BaseTypeFactory::NewUInt64(const string &n) const
204 {
205  UInt64 *b = new UInt64(n);
206  b->set_is_dap4(true);
207  return b;
208 }
209 
210 Float32 *
211 D4BaseTypeFactory::NewFloat32(const string &n) const
212 {
213  Float32 *b = new Float32(n);
214  b->set_is_dap4(true);
215  return b;
216 }
217 
218 Float64 *
219 D4BaseTypeFactory::NewFloat64(const string &n) const
220 {
221  Float64 *b = new Float64(n);
222  b->set_is_dap4(true);
223  return b;
224 }
225 
233 D4Enum *
234 D4BaseTypeFactory::NewEnum(const string &name, Type type) const
235 {
236  return new D4Enum(name, type);
237 }
238 
239 
240 Str *
241 D4BaseTypeFactory::NewStr(const string &n) const
242 {
243  Str *b = new Str(n);
244  b->set_is_dap4(true);
245  return b;
246 }
247 
248 Url *
249 D4BaseTypeFactory::NewUrl(const string &n) const
250 {
251  Url *b = new Url(n);
252  b->set_is_dap4(true);
253  return b;
254 }
255 
256 D4Opaque *
257 D4BaseTypeFactory::NewOpaque(const string &n) const
258 {
259  return new D4Opaque(n);
260 }
261 
264 Url *
265 D4BaseTypeFactory::NewURL(const string &n) const
266 {
267  Url *b = new Url(n);
268  b->set_is_dap4(true);
269  return b;
270 }
271 
272 Array *
273 D4BaseTypeFactory::NewArray(const string &n, BaseType *v) const
274 {
275  return new Array(n, v, true /* is_dap4 */);
276 }
277 
278 Structure *
279 D4BaseTypeFactory::NewStructure(const string &n) const
280 {
281  Structure *b = new Structure(n);
282  b->set_is_dap4(true);
283  return b;
284 }
285 
286 D4Sequence *
287 D4BaseTypeFactory::NewD4Sequence(const string &n) const
288 {
289  return new D4Sequence(n);
290 }
291 
292 D4Group *
293 D4BaseTypeFactory::NewGroup(const string &n) const
294 {
295  return new D4Group(n);
296 }
297 
298 } // namespace libdap
virtual BaseType * NewVariable(Type t, const string &name) const
Holds an 8-bit signed integer value.
Definition: Int8.h:42
Holds a64-bit signed integer.
Definition: Int64.h:49
Holds an Internet address (URL).
Definition: Url.h:68
Holds an unsigned 16-bit integer.
Definition: UInt16.h:57
virtual D4Enum * NewEnum(const string &n="", Type type=dods_null_c) const
Holds a structure (aggregate) type.
Definition: Structure.h:83
Type
Identifies the data type.
Definition: Type.h:94
Holds a 32-bit floating point value.
Definition: Float32.h:61
top level DAP object to house generic methods
Definition: AISConnect.cc:30
A class for software fault reporting.
Definition: InternalErr.h:64
Holds character string data.
Definition: Str.h:62
Holds a DAP4 enumeration.
Definition: D4Enum.h:61
Holds a 16-bit signed integer value.
Definition: Int16.h:59
Holds a sequence.
Definition: D4Sequence.h:133
virtual void set_type(const Type &t)
Sets the type of the class instance.
Definition: BaseType.cc:372
Holds a 64-bit unsigned integer.
Definition: UInt64.h:49
virtual Url * NewURL(const string &n="") const
The basic data type for the DODS DAP types.
Definition: BaseType.h:117
Holds a 64-bit (double precision) floating point value.
Definition: Float64.h:60
Holds a single byte.
Definition: Byte.h:60
Holds a 32-bit unsigned integer.
Definition: UInt32.h:59
A multidimensional array of identical data types.
Definition: Array.h:112
Holds a 32-bit signed integer.
Definition: Int32.h:65