libdap  Updated for version 3.20.6
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 
53 namespace libdap
54 {
55 class D4Group;
56 class D4Maps;
57 class XMLWriter;
58 class D4Dimension;
59 class D4Dimensions;
60 
61 const int DODS_MAX_ARRAY = DODS_INT_MAX;
62 
112 class Array: public Vector
113 {
114 public:
125  struct dimension
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 
169  };
170 
171  D4Maps *d_maps;
172 
173 private:
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 
181  bool is_dap2_grid();
182 
183 protected:
184  void _duplicate(const Array &a);
185 
186  unsigned int print_array(FILE *out, unsigned int index,
187  unsigned int dims, unsigned int shape[]);
188 
189  unsigned int print_array(ostream &out, unsigned int index,
190  unsigned int dims, unsigned int shape[]);
191 
192 public:
198  typedef std::vector<dimension>::const_iterator Dim_citer;
199 
206  typedef std::vector<dimension>::iterator Dim_iter;
207 
208  Array(const string &n, BaseType *v, bool is_dap4 = false);
209  Array(const string &n, const string &d, BaseType *v, bool is_dap4 = false);
210  Array(const Array &rhs);
211  virtual ~Array();
212 
213  Array &operator=(const Array &rhs);
214  virtual BaseType *ptr_duplicate();
215 
216  virtual void transform_to_dap4(D4Group *root, Constructor *container);
217  virtual std::vector<BaseType *> *transform_to_dap2(AttrTable *parent_attr_table);
218 
219  void add_var(BaseType *v, Part p = nil);
220  void add_var_nocopy(BaseType *v, Part p = nil);
221 
222  void append_dim(int size, const string &name = "");
223  void append_dim(D4Dimension *dim);
224  void prepend_dim(int size, const string& name = "");
225  void prepend_dim(D4Dimension *dim);
226  void clear_all_dims();
227  void rename_dim(const string &oldName = "", const string &newName = "");
228 
229  virtual void add_constraint(Dim_iter i, int start, int stride, int stop);
230  virtual void add_constraint(Dim_iter i, D4Dimension *dim);
231  virtual void reset_constraint();
232 
233  virtual void clear_constraint(); // deprecated
234 
235  virtual void update_length(int size = 0); // should be used internally only
236 
237  Dim_iter dim_begin() ;
238  Dim_iter dim_end() ;
239 
240  virtual int dimension_size(Dim_iter i, bool constrained = false);
241  virtual int dimension_start(Dim_iter i, bool constrained = false);
242  virtual int dimension_stop(Dim_iter i, bool constrained = false);
243  virtual int dimension_stride(Dim_iter i, bool constrained = false);
244  virtual string dimension_name(Dim_iter i);
245  virtual D4Dimension *dimension_D4dim(Dim_iter i);
246 
247  virtual unsigned int dimensions(bool constrained = false);
248 
249  virtual D4Maps *maps();
250 
251  virtual void print_dap4(XMLWriter &xml, bool constrained = false);
252 
253  // These are all DAP2 output methods
254 
255  virtual void print_decl(ostream &out, string space = " ",
256  bool print_semi = true,
257  bool constraint_info = false,
258  bool constrained = false);
259 
260  virtual void print_xml(ostream &out, string space = " ",
261  bool constrained = false);
262 
263  virtual void print_xml_writer(XMLWriter &xml, bool constrained = false);
264  virtual void print_xml_writer_core(XMLWriter &out, bool constrained, string tag);
265  virtual void print_as_map_xml_writer(XMLWriter &xml, bool constrained);
266 
267  virtual void print_xml_core(FILE *out, string space, bool constrained, string tag);
268  virtual void print_xml_core(ostream &out, string space, bool constrained, string tag);
269 
270  // not used (?)
271  virtual void print_as_map_xml(ostream &out, string space = " ",
272  bool constrained = false);
273 
274  virtual void print_val(ostream &out, string space = "",
275  bool print_decl_p = true);
276 
277  virtual void print_xml(FILE *out, string space = " ",
278  bool constrained = false);
279  virtual void print_as_map_xml(FILE *out, string space = " ",
280  bool constrained = false);
281  virtual void print_val(FILE *out, string space = "",
282  bool print_decl_p = true);
283  virtual void print_decl(FILE *out, string space = " ",
284  bool print_semi = true,
285  bool constraint_info = false,
286  bool constrained = false);
287 
288  virtual bool check_semantics(string &msg, bool all = false);
289 
290 
291  virtual void dump(ostream &strm) const ;
292 };
293 
294 } // namespace libdap
295 
296 #endif // _array_h
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
Definition: Array.cc:1124
virtual void reset_constraint()
Reset constraint to select entire array.
Definition: Array.cc:593
virtual void add_constraint(Dim_iter i, int start, int stride, int stop)
Adds a constraint to an Array dimension.
Definition: Array.cc:647
virtual bool check_semantics(string &msg, bool all=false)
Check semantic features of the Array.
Definition: Array.cc:1308
virtual void print_xml_core(FILE *out, string space, bool constrained, string tag)
Definition: Array.cc:1107
virtual void dump(ostream &strm) const
dumps information about this object
Definition: Array.cc:1325
Array(const string &n, BaseType *v, bool is_dap4=false)
Array constructor.
Definition: Array.cc:136
virtual unsigned int dimensions(bool constrained=false)
Return the total number of dimensions in the array.
Definition: Array.cc:711
Part
Names the parts of multi-section constructor data types.
Definition: Type.h:48
void add_var(BaseType *v, Part p=nil)
Add the BaseType pointer to this constructor type instance.
Definition: Array.cc:470
Contains the attributes for a dataset.
Definition: AttrTable.h:142
int stop
The constraint end index.
Definition: Array.h:149
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:80
std::vector< dimension >::const_iterator Dim_citer
Definition: Array.h:198
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
void append_dim(int size, const string &name="")
Add a dimension of a given size.
Definition: Array.cc:522
virtual void update_length(int size=0)
Definition: Array.cc:103
top level DAP object to house generic methods
Definition: AISConnect.cc:30
Dim_iter dim_end()
Definition: Array.cc:696
virtual void print_as_map_xml(ostream &out, string space=" ", bool constrained=false)
Definition: Array.cc:1097
virtual std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table)
Transforms this instance of a D4Array into the corresponding DAP2 object.
Definition: Array.cc:302
virtual int dimension_size(Dim_iter i, bool constrained=false)
Returns the size of the dimension.
Definition: Array.cc:733
std::vector< dimension >::iterator Dim_iter
Definition: Array.h:206
void clear_all_dims()
Definition: Array.cc:564
virtual string dimension_name(Dim_iter i)
Returns the name of the specified dimension.
Definition: Array.cc:827
virtual BaseType * ptr_duplicate()
Definition: Array.cc:175
virtual int dimension_stride(Dim_iter i, bool constrained=false)
Returns the stride value of the constraint.
Definition: Array.cc:812
int stride
The constraint stride.
Definition: Array.h:150
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:1039
D4Dimension * dim
If not null, a weak pointer to the D4Dimension.
Definition: Array.h:138
int c_size
Size of dimension once constrained.
Definition: Array.h:151
void prepend_dim(int size, const string &name="")
Definition: Array.cc:543
virtual void print_xml(ostream &out, string space=" ", bool constrained=false)
Definition: Array.cc:1077
virtual int dimension_stop(Dim_iter i, bool constrained=false)
Return the stop index of the constraint.
Definition: Array.cc:788
virtual int dimension_start(Dim_iter i, bool constrained=false)
Return the start index of a dimension.
Definition: Array.cc:765
virtual void print_dap4(XMLWriter &xml, bool constrained=false)
Print the DAP4 representation of an array.
Definition: Array.cc:958
virtual ~Array()
The Array destructor.
Definition: Array.cc:169
int size
The unconstrained dimension size.
Definition: Array.h:135
string name
The name of this dimension.
Definition: Array.h:136
The basic data type for the DODS DAP types.
Definition: BaseType.h:117
Dim_iter dim_begin()
Definition: Array.cc:690
void rename_dim(const string &oldName="", const string &newName="")
Renames dimension.
Definition: Array.cc:574
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:1198
A multidimensional array of identical data types.
Definition: Array.h:112
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition: Array.cc:1271
virtual void transform_to_dap4(D4Group *root, Constructor *container)
DAP2 to DAP4 transform.
Definition: Array.cc:192
virtual void clear_constraint()
Clears the projection; add each projected dimension explicitly using add_constraint.
Definition: Array.cc:616