libdap++  Updated for version 3.14.0
D4BaseTypeFactory.cc
Go to the documentation of this file.
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  return new Byte(n);
128 }
129 
130 // Use the type constants specific to Char and UInt8 so the print reps will
131 // match the server's idea of the types.
132 Byte *
133 D4BaseTypeFactory::NewChar(const string &n) const
134 {
135  Byte *b = new Byte(n);
136  b->set_type(dods_char_c);
137  return b;
138 }
139 
140 Byte *
141 D4BaseTypeFactory::NewUInt8(const string &n) const
142 {
143  Byte *b = new Byte(n);
145  return b;
146 }
147 
148 Int8 *
149 D4BaseTypeFactory::NewInt8(const string &n) const
150 {
151  return new Int8(n);
152 }
153 
154 Int16 *
155 D4BaseTypeFactory::NewInt16(const string &n) const
156 {
157  return new Int16(n);
158 }
159 
160 UInt16 *
161 D4BaseTypeFactory::NewUInt16(const string &n) const
162 {
163  return new UInt16(n);
164 }
165 
166 Int32 *
167 D4BaseTypeFactory::NewInt32(const string &n) const
168 {
169  DBG(cerr << "Inside DAP4BaseTypeFactory::NewInt32" << endl);
170  return new Int32(n);
171 }
172 
173 UInt32 *
174 D4BaseTypeFactory::NewUInt32(const string &n) const
175 {
176  return new UInt32(n);
177 }
178 
179 Int64 *
180 D4BaseTypeFactory::NewInt64(const string &n) const
181 {
182  DBG(cerr << "Inside DAP4BaseTypeFactory::NewInt64" << endl);
183  return new Int64(n);
184 }
185 
186 UInt64 *
187 D4BaseTypeFactory::NewUInt64(const string &n) const
188 {
189  return new UInt64(n);
190 }
191 
192 Float32 *
193 D4BaseTypeFactory::NewFloat32(const string &n) const
194 {
195  return new Float32(n);
196 }
197 
198 Float64 *
199 D4BaseTypeFactory::NewFloat64(const string &n) const
200 {
201  return new Float64(n);
202 }
203 
211 D4Enum *
212 D4BaseTypeFactory::NewEnum(const string &name, Type type) const
213 {
214  return new D4Enum(name, type);
215 }
216 
217 
218 Str *
219 D4BaseTypeFactory::NewStr(const string &n) const
220 {
221  return new Str(n);
222 }
223 
224 Url *
225 D4BaseTypeFactory::NewUrl(const string &n) const
226 {
227  return new Url(n);
228 }
229 
230 D4Opaque *
231 D4BaseTypeFactory::NewOpaque(const string &n) const
232 {
233  return new D4Opaque(n);
234 }
235 
238 Url *
239 D4BaseTypeFactory::NewURL(const string &n) const
240 {
241  return new Url(n);
242 }
243 
244 Array *
245 D4BaseTypeFactory::NewArray(const string &n, BaseType *v) const
246 {
247  return new Array(n, v, true /* is_dap4 */);
248 }
249 
250 Structure *
251 D4BaseTypeFactory::NewStructure(const string &n) const
252 {
253  return new Structure(n);
254 }
255 
256 D4Sequence *
257 D4BaseTypeFactory::NewD4Sequence(const string &n) const
258 {
259  return new D4Sequence(n);
260 }
261 
262 D4Group *
263 D4BaseTypeFactory::NewGroup(const string &n) const
264 {
265  return new D4Group(n);
266 }
267 
268 } // namespace libdap
virtual Float64 * NewFloat64(const string &n="") const
virtual UInt64 * NewUInt64(const string &n="") 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:63
virtual Int64 * NewInt64(const string &n="") const
virtual D4Group * NewGroup(const string &n="") const
virtual UInt16 * NewUInt16(const string &n="") const
virtual Int16 * NewInt16(const string &n="") const
virtual Byte * NewByte(const string &n="") const
virtual Byte * NewChar(const string &n="") const
Holds an unsigned 16-bit integer.
Definition: UInt16.h:57
virtual D4Opaque * NewOpaque(const string &n="") 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
A class for software fault reporting.
Definition: InternalErr.h:64
virtual Structure * NewStructure(const string &n="") const
virtual Float32 * NewFloat32(const string &n="") const
Holds character string data.
Definition: Str.h:62
#define DBG(x)
Definition: debug.h:58
Holds a DAP4 enumeration.
Definition: D4Enum.h:55
Holds a 16-bit signed integer value.
Definition: Int16.h:59
virtual Str * NewStr(const string &n="") const
Holds a sequence.
Definition: D4Sequence.h:124
virtual UInt32 * NewUInt32(const string &n="") const
void set_type(const Type &t)
Sets the type of the class instance.
Definition: BaseType.cc:313
virtual D4Enum * NewEnum(const string &n="", Type type=dods_null_c) const
Holds a 64-bit unsigned integer.
Definition: UInt64.h:49
virtual Int32 * NewInt32(const string &n="") const
virtual Array * NewArray(const string &n="", BaseType *v=0) const
virtual Url * NewUrl(const string &n="") const
virtual Int8 * NewInt8(const string &n="") const
virtual Url * NewURL(const string &n="") const
The basic data type for the DODS DAP types.
Definition: BaseType.h:117
virtual D4Sequence * NewD4Sequence(const string &n="") const
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
virtual Byte * NewUInt8(const string &n="") const
Holds a 32-bit signed integer.
Definition: Int32.h:65
virtual BaseType * NewVariable(Type t, const string &name) const