libdap Updated for version 3.18.1
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
63namespace libdap {
64
65BaseType *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
124Byte *
125D4BaseTypeFactory::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.
132Byte *
133D4BaseTypeFactory::NewChar(const string &n) const
134{
135 Byte *b = new Byte(n);
136 b->set_type(dods_char_c);
137 return b;
138}
139
140Byte *
141D4BaseTypeFactory::NewUInt8(const string &n) const
142{
143 Byte *b = new Byte(n);
144 b->set_type(dods_uint8_c);
145 return b;
146}
147
148Int8 *
149D4BaseTypeFactory::NewInt8(const string &n) const
150{
151 return new Int8(n);
152}
153
154Int16 *
155D4BaseTypeFactory::NewInt16(const string &n) const
156{
157 return new Int16(n);
158}
159
160UInt16 *
161D4BaseTypeFactory::NewUInt16(const string &n) const
162{
163 return new UInt16(n);
164}
165
166Int32 *
167D4BaseTypeFactory::NewInt32(const string &n) const
168{
169 DBG(cerr << "Inside DAP4BaseTypeFactory::NewInt32" << endl);
170 return new Int32(n);
171}
172
173UInt32 *
174D4BaseTypeFactory::NewUInt32(const string &n) const
175{
176 return new UInt32(n);
177}
178
179Int64 *
180D4BaseTypeFactory::NewInt64(const string &n) const
181{
182 DBG(cerr << "Inside DAP4BaseTypeFactory::NewInt64" << endl);
183 return new Int64(n);
184}
185
186UInt64 *
187D4BaseTypeFactory::NewUInt64(const string &n) const
188{
189 return new UInt64(n);
190}
191
192Float32 *
193D4BaseTypeFactory::NewFloat32(const string &n) const
194{
195 return new Float32(n);
196}
197
198Float64 *
199D4BaseTypeFactory::NewFloat64(const string &n) const
200{
201 return new Float64(n);
202}
203
211D4Enum *
212D4BaseTypeFactory::NewEnum(const string &name, Type type) const
213{
214 return new D4Enum(name, type);
215}
216
217
218Str *
219D4BaseTypeFactory::NewStr(const string &n) const
220{
221 return new Str(n);
222}
223
224Url *
225D4BaseTypeFactory::NewUrl(const string &n) const
226{
227 return new Url(n);
228}
229
230D4Opaque *
231D4BaseTypeFactory::NewOpaque(const string &n) const
232{
233 return new D4Opaque(n);
234}
235
238Url *
239D4BaseTypeFactory::NewURL(const string &n) const
240{
241 return new Url(n);
242}
243
244Array *
245D4BaseTypeFactory::NewArray(const string &n, BaseType *v) const
246{
247 return new Array(n, v, true /* is_dap4 */);
248}
249
250Structure *
251D4BaseTypeFactory::NewStructure(const string &n) const
252{
253 return new Structure(n);
254}
255
256D4Sequence *
257D4BaseTypeFactory::NewD4Sequence(const string &n) const
258{
259 return new D4Sequence(n);
260}
261
262D4Group *
263D4BaseTypeFactory::NewGroup(const string &n) const
264{
265 return new D4Group(n);
266}
267
268} // namespace libdap
A multidimensional array of identical data types.
Definition: Array.h:113
The basic data type for the DODS DAP types.
Definition: BaseType.h:118
Holds a single byte.
Definition: Byte.h:61
virtual D4Enum * NewEnum(const string &n="", Type type=dods_null_c) const
virtual BaseType * NewVariable(Type t, const string &name) const
virtual Url * NewURL(const string &n="") const
Holds a DAP4 enumeration.
Definition: D4Enum.h:62
A class for software fault reporting.
Definition: InternalErr.h:65
Holds character string data.
Definition: Str.h:63
Holds an Internet address (URL).
Definition: Url.h:64
Type
Identifies the data type.
Definition: Type.h:94