libdap Updated for version 3.21.0
libdap4 is an implementation of OPeNDAP's DAP protocol.
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
122class Array: public Vector
123{
124public:
136 {
137 // In DAP2, the name and size of a dimension is stored here, along
138 // with information about any constraint. In DAP4, either the name
139 // and size are stored in the two fields below _or_ the name and
140 // size information comes from a dimension object defined in a
141 // group that is referenced by the 'dim' pointer. Do not free this
142 // pointer; it is shared between the array and the Group where the
143 // Dimension is defined. To keep Array manageable to implement, size
144 // will be set here using the value from 'dim' if it is not null.
145 int64_t size;
146 string name;
147
149
150 // when a DMR is printed for a data response, if an array uses shared
151 // dimensions and those sdims have been sliced, make sure to use those
152 // and get the syntax correct. That's what this field does - in every
153 // case the array records the sizes of its dimensions and their slices
154 // regardless of whether they were provided explicitly in a CE or inherited
155 // from a sliced sdim.
157
158 int64_t start;
159 int64_t stop;
160 int64_t stride;
161 int64_t c_size;
162
163 dimension() : size(0), name(""), dim(0), use_sdim_for_slice(false) {
164 // this information changes with each constraint expression
165 start = 0;
166 stop = 0;
167 stride = 1;
168 c_size = size;
169 }
170
171 dimension(int64_t s, string n) : size(s), name(n), dim(0), use_sdim_for_slice(false) {
172 start = 0;
173 stop = size - 1;
174 stride = 1;
175 c_size = size;
176 }
177
178 explicit dimension(D4Dimension *d);
179 };
180
181 // The following two structs are for the direct IO optimization.
182 // The variable chunk and compression information need to be passed
183 // between two BES modules. The ideal approach is to use the
184 // dynamic_cast for a BES module to retrieve the information stored
185 // by another module. However, there are issues in the current BES
186 // that prevent us from implementing in this way.
187 // So we need to use libdap to do the job.
189 unsigned int filter_mask;
190 unsigned long long chunk_direct_io_offset;
191 unsigned long long chunk_buffer_size;
192 vector<unsigned long long> chunk_coords;
193 };
194
196 string filter;
197 vector<unsigned int>deflate_levels;
198 vector<size_t> chunk_dims;
199 vector<var_chunk_info_t> var_chunk_info;
200 };
201private:
202 D4Maps *d_maps = nullptr;
203
204 std::vector<dimension> _shape; // list of dimensions (i.e., the shape)
205
206 bool direct_io_flag = false;
207 var_storage_info vs_info;
208
209 void update_dimension_pointers(D4Dimensions *old_dims, D4Dimensions *new_dims);
210
211 friend class ArrayTest;
212 friend class D4Group;
213
214protected:
215 void _duplicate(const Array &a);
216
217 uint64_t print_array(FILE *out, uint64_t index,
218 unsigned int dims, uint64_t shape[]);
219
220 uint64_t print_array(ostream &out, uint64_t index,
221 unsigned int dims, uint64_t shape[]);
222
223 std::vector<dimension> &shape(){
224 return _shape;
225 }
226
227public:
233 typedef std::vector<dimension>::const_iterator Dim_citer;
234
241 typedef std::vector<dimension>::iterator Dim_iter;
242
243 Array(const string &n, BaseType *v, bool is_dap4 = false);
244 Array(const string &n, const string &d, BaseType *v, bool is_dap4 = false);
245 Array(const Array &rhs);
246 virtual ~Array();
247
248 Array &operator=(const Array &rhs);
249 BaseType *ptr_duplicate() override;
250
251 bool is_dap2_grid();
252 void transform_to_dap4(D4Group *root, Constructor *container) override;
253 std::vector<BaseType *> *transform_to_dap2(AttrTable *parent_attr_table) override;
254
255 void add_var(BaseType *v, Part p = nil) override;
256 void add_var_nocopy(BaseType *v, Part p = nil) override;
257
258 void append_dim(int size, const string &name = "");
259 void append_dim_ll(int64_t size, const string &name = "");
260 void append_dim(D4Dimension *dim);
261 void prepend_dim(int size, const string& name = "");
262 void prepend_dim(D4Dimension *dim);
263 void clear_all_dims();
264 void rename_dim(const string &oldName = "", const string &newName = "");
265
266 virtual void add_constraint(Dim_iter i, int start, int stride, int stop);
267 virtual void add_constraint_ll(Dim_iter i, int64_t start, int64_t stride, int64_t stop);
268 virtual void add_constraint(Dim_iter i, D4Dimension *dim);
269 virtual void reset_constraint();
270
271 virtual void clear_constraint(); // deprecated
272
273 virtual void update_length(int size = 0); // should be used internally only
274 virtual void update_length_ll(unsigned long long size = 0); // should be used internally only
275
277 Dim_iter dim_end() ;
278
279 virtual int dimension_size(Dim_iter i, bool constrained = false);
280 virtual int dimension_start(Dim_iter i, bool constrained = false);
281 virtual int dimension_stop(Dim_iter i, bool constrained = false);
282 virtual int dimension_stride(Dim_iter i, bool constrained = false);
283
284 virtual int64_t dimension_size_ll(Dim_iter i, bool constrained = false);
285 virtual int64_t dimension_start_ll(Dim_iter i, bool constrained = false);
286 virtual int64_t dimension_stop_ll(Dim_iter i, bool constrained = false);
287 virtual int64_t dimension_stride_ll(Dim_iter i, bool constrained = false);
288
289 virtual string dimension_name(Dim_iter i);
290 virtual D4Dimension *dimension_D4dim(Dim_iter i);
291
292 virtual unsigned int dimensions(bool constrained = false);
293
294 virtual D4Maps *maps();
295
296 void print_dap4(XMLWriter &xml, bool constrained = false) override;
297
298 // These are all DAP2 output methods
299
300 void print_decl(ostream &out, string space = " ",
301 bool print_semi = true,
302 bool constraint_info = false,
303 bool constrained = false) override;
304
305 void print_xml(ostream &out, string space = " ",
306 bool constrained = false) override;
307
308 void print_xml_writer(XMLWriter &xml, bool constrained = false) override;
309 virtual void print_xml_writer_core(XMLWriter &out, bool constrained, string tag);
310 virtual void print_as_map_xml_writer(XMLWriter &xml, bool constrained);
311
312 virtual void print_xml_core(FILE *out, string space, bool constrained, string tag);
313 virtual void print_xml_core(ostream &out, string space, bool constrained, string tag);
314
315 // not used (?)
316 virtual void print_as_map_xml(ostream &out, string space = " ",
317 bool constrained = false);
318
319 void print_val(ostream &out, string space = "",
320 bool print_decl_p = true) override;
321
322 void print_xml(FILE *out, string space = " ",
323 bool constrained = false) override;
324 virtual void print_as_map_xml(FILE *out, string space = " ",
325 bool constrained = false);
326 void print_val(FILE *out, string space = "",
327 bool print_decl_p = true) override;
328 void print_decl(FILE *out, string space = " ",
329 bool print_semi = true,
330 bool constraint_info = false,
331 bool constrained = false) override;
332
333 bool check_semantics(string &msg, bool all = false) override;
334
335
336 bool is_dap4_projected(std::vector<std::string> &projected_dap4_inventory) override;
337
338 void dump(ostream &strm) const override;
339
340 // The following methods are for direct IO optimization.
341 bool get_dio_flag() const {return direct_io_flag; }
342 void set_dio_flag( bool dio_flag_value = true) { direct_io_flag = dio_flag_value; }
343 var_storage_info & get_var_storage_info() {return vs_info;}
344 void set_var_storage_info(const var_storage_info &my_vs_info);
345
346};
347
348} // namespace libdap
349
350#endif // _array_h
A multidimensional array of identical data types.
Definition: Array.h:123
void print_dap4(XMLWriter &xml, bool constrained=false) override
Print the DAP4 representation of an array.
Definition: Array.cc:1082
virtual int dimension_start(Dim_iter i, bool constrained=false)
Return the start index of a dimension.
Definition: Array.cc:849
virtual void clear_constraint()
Clears the projection; add each projected dimension explicitly using add_constraint.
Definition: Array.cc:639
Dim_iter dim_end()
Definition: Array.cc:768
virtual int dimension_stop(Dim_iter i, bool constrained=false)
Return the stop index of the constraint.
Definition: Array.cc:876
void dump(ostream &strm) const override
dumps information about this object
Definition: Array.cc:1495
virtual void update_length(int size=0)
Definition: Array.cc:102
bool is_dap4_projected(std::vector< std::string > &projected_dap4_inventory) override
Definition: Array.cc:1467
virtual void add_constraint(Dim_iter i, int start, int stride, int stop)
Adds a constraint to an Array dimension.
Definition: Array.cc:670
virtual string dimension_name(Dim_iter i)
Returns the name of the specified dimension.
Definition: Array.cc:951
void print_decl(ostream &out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false) override
Prints a DDS entry for the Array.
Definition: Array.cc:1163
void print_xml(ostream &out, string space=" ", bool constrained=false) override
Definition: Array.cc:1201
void print_val(ostream &out, string space="", bool print_decl_p=true) override
Prints the value of the variable.
Definition: Array.cc:1395
BaseType * ptr_duplicate() override
Definition: Array.cc:181
void append_dim(int size, const string &name="")
Add a dimension of a given size.
Definition: Array.cc:533
std::vector< dimension >::iterator Dim_iter
Definition: Array.h:241
void rename_dim(const string &oldName="", const string &newName="")
Renames dimension.
Definition: Array.cc:597
std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table) override
Transforms this instance of a D4Array into the corresponding DAP2 object.
Definition: Array.cc:308
virtual int dimension_size(Dim_iter i, bool constrained=false)
Returns the size of the dimension.
Definition: Array.cc:805
void clear_all_dims()
Definition: Array.cc:587
std::vector< dimension >::const_iterator Dim_citer
Definition: Array.h:233
void add_var(BaseType *v, Part p=nil) override
Add the BaseType pointer to this constructor type instance.
Definition: Array.cc:481
uint64_t print_array(FILE *out, uint64_t index, unsigned int dims, uint64_t shape[])
Print the value given the current constraint.
Definition: Array.cc:1322
virtual void print_as_map_xml(ostream &out, string space=" ", bool constrained=false)
Definition: Array.cc:1221
void print_xml_writer(XMLWriter &xml, bool constrained=false) override
Definition: Array.cc:1248
virtual void reset_constraint()
Reset constraint to select entire array.
Definition: Array.cc:616
void set_var_storage_info(const var_storage_info &my_vs_info)
Set the variable storage information for direct IO optimization.
Definition: Array.cc:1526
virtual ~Array()
The Array destructor.
Definition: Array.cc:175
virtual void print_xml_core(FILE *out, string space, bool constrained, string tag)
Definition: Array.cc:1231
void prepend_dim(int size, const string &name="")
Definition: Array.cc:566
Dim_iter dim_begin()
Definition: Array.cc:762
void transform_to_dap4(D4Group *root, Constructor *container) override
DAP2 to DAP4 transform.
Definition: Array.cc:195
Array(const string &n, BaseType *v, bool is_dap4=false)
Array constructor.
Definition: Array.cc:139
bool check_semantics(string &msg, bool all=false) override
Check semantic features of the Array.
Definition: Array.cc:1432
virtual unsigned int dimensions(bool constrained=false)
Return the total number of dimensions in the array.
Definition: Array.cc:783
virtual int dimension_stride(Dim_iter i, bool constrained=false)
Returns the stride value of the constraint.
Definition: Array.cc:904
Contains the attributes for a dataset.
Definition: AttrTable.h:154
The basic data type for the DODS DAP types.
Definition: BaseType.h:120
virtual string name() const
Returns the name of the class instance.
Definition: BaseType.cc:317
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:83
top level DAP object to house generic methods
Definition: AlarmHandler.h:36
Part
Names the parts of multi-section constructor data types.
Definition: Type.h:48
int64_t start
The constraint start index.
Definition: Array.h:158
int64_t stride
The constraint stride.
Definition: Array.h:160
string name
The name of this dimension.
Definition: Array.h:146
D4Dimension * dim
If not null, a weak pointer to the D4Dimension.
Definition: Array.h:148
int64_t size
The unconstrained dimension size.
Definition: Array.h:145
int64_t stop
The constraint end index.
Definition: Array.h:159
bool use_sdim_for_slice
Used to control printing the DMR in data responses.
Definition: Array.h:156
int64_t c_size
Size of dimension once constrained.
Definition: Array.h:161