libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
Array.h
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) 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
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 = 0;
143 string name;
144
145 D4Dimension *dim = nullptr;
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.
153 bool use_sdim_for_slice = false;
154
155 int64_t start = 0;
156 int64_t stop = 0;
157 int64_t stride = 1;
158 int64_t c_size = 0;
159
160 dimension() = default;
161
162 dimension(int64_t s, string n) : size(s), name(std::move(n)), stop(s - 1), c_size(s) {}
163
164 explicit dimension(D4Dimension *d);
165 };
166
167 // The following two structs are for the direct IO optimization.
168 // The variable chunk and compression information need to be passed
169 // between two BES modules. The ideal approach is to use the
170 // dynamic_cast for a BES module to retrieve the information stored
171 // by another module. However, there are issues in the current BES
172 // that prevent us from implementing in this way.
173 // So we need to use libdap to do the job.
175 unsigned int filter_mask;
176 unsigned long long chunk_direct_io_offset;
177 unsigned long long chunk_buffer_size;
178 vector<unsigned long long> chunk_coords;
179 };
180
182 string filter;
183 vector<unsigned int> deflate_levels;
184 vector<size_t> chunk_dims;
185 vector<var_chunk_info_t> var_chunk_info;
186 };
187
188private:
189 D4Maps *d_maps = nullptr;
190
191 std::vector<dimension> _shape; // list of dimensions (i.e., the shape)
192
193 bool direct_io_flag = false;
194 var_storage_info vs_info;
195
196 void update_dimension_pointers(D4Dimensions *old_dims, D4Dimensions *new_dims);
197 void print_dim_element(const XMLWriter &xml, const dimension &d, bool constrained);
198
199 friend class ArrayTest;
200 friend class D4Group;
201
202protected:
203 void _duplicate(const Array &a);
204
205 uint64_t print_array(FILE *out, uint64_t index, unsigned int dims, uint64_t shape[]);
206
207 uint64_t print_array(ostream &out, uint64_t index, unsigned int dims, uint64_t shape[]);
208
209 std::vector<dimension> &shape() { return _shape; }
210
211public:
217 typedef std::vector<dimension>::const_iterator Dim_citer;
218
225 typedef std::vector<dimension>::iterator Dim_iter;
226
227 Array(const string &n, BaseType *v, bool is_dap4 = false);
228 Array(const string &n, const string &d, BaseType *v, bool is_dap4 = false);
229 Array(const Array &rhs);
230 virtual ~Array();
231
232 Array &operator=(const Array &rhs);
233 BaseType *ptr_duplicate() override;
234
235 bool is_dap2_grid();
236 void transform_to_dap4(D4Group *root, Constructor *container) override;
237 std::vector<BaseType *> *transform_to_dap2(AttrTable *parent_attr_table) override;
238
239 void add_var(BaseType *v, Part p = nil) override;
240 void add_var_nocopy(BaseType *v, Part p = nil) override;
241
242 void append_dim(int size, const string &name = "");
243 void append_dim_ll(int64_t size, const string &name = "");
244 void append_dim(D4Dimension *dim);
245 void prepend_dim(int size, const string &name = "");
246 void prepend_dim(D4Dimension *dim);
247 void clear_all_dims();
248 void rename_dim(const string &oldName = "", const string &newName = "");
249
250 virtual void add_constraint(Dim_iter i, int start, int stride, int stop);
251 virtual void add_constraint_ll(Dim_iter i, int64_t start, int64_t stride, int64_t stop);
252 virtual void add_constraint(Dim_iter i, D4Dimension *dim);
253 virtual void reset_constraint();
254
255 virtual void clear_constraint(); // deprecated
256
257 virtual void update_length(int size = 0); // should be used internally only
258 virtual void update_length_ll(unsigned long long size = 0); // should be used internally only
259
262
263 virtual int dimension_size(Dim_iter i, bool constrained = false);
264 virtual int dimension_start(Dim_iter i, bool constrained = false);
265 virtual int dimension_stop(Dim_iter i, bool constrained = false);
266 virtual int dimension_stride(Dim_iter i, bool constrained = false);
267
268 virtual int64_t dimension_size_ll(Dim_iter i, bool constrained = false);
269 virtual int64_t dimension_start_ll(Dim_iter i, bool constrained = false);
270 virtual int64_t dimension_stop_ll(Dim_iter i, bool constrained = false);
271 virtual int64_t dimension_stride_ll(Dim_iter i, bool constrained = false);
272
273 virtual string dimension_name(Dim_iter i);
275
276 virtual unsigned int dimensions(bool constrained = false);
277
278 virtual D4Maps *maps();
279
280 void print_dap4(XMLWriter &xml, bool constrained = false) override;
281
282 // These are all DAP2 output methods
283
284 void print_decl(ostream &out, string space = " ", bool print_semi = true, bool constraint_info = false,
285 bool constrained = false) override;
286
287 void print_xml(ostream &out, string space = " ", bool constrained = false) override;
288
289 void print_xml_writer(XMLWriter &xml, bool constrained = false) override;
290 virtual void print_xml_writer_core(XMLWriter &out, bool constrained, string tag);
291 virtual void print_as_map_xml_writer(XMLWriter &xml, bool constrained);
292
293 virtual void print_xml_core(FILE *out, string space, bool constrained, string tag);
294 virtual void print_xml_core(ostream &out, string space, bool constrained, string tag);
295
296 // not used (?)
297 virtual void print_as_map_xml(ostream &out, string space = " ", bool constrained = false);
298
299 void print_val(ostream &out, string space = "", bool print_decl_p = true) override;
300
301 void print_xml(FILE *out, string space = " ", bool constrained = false) override;
302 virtual void print_as_map_xml(FILE *out, string space = " ", bool constrained = false);
303 void print_val(FILE *out, string space = "", bool print_decl_p = true) override;
304 void print_decl(FILE *out, string space = " ", bool print_semi = true, bool constraint_info = false,
305 bool constrained = false) override;
306
307 bool check_semantics(string &msg, bool all = false) override;
308
309 bool is_dap4_projected(std::vector<std::string> &projected_dap4_inventory) override;
310
311 void dump(ostream &strm) const override;
312
313 // The following methods are for direct IO optimization.
314 bool get_dio_flag() const { return direct_io_flag; }
315 void set_dio_flag(bool dio_flag_value = true) { direct_io_flag = dio_flag_value; }
317 void set_var_storage_info(const var_storage_info &my_vs_info);
318};
319
320} // namespace libdap
321
322#endif // _array_h
virtual void print_as_map_xml_writer(XMLWriter &xml, bool constrained)
Definition Array.cc:1061
void print_dap4(XMLWriter &xml, bool constrained=false) override
Print the DAP4 representation of an array.
Definition Array.cc:897
virtual int dimension_start(Dim_iter i, bool constrained=false)
Return the start index of a dimension.
Definition Array.cc:761
virtual void clear_constraint()
Clears the projection; add each projected dimension explicitly using add_constraint.
Definition Array.cc:571
virtual void add_constraint_ll(Dim_iter i, int64_t start, int64_t stride, int64_t stop)
Definition Array.cc:640
Dim_iter dim_end()
Definition Array.cc:692
bool is_dap2_grid()
Definition Array.cc:220
var_storage_info & get_var_storage_info()
Definition Array.h:316
virtual int64_t dimension_start_ll(Dim_iter i, bool constrained=false)
Definition Array.cc:831
bool get_dio_flag() const
Definition Array.h:314
virtual int64_t dimension_stop_ll(Dim_iter i, bool constrained=false)
Definition Array.cc:833
virtual int dimension_stop(Dim_iter i, bool constrained=false)
Return the stop index of the constraint.
Definition Array.cc:786
void dump(ostream &strm) const override
dumps information about this object
Definition Array.cc:1283
virtual void update_length(int size=0)
Definition Array.cc:87
bool is_dap4_projected(std::vector< std::string > &projected_dap4_inventory) override
Definition Array.cc:1257
virtual void add_constraint(Dim_iter i, int start, int stride, int stop)
Adds a constraint to an Array dimension.
Definition Array.cc:598
virtual string dimension_name(Dim_iter i)
Returns the name of the specified dimension.
Definition Array.cc:847
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:981
friend class D4Group
Definition Array.h:200
virtual int64_t dimension_size_ll(Dim_iter i, bool constrained=false)
Definition Array.cc:819
void print_xml(ostream &out, string space=" ", bool constrained=false) override
Definition Array.cc:1017
void print_val(ostream &out, string space="", bool print_decl_p=true) override
Prints the value of the variable.
Definition Array.cc:1187
friend class ArrayTest
Definition Array.h:199
BaseType * ptr_duplicate() override
Definition Array.cc:153
void append_dim(int size, const string &name="")
Add a dimension of a given size.
Definition Array.cc:481
std::vector< dimension >::iterator Dim_iter
Definition Array.h:225
virtual D4Maps * maps()
Definition Array.cc:860
virtual D4Dimension * dimension_D4dim(Dim_iter i)
Definition Array.cc:858
void rename_dim(const string &oldName="", const string &newName="")
Renames dimension.
Definition Array.cc:531
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:268
std::vector< dimension > & shape()
Definition Array.h:209
virtual int dimension_size(Dim_iter i, bool constrained=false)
Returns the size of the dimension.
Definition Array.cc:723
void clear_all_dims()
Definition Array.cc:524
virtual void print_xml_writer_core(XMLWriter &out, bool constrained, string tag)
Definition Array.cc:1065
std::vector< dimension >::const_iterator Dim_citer
Definition Array.h:217
void add_var(BaseType *v, Part p=nil) override
Add the BaseType pointer to this constructor type instance.
Definition Array.cc:433
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:1118
virtual void print_as_map_xml(ostream &out, string space=" ", bool constrained=false)
Definition Array.cc:1035
void print_xml_writer(XMLWriter &xml, bool constrained=false) override
Definition Array.cc:1059
virtual void reset_constraint()
Reset constraint to select entire array.
Definition Array.cc:549
void set_var_storage_info(const var_storage_info &my_vs_info)
Set the variable storage information for direct IO optimization.
Definition Array.cc:1320
virtual ~Array()
The Array destructor.
Definition Array.cc:151
virtual void print_xml_core(FILE *out, string space, bool constrained, string tag)
Definition Array.cc:1044
void add_var_nocopy(BaseType *v, Part p=nil) override
Definition Array.cc:452
void append_dim_ll(int64_t size, const string &name="")
Definition Array.cc:488
void prepend_dim(int size, const string &name="")
Definition Array.cc:505
void set_dio_flag(bool dio_flag_value=true)
Definition Array.h:315
Dim_iter dim_begin()
Definition Array.cc:689
void transform_to_dap4(D4Group *root, Constructor *container) override
DAP2 to DAP4 transform.
Definition Array.cc:163
Array(const string &n, BaseType *v, bool is_dap4=false)
Array constructor.
Definition Array.cc:121
bool check_semantics(string &msg, bool all=false) override
Check semantic features of the Array.
Definition Array.cc:1223
virtual void update_length_ll(unsigned long long size=0)
Definition Array.cc:96
virtual unsigned int dimensions(bool constrained=false)
Return the total number of dimensions in the array.
Definition Array.cc:704
virtual int64_t dimension_stride_ll(Dim_iter i, bool constrained=false)
Definition Array.cc:835
void _duplicate(const Array &a)
Definition Array.cc:64
Array & operator=(const Array &rhs)
Definition Array.cc:155
virtual int dimension_stride(Dim_iter i, bool constrained=false)
Returns the stride value of the constraint.
Definition Array.cc:812
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
virtual bool is_dap4() const
Definition BaseType.h:181
Vector(const string &n, BaseType *v, const Type &t, bool is_dap4=false)
The Vector constructor.
Definition Vector.cc:254
#define DODS_INT_MAX
Definition dods-limits.h:73
top level DAP object to house generic methods
Definition AISConnect.cc:30
const int DODS_MAX_ARRAY
Definition Array.h:60
Part
Names the parts of multi-section constructor data types.
Definition Type.h:48
@ nil
Definition Type.h:49
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
dimension(int64_t s, string n)
Definition Array.h:162
int64_t c_size
Size of dimension once constrained.
Definition Array.h:158
unsigned long long chunk_buffer_size
Definition Array.h:177
vector< unsigned long long > chunk_coords
Definition Array.h:178
unsigned long long chunk_direct_io_offset
Definition Array.h:176
vector< size_t > chunk_dims
Definition Array.h:184
vector< var_chunk_info_t > var_chunk_info
Definition Array.h:185
vector< unsigned int > deflate_levels
Definition Array.h:183