libdap++  Updated for version 3.14.0
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 
53 namespace libdap
54 {
55 class D4Group;
56 class D4Maps;
57 class XMLWriter;
58 class D4Dimension;
59 class D4Dimensions;
60 
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 #if 0
170  dimension(D4Dimension *d) : dim(d), use_sdim_for_slice(true) {
171  size = d->size();
172  name = d->name();
173 
174  start = 0;
175  stop = size - 1;
176  stride = 1;
177  c_size = size;
178  }
179 #endif
180  };
181 
183 
184 private:
185  std::vector<dimension> _shape; // list of dimensions (i.e., the shape)
186 
187  void update_dimension_pointers(D4Dimensions *old_dims, D4Dimensions *new_dims);
188 
189  friend class ArrayTest;
190  friend class D4Group;
191 
192 protected:
193  void _duplicate(const Array &a);
194 
195  unsigned int print_array(FILE *out, unsigned int index,
196  unsigned int dims, unsigned int shape[]);
197 
198  unsigned int print_array(ostream &out, unsigned int index,
199  unsigned int dims, unsigned int shape[]);
200 
201 public:
207  typedef std::vector<dimension>::const_iterator Dim_citer ;
214  typedef std::vector<dimension>::iterator Dim_iter ;
215 
216  Array(const string &n, BaseType *v, bool is_dap4 = false);
217  Array(const string &n, const string &d, BaseType *v, bool is_dap4 = false);
218  Array(const Array &rhs);
219  virtual ~Array();
220 
221  Array &operator=(const Array &rhs);
222  virtual BaseType *ptr_duplicate();
223 
224  virtual BaseType *transform_to_dap4(D4Group *root, Constructor *container);
225 
226  void add_var(BaseType *v, Part p = nil);
227  void add_var_nocopy(BaseType *v, Part p = nil);
228 
229  void append_dim(int size, const string &name = "");
230  void append_dim(D4Dimension *dim);
231  void prepend_dim(int size, const string& name = "");
232  void prepend_dim(D4Dimension *dim);
233  void clear_all_dims();
234 
235  virtual void add_constraint(Dim_iter i, int start, int stride, int stop);
236  virtual void add_constraint(Dim_iter i, D4Dimension *dim);
237  virtual void reset_constraint();
238 
239  virtual void clear_constraint(); // deprecated
240 
241  virtual void update_length(int size = 0); // should be used internally only
242 
243  Dim_iter dim_begin() ;
244  Dim_iter dim_end() ;
245 
246  virtual int dimension_size(Dim_iter i, bool constrained = false);
247  virtual int dimension_start(Dim_iter i, bool constrained = false);
248  virtual int dimension_stop(Dim_iter i, bool constrained = false);
249  virtual int dimension_stride(Dim_iter i, bool constrained = false);
250  virtual string dimension_name(Dim_iter i);
251  virtual D4Dimension *dimension_D4dim(Dim_iter i);
252 
253  virtual unsigned int dimensions(bool constrained = false);
254 
255  virtual D4Maps *maps();
256 
257  virtual void print_dap4(XMLWriter &xml, bool constrained = false);
258 
259  // These are all DAP2 output methods
260 
261  virtual void print_decl(ostream &out, string space = " ",
262  bool print_semi = true,
263  bool constraint_info = false,
264  bool constrained = false);
265 
266  virtual void print_xml(ostream &out, string space = " ",
267  bool constrained = false);
268 
269  virtual void print_xml_writer(XMLWriter &xml, bool constrained = false);
270  virtual void print_xml_writer_core(XMLWriter &out, bool constrained, string tag);
271  virtual void print_as_map_xml_writer(XMLWriter &xml, bool constrained);
272 
273  virtual void print_xml_core(FILE *out, string space, bool constrained, string tag);
274  virtual void print_xml_core(ostream &out, string space, bool constrained, string tag);
275 
276  // not used (?)
277  virtual void print_as_map_xml(ostream &out, string space = " ",
278  bool constrained = false);
279 
280  virtual void print_val(ostream &out, string space = "",
281  bool print_decl_p = true);
282 
283  virtual void print_xml(FILE *out, string space = " ",
284  bool constrained = false);
285  virtual void print_as_map_xml(FILE *out, string space = " ",
286  bool constrained = false);
287  virtual void print_val(FILE *out, string space = "",
288  bool print_decl_p = true);
289  virtual void print_decl(FILE *out, string space = " ",
290  bool print_semi = true,
291  bool constraint_info = false,
292  bool constrained = false);
293 
294  virtual bool check_semantics(string &msg, bool all = false);
295 
296  virtual void dump(ostream &strm) const ;
297 };
298 
299 } // namespace libdap
300 
301 #endif // _array_h
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
Definition: Array.cc:951
virtual void reset_constraint()
Reset constraint to select entire array.
Definition: Array.cc:398
virtual void add_constraint(Dim_iter i, int start, int stride, int stop)
Adds a constraint to an Array dimension.
Definition: Array.cc:455
virtual bool check_semantics(string &msg, bool all=false)
Check semantic features of the Array.
Definition: Array.cc:1126
virtual void print_xml_core(FILE *out, string space, bool constrained, string tag)
Definition: Array.cc:932
Array(const string &n, BaseType *v, bool is_dap4=false)
Array constructor.
Definition: Array.cc:130
virtual unsigned int dimensions(bool constrained=false)
Return the total number of dimensions in the array.
Definition: Array.cc:527
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:287
int stop
The constraint end index.
Definition: Array.h:149
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:80
bool is_dap4() const
Definition: BaseType.h:166
std::vector< dimension >::const_iterator Dim_citer
Definition: Array.h:207
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
Array & operator=(const Array &rhs)
Definition: Array.cc:174
virtual D4Maps * maps()
Definition: Array.cc:668
D4Maps * d_maps
Definition: Array.h:182
void append_dim(int size, const string &name="")
Add a dimension of a given size.
Definition: Array.cc:341
virtual void update_length(int size=0)
Definition: Array.cc:102
void _duplicate(const Array &a)
Definition: Array.cc:75
virtual D4Dimension * dimension_D4dim(Dim_iter i)
Definition: Array.cc:662
Dim_iter dim_end()
Definition: Array.cc:511
virtual void print_as_map_xml(ostream &out, string space=" ", bool constrained=false)
Definition: Array.cc:921
friend class ArrayTest
Definition: Array.h:189
virtual int dimension_size(Dim_iter i, bool constrained=false)
Returns the size of the dimension.
Definition: Array.cc:550
std::vector< dimension >::iterator Dim_iter
Definition: Array.h:214
void clear_all_dims()
Definition: Array.cc:387
virtual string dimension_name(Dim_iter i)
Returns the name of the specified dimension.
Definition: Array.cc:648
virtual BaseType * ptr_duplicate()
Definition: Array.cc:168
virtual int dimension_stride(Dim_iter i, bool constrained=false)
Returns the stride value of the constraint.
Definition: Array.cc:632
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:857
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
virtual void print_as_map_xml_writer(XMLWriter &xml, bool constrained)
Definition: Array.cc:957
void prepend_dim(int size, const string &name="")
Definition: Array.cc:364
virtual void print_xml(ostream &out, string space=" ", bool constrained=false)
Definition: Array.cc:899
virtual int dimension_stop(Dim_iter i, bool constrained=false)
Return the stop index of the constraint.
Definition: Array.cc:607
dimension(unsigned long s, string n)
Definition: Array.h:161
virtual void dump(ostream &strm) const
dumps information about this object
Definition: Array.cc:1145
virtual int dimension_start(Dim_iter i, bool constrained=false)
Return the start index of a dimension.
Definition: Array.cc:583
virtual void print_dap4(XMLWriter &xml, bool constrained=false)
Print the DAP4 representation of an array.
Definition: Array.cc:773
virtual ~Array()
The Array destructor.
Definition: Array.cc:162
int size
The unconstrained dimension size.
Definition: Array.h:135
string name
The name of this dimension.
Definition: Array.h:136
const int DODS_MAX_ARRAY
Definition: Array.h:61
The basic data type for the DODS DAP types.
Definition: BaseType.h:117
Dim_iter dim_begin()
Definition: Array.cc:504
void add_var_nocopy(BaseType *v, Part p=nil)
Definition: Array.cc:309
virtual void print_xml_writer_core(XMLWriter &out, bool constrained, string tag)
Definition: Array.cc:989
string name() const
Definition: D4Dimensions.h:58
unsigned long size() const
Definition: D4Dimensions.h:62
virtual BaseType * transform_to_dap4(D4Group *root, Constructor *container)
DAP2 to DAP4 transform.
Definition: Array.cc:187
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:1027
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:1089
#define DODS_INT_MAX
Definition: dods-limits.h:73
virtual void clear_constraint()
Clears the projection; add each projected dimension explicitly using add_constraint.
Definition: Array.cc:423