libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
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 "Int16.h"
35#include "Int32.h"
36#include "Int8.h"
37#include "UInt16.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 "D4Sequence.h"
56#include "Structure.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 switch (t) {
67 case dods_byte_c:
68 return NewByte(name);
69 case dods_char_c:
70 return NewChar(name);
71 case dods_uint8_c:
72 return NewUInt8(name);
73 case dods_int8_c:
74 return NewInt8(name);
75
76 case dods_int16_c:
77 return NewInt16(name);
78 case dods_uint16_c:
79 return NewUInt16(name);
80 case dods_int32_c:
81 return NewInt32(name);
82 case dods_uint32_c:
83 return NewUInt32(name);
84
85 case dods_int64_c:
86 return NewInt64(name);
87 case dods_uint64_c:
88 return NewUInt64(name);
89
90 case dods_float32_c:
91 return NewFloat32(name);
92 case dods_float64_c:
93 return NewFloat64(name);
94
95 case dods_enum_c:
96 return NewEnum(name);
97
98 case dods_str_c:
99 return NewStr(name);
100 case dods_url_c:
101 return NewURL(name);
102
103 case dods_opaque_c:
104 return NewOpaque(name);
105
106 case dods_structure_c:
107 return NewStructure(name);
108
109 case dods_sequence_c:
110 return NewD4Sequence(name);
111
112 case dods_array_c:
113 return NewArray(name);
114
115 case dods_group_c:
116 return NewGroup(name);
117
118 default:
119 throw InternalErr(__FILE__, __LINE__, "Unimplemented type in DAP4");
120 }
121}
122
123Byte *D4BaseTypeFactory::NewByte(const string &n) const {
124 Byte *b = new Byte(n);
125 b->set_is_dap4(true);
126 return b;
127}
128
129// Use the type constants specific to Char and UInt8 so the print reps will
130// match the server's idea of the types.
131Byte *D4BaseTypeFactory::NewChar(const string &n) const {
132 Byte *b = new Byte(n);
134 b->set_is_dap4(true);
135 return b;
136}
137
138Byte *D4BaseTypeFactory::NewUInt8(const string &n) const {
139 Byte *b = new Byte(n);
141 b->set_is_dap4(true);
142 return b;
143}
144
145Int8 *D4BaseTypeFactory::NewInt8(const string &n) const {
146 Int8 *b = new Int8(n);
147 b->set_is_dap4(true);
148 return b;
149}
150
151Int16 *D4BaseTypeFactory::NewInt16(const string &n) const {
152 Int16 *b = new Int16(n);
153 b->set_is_dap4(true);
154 return b;
155}
156
157UInt16 *D4BaseTypeFactory::NewUInt16(const string &n) const {
158 UInt16 *b = new UInt16(n);
159 b->set_is_dap4(true);
160 return b;
161}
162
163Int32 *D4BaseTypeFactory::NewInt32(const string &n) const {
164 DBG(cerr << "Inside DAP4BaseTypeFactory::NewInt32" << endl);
165 Int32 *b = new Int32(n);
166 b->set_is_dap4(true);
167 return b;
168}
169
170UInt32 *D4BaseTypeFactory::NewUInt32(const string &n) const {
171 UInt32 *b = new UInt32(n);
172 b->set_is_dap4(true);
173 return b;
174}
175
176Int64 *D4BaseTypeFactory::NewInt64(const string &n) const {
177 DBG(cerr << "Inside DAP4BaseTypeFactory::NewInt64" << endl);
178 Int64 *b = new Int64(n);
179 b->set_is_dap4(true);
180 return b;
181}
182
183UInt64 *D4BaseTypeFactory::NewUInt64(const string &n) const {
184 UInt64 *b = new UInt64(n);
185 b->set_is_dap4(true);
186 return b;
187}
188
189Float32 *D4BaseTypeFactory::NewFloat32(const string &n) const {
190 Float32 *b = new Float32(n);
191 b->set_is_dap4(true);
192 return b;
193}
194
195Float64 *D4BaseTypeFactory::NewFloat64(const string &n) const {
196 Float64 *b = new Float64(n);
197 b->set_is_dap4(true);
198 return b;
199}
200
208D4Enum *D4BaseTypeFactory::NewEnum(const string &name, Type type) const { return new D4Enum(name, type); }
209
210Str *D4BaseTypeFactory::NewStr(const string &n) const {
211 Str *b = new Str(n);
212 b->set_is_dap4(true);
213 return b;
214}
215
216Url *D4BaseTypeFactory::NewUrl(const string &n) const {
217 Url *b = new Url(n);
218 b->set_is_dap4(true);
219 return b;
220}
221
222D4Opaque *D4BaseTypeFactory::NewOpaque(const string &n) const { return new D4Opaque(n); }
223
226Url *D4BaseTypeFactory::NewURL(const string &n) const {
227 Url *b = new Url(n);
228 b->set_is_dap4(true);
229 return b;
230}
231
232Array *D4BaseTypeFactory::NewArray(const string &n, BaseType *v) const { return new Array(n, v, true /* is_dap4 */); }
233
235 Structure *b = new Structure(n);
236 b->set_is_dap4(true);
237 return b;
238}
239
240D4Sequence *D4BaseTypeFactory::NewD4Sequence(const string &n) const { return new D4Sequence(n); }
241
242D4Group *D4BaseTypeFactory::NewGroup(const string &n) const { return new D4Group(n); }
243
244} // namespace libdap
A multidimensional array of identical data types.
Definition Array.h:121
The basic data type for the DODS DAP types.
Definition BaseType.h:118
virtual void set_is_dap4(const bool v)
Definition BaseType.h:182
virtual void set_type(const Type &t)
Sets the type of the class instance.
Definition BaseType.cc:332
Holds a single byte.
Definition Byte.h:59
virtual Int16 * NewInt16(const string &n="") const
virtual UInt32 * NewUInt32(const string &n="") const
virtual UInt64 * NewUInt64(const string &n="") const
virtual Byte * NewByte(const string &n="") const
virtual Float32 * NewFloat32(const string &n="") const
virtual Str * NewStr(const string &n="") const
virtual D4Sequence * NewD4Sequence(const string &n="") const
virtual D4Opaque * NewOpaque(const string &n="") const
virtual Structure * NewStructure(const string &n="") const
virtual Byte * NewUInt8(const string &n="") const
virtual D4Enum * NewEnum(const string &n="", Type type=dods_null_c) const
virtual UInt16 * NewUInt16(const string &n="") const
virtual Int64 * NewInt64(const string &n="") const
virtual D4Group * NewGroup(const string &n="") const
virtual BaseType * NewVariable(Type t, const string &name) const
virtual Array * NewArray(const string &n="", BaseType *v=0) const
virtual Int32 * NewInt32(const string &n="") const
virtual Float64 * NewFloat64(const string &n="") const
virtual Int8 * NewInt8(const string &n="") const
virtual Byte * NewChar(const string &n="") const
virtual Url * NewUrl(const string &n="") const
virtual Url * NewURL(const string &n="") const
Holds a DAP4 enumeration.
Definition D4Enum.h:53
Holds a sequence.
Definition D4Sequence.h:131
Holds a 32-bit floating point value.
Definition Float32.h:59
Holds a 64-bit (double precision) floating point value.
Definition Float64.h:58
Holds a 16-bit signed integer value.
Definition Int16.h:57
Holds a 32-bit signed integer.
Definition Int32.h:63
Holds a64-bit signed integer.
Definition Int64.h:48
Holds an 8-bit signed integer value.
Definition Int8.h:41
A class for software fault reporting.
Definition InternalErr.h:61
Holds character string data.
Definition Str.h:61
Holds a structure (aggregate) type.
Definition Structure.h:82
Holds an unsigned 16-bit integer.
Definition UInt16.h:55
Holds a 32-bit unsigned integer.
Definition UInt32.h:57
Holds a 64-bit unsigned integer.
Definition UInt64.h:47
Holds an Internet address (URL).
Definition Url.h:55
#define DBG(x)
Definition debug.h:58
top level DAP object to house generic methods
Definition AISConnect.cc:30
Type
Identifies the data type.
Definition Type.h:94
@ dods_group_c
Definition Type.h:122
@ dods_sequence_c
Definition Type.h:108
@ dods_uint32_c
Definition Type.h:100
@ dods_int16_c
Definition Type.h:97
@ dods_byte_c
Definition Type.h:96
@ dods_int32_c
Definition Type.h:99
@ dods_url_c
Definition Type.h:104
@ dods_int8_c
Definition Type.h:115
@ dods_float32_c
Definition Type.h:101
@ dods_char_c
Definition Type.h:114
@ dods_int64_c
Definition Type.h:118
@ dods_uint64_c
Definition Type.h:119
@ dods_uint16_c
Definition Type.h:98
@ dods_float64_c
Definition Type.h:102
@ dods_enum_c
Definition Type.h:120
@ dods_uint8_c
Definition Type.h:116
@ dods_str_c
Definition Type.h:103
@ dods_structure_c
Definition Type.h:106
@ dods_array_c
Definition Type.h:107
@ dods_opaque_c
Definition Type.h:121