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