libdap Updated for version 3.18.1
Array.h
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) 2002,2003 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// (c) COPYRIGHT URI/MIT 1994-1999
27// Please read the full copyright statement in the file COPYRIGHT_URI.
28//
29// Authors:
30// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
31
32// Class for array variables. The dimensions of the array are stored in the
33// list SHAPE.
34//
35// jhrg 9/6/94
36
37#ifndef _array_h
38#define _array_h 1
39
40#include <string>
41#include <vector>
42
43#ifndef _dods_limits_h
44#include "dods-limits.h"
45#endif
46
47#ifndef _vector_h
48#include "Vector.h"
49#endif
50
51//#include "D4Dimensions.h"
52
53namespace libdap
54{
55class D4Group;
56class D4Maps;
57class XMLWriter;
58class D4Dimension;
59class D4Dimensions;
60
61const int DODS_MAX_ARRAY = DODS_INT_MAX;
62
112class Array: public Vector
113{
114public:
126 {
127 // In DAP2, the name and size of a dimension is stored here, along
128 // with information about any constraint. In DAP4, either the name
129 // and size are stored in the two fields below _or_ the name and
130 // size information comes from a dimension object defined in a
131 // group that is referenced by the 'dim' pointer. Do not free this
132 // pointer; it is shared between the array and the Group where the
133 // Dimension is defined. To keep Array manageable to implement, size
134 // will be set here using the value from 'dim' if it is not null.
135 int size;
136 string name;
137
139
140 // when a DMR is printed for a data response, if an array uses shared
141 // dimensions and those sdims have been sliced, make sure to use those
142 // and get the syntax correct. That's what this field does - in every
143 // case the array records the sizes of its dimensions and their slices
144 // regardless of whether they were provided explicitly in a CE or inherited
145 // from a sliced sdim.
147
148 int start;
149 int stop;
150 int stride;
151 int c_size;
152
153 dimension() : size(0), name(""), dim(0), use_sdim_for_slice(false) {
154 // this information changes with each constraint expression
155 start = 0;
156 stop = 0;
157 stride = 1;
158 c_size = size;
159 }
160
161 dimension(unsigned long s, string n) : size(s), name(n), dim(0), use_sdim_for_slice(false) {
162 start = 0;
163 stop = size - 1;
164 stride = 1;
165 c_size = size;
166 }
167
168 dimension(D4Dimension *d);
169 };
170
171 D4Maps *d_maps;
172
173private:
174 std::vector<dimension> _shape; // list of dimensions (i.e., the shape)
175
176 void update_dimension_pointers(D4Dimensions *old_dims, D4Dimensions *new_dims);
177
178 friend class ArrayTest;
179 friend class D4Group;
180
181protected:
182 void _duplicate(const Array &a);
183
184 unsigned int print_array(FILE *out, unsigned int index,
185 unsigned int dims, unsigned int shape[]);
186
187 unsigned int print_array(ostream &out, unsigned int index,
188 unsigned int dims, unsigned int shape[]);
189
190public:
196 typedef std::vector<dimension>::const_iterator Dim_citer;
197
204 typedef std::vector<dimension>::iterator Dim_iter;
205
206 Array(const string &n, BaseType *v, bool is_dap4 = false);
207 Array(const string &n, const string &d, BaseType *v, bool is_dap4 = false);
208 Array(const Array &rhs);
209 virtual ~Array();
210
211 Array &operator=(const Array &rhs);
212 virtual BaseType *ptr_duplicate();
213
214 virtual BaseType *transform_to_dap4(D4Group *root, Constructor *container);
215
216 void add_var(BaseType *v, Part p = nil);
217 void add_var_nocopy(BaseType *v, Part p = nil);
218
219 void append_dim(int size, const string &name = "");
220 void append_dim(D4Dimension *dim);
221 void prepend_dim(int size, const string& name = "");
222 void prepend_dim(D4Dimension *dim);
223 void clear_all_dims();
224
225 virtual void add_constraint(Dim_iter i, int start, int stride, int stop);
226 virtual void add_constraint(Dim_iter i, D4Dimension *dim);
227 virtual void reset_constraint();
228
229 virtual void clear_constraint(); // deprecated
230
231 virtual void update_length(int size = 0); // should be used internally only
232
234 Dim_iter dim_end() ;
235
236 virtual int dimension_size(Dim_iter i, bool constrained = false);
237 virtual int dimension_start(Dim_iter i, bool constrained = false);
238 virtual int dimension_stop(Dim_iter i, bool constrained = false);
239 virtual int dimension_stride(Dim_iter i, bool constrained = false);
240 virtual string dimension_name(Dim_iter i);
241 virtual D4Dimension *dimension_D4dim(Dim_iter i);
242
243 virtual unsigned int dimensions(bool constrained = false);
244
245 virtual D4Maps *maps();
246
247 virtual void print_dap4(XMLWriter &xml, bool constrained = false);
248
249 // These are all DAP2 output methods
250
251 virtual void print_decl(ostream &out, string space = " ",
252 bool print_semi = true,
253 bool constraint_info = false,
254 bool constrained = false);
255
256 virtual void print_xml(ostream &out, string space = " ",
257 bool constrained = false);
258
259 virtual void print_xml_writer(XMLWriter &xml, bool constrained = false);
260 virtual void print_xml_writer_core(XMLWriter &out, bool constrained, string tag);
261 virtual void print_as_map_xml_writer(XMLWriter &xml, bool constrained);
262
263 virtual void print_xml_core(FILE *out, string space, bool constrained, string tag);
264 virtual void print_xml_core(ostream &out, string space, bool constrained, string tag);
265
266 // not used (?)
267 virtual void print_as_map_xml(ostream &out, string space = " ",
268 bool constrained = false);
269
270 virtual void print_val(ostream &out, string space = "",
271 bool print_decl_p = true);
272
273 virtual void print_xml(FILE *out, string space = " ",
274 bool constrained = false);
275 virtual void print_as_map_xml(FILE *out, string space = " ",
276 bool constrained = false);
277 virtual void print_val(FILE *out, string space = "",
278 bool print_decl_p = true);
279 virtual void print_decl(FILE *out, string space = " ",
280 bool print_semi = true,
281 bool constraint_info = false,
282 bool constrained = false);
283
284 virtual bool check_semantics(string &msg, bool all = false);
285
286 virtual void dump(ostream &strm) const ;
287};
288
289} // namespace libdap
290
291#endif // _array_h
A multidimensional array of identical data types.
Definition: Array.h:113
virtual int dimension_start(Dim_iter i, bool constrained=false)
Return the start index of a dimension.
Definition: Array.cc:589
virtual void clear_constraint()
Clears the projection; add each projected dimension explicitly using add_constraint.
Definition: Array.cc:429
virtual void dump(ostream &strm) const
dumps information about this object
Definition: Array.cc:1162
Dim_iter dim_end()
Definition: Array.cc:517
virtual BaseType * ptr_duplicate()
Definition: Array.cc:174
virtual void print_xml(ostream &out, string space=" ", bool constrained=false)
Definition: Array.cc:902
unsigned int print_array(FILE *out, unsigned int index, unsigned int dims, unsigned int shape[])
Print the value given the current constraint.
Definition: Array.cc:1030
virtual int dimension_stop(Dim_iter i, bool constrained=false)
Return the stop index of the constraint.
Definition: Array.cc:613
virtual void update_length(int size=0)
Definition: Array.cc:103
virtual void add_constraint(Dim_iter i, int start, int stride, int stop)
Adds a constraint to an Array dimension.
Definition: Array.cc:461
virtual string dimension_name(Dim_iter i)
Returns the name of the specified dimension.
Definition: Array.cc:654
virtual void print_decl(ostream &out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false)
Prints a DDS entry for the Array.
Definition: Array.cc:862
virtual BaseType * transform_to_dap4(D4Group *root, Constructor *container)
DAP2 to DAP4 transform.
Definition: Array.cc:193
void append_dim(int size, const string &name="")
Add a dimension of a given size.
Definition: Array.cc:347
std::vector< dimension >::iterator Dim_iter
Definition: Array.h:204
virtual int dimension_size(Dim_iter i, bool constrained=false)
Returns the size of the dimension.
Definition: Array.cc:556
void clear_all_dims()
Definition: Array.cc:393
virtual void print_dap4(XMLWriter &xml, bool constrained=false)
Print the DAP4 representation of an array.
Definition: Array.cc:779
virtual bool check_semantics(string &msg, bool all=false)
Check semantic features of the Array.
Definition: Array.cc:1143
std::vector< dimension >::const_iterator Dim_citer
Definition: Array.h:196
virtual void print_as_map_xml(ostream &out, string space=" ", bool constrained=false)
Definition: Array.cc:924
virtual void reset_constraint()
Reset constraint to select entire array.
Definition: Array.cc:404
void add_var(BaseType *v, Part p=nil)
Add the BaseType pointer to this constructor type instance.
Definition: Array.cc:293
virtual ~Array()
The Array destructor.
Definition: Array.cc:168
virtual void print_xml_core(FILE *out, string space, bool constrained, string tag)
Definition: Array.cc:935
void prepend_dim(int size, const string &name="")
Definition: Array.cc:370
Dim_iter dim_begin()
Definition: Array.cc:510
Array(const string &n, BaseType *v, bool is_dap4=false)
Array constructor.
Definition: Array.cc:136
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
Definition: Array.cc:954
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition: Array.cc:1106
virtual unsigned int dimensions(bool constrained=false)
Return the total number of dimensions in the array.
Definition: Array.cc:533
virtual int dimension_stride(Dim_iter i, bool constrained=false)
Returns the stride value of the constraint.
Definition: Array.cc:638
The basic data type for the DODS DAP types.
Definition: BaseType.h:118
virtual string name() const
Returns the name of the class instance.
Definition: BaseType.cc:265
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:81
Part
Names the parts of multi-section constructor data types.
Definition: Type.h:48
int stride
The constraint stride.
Definition: Array.h:150
string name
The name of this dimension.
Definition: Array.h:136
D4Dimension * dim
If not null, a weak pointer to the D4Dimension.
Definition: Array.h:138
bool use_sdim_for_slice
Used to control printing the DMR in data responses.
Definition: Array.h:146
int start
The constraint start index.
Definition: Array.h:148
int size
The unconstrained dimension size.
Definition: Array.h:135
int stop
The constraint end index.
Definition: Array.h:149
int c_size
Size of dimension once constrained.
Definition: Array.h:151