libdap++  Updated for version 3.8.2
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 #define FILE_METHODS 1
52 
53 namespace libdap
54 {
55 
57 
101 class Array: public Vector
102 {
103 public:
114  struct dimension
115  {
116  int size;
117  string name;
118  int start;
119  int stop;
120  int stride;
121  int c_size;
122  };
123 
124 private:
125  std::vector<dimension> _shape; // list of dimensions (i.e., the shape)
126 
127  friend class ArrayTest;
128 
129 protected:
130  void _duplicate(const Array &a);
131 
132 #if FILE_METHODS
133  unsigned int print_array(FILE *out, unsigned int index,
134  unsigned int dims, unsigned int shape[]);
135 #endif
136  unsigned int print_array(ostream &out, unsigned int index,
137  unsigned int dims, unsigned int shape[]);
138 
139 public:
145  typedef std::vector<dimension>::const_iterator Dim_citer ;
152  typedef std::vector<dimension>::iterator Dim_iter ;
153 
154  Array(const string &n, BaseType *v);
155  Array(const string &n, const string &d, BaseType *v);
156  Array(const Array &rhs);
157  virtual ~Array();
158 
159  Array &operator=(const Array &rhs);
160  virtual BaseType *ptr_duplicate();
161 
162  void add_var(BaseType *v, Part p = nil);
163 
164  void append_dim(int size, string name = "");
165  void prepend_dim(int size, const string& name = "");
166 
167  virtual void add_constraint(Dim_iter i, int start, int stride, int stop);
168  virtual void reset_constraint();
169 
170  virtual void clear_constraint();
171 
172  virtual void update_length(int size);
173 
174  Dim_iter dim_begin() ;
175  Dim_iter dim_end() ;
176 
177  virtual int dimension_size(Dim_iter i, bool constrained = false);
178  virtual int dimension_start(Dim_iter i, bool constrained = false);
179  virtual int dimension_stop(Dim_iter i, bool constrained = false);
180  virtual int dimension_stride(Dim_iter i, bool constrained = false);
181  virtual string dimension_name(Dim_iter i);
182 
183  virtual unsigned int dimensions(bool constrained = false);
184 
185  virtual void print_decl(ostream &out, string space = " ",
186  bool print_semi = true,
187  bool constraint_info = false,
188  bool constrained = false);
189 
190  virtual void print_xml(ostream &out, string space = " ",
191  bool constrained = false);
192 
193 #if FILE_METHODS
194  virtual void print_xml_core(FILE *out, string space, bool constrained, string tag);
195 #endif
196  virtual void print_xml_core(ostream &out, string space, bool constrained, string tag);
197 
198  // not used (?)
199  virtual void print_as_map_xml(ostream &out, string space = " ",
200  bool constrained = false);
201 
202  virtual void print_val(ostream &out, string space = "",
203  bool print_decl_p = true);
204 
205 #if FILE_METHODS
206  virtual void print_xml(FILE *out, string space = " ",
207  bool constrained = false);
208  virtual void print_as_map_xml(FILE *out, string space = " ",
209  bool constrained = false);
210  virtual void print_val(FILE *out, string space = "",
211  bool print_decl_p = true);
212  virtual void print_decl(FILE *out, string space = " ",
213  bool print_semi = true,
214  bool constraint_info = false,
215  bool constrained = false);
216 #endif
217 
218  virtual bool check_semantics(string &msg, bool all = false);
219 
220  virtual void dump(ostream &strm) const ;
221 };
222 
223 } // namespace libdap
224 
225 #endif // _array_h
virtual void reset_constraint()
Reset constraint to select entire array.
Definition: Array.cc:257
virtual void add_constraint(Dim_iter i, int start, int stride, int stop)
Adds a constraint to an Array dimension.
Definition: Array.cc:313
virtual bool check_semantics(string &msg, bool all=false)
Check semantic features of the Array.
Definition: Array.cc:871
virtual void print_xml_core(FILE *out, string space, bool constrained, string tag)
Definition: Array.cc:640
virtual unsigned int dimensions(bool constrained=false)
Return the total number of dimensions in the array.
Definition: Array.cc:362
Part
Names the parts of multi-section constructor data types.
Definition: BaseType.h:98
void add_var(BaseType *v, Part p=nil)
Add the BaseType pointer to this constructor type instance.
Definition: Array.cc:176
int stop
The constraint end index.
Definition: Array.h:119
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:78
std::vector< dimension >::const_iterator Dim_citer
Definition: Array.h:145
int start
The constraint start index.
Definition: Array.h:118
Array & operator=(const Array &rhs)
Definition: Array.cc:144
void _duplicate(const Array &a)
Definition: Array.cc:53
Dim_iter dim_end()
Definition: Array.cc:347
virtual void print_as_map_xml(ostream &out, string space=" ", bool constrained=false)
Definition: Array.cc:612
friend class ArrayTest
Definition: Array.h:127
virtual int dimension_size(Dim_iter i, bool constrained=false)
Returns the size of the dimension.
Definition: Array.cc:390
void append_dim(int size, string name="")
Add a dimension of a given size.
Definition: Array.cc:205
std::vector< dimension >::iterator Dim_iter
Definition: Array.h:152
virtual string dimension_name(Dim_iter i)
Returns the name of the specified dimension.
Definition: Array.cc:488
virtual BaseType * ptr_duplicate()
Definition: Array.cc:138
virtual int dimension_stride(Dim_iter i, bool constrained=false)
Returns the stride value of the constraint.
Definition: Array.cc:472
int stride
The constraint stride.
Definition: Array.h:120
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:566
int c_size
Size of dimension once constrained.
Definition: Array.h:121
void prepend_dim(int size, const string &name="")
Definition: Array.cc:230
string name() const
Returns the name of the class instance.
Definition: BaseType.cc:210
virtual void print_xml(ostream &out, string space=" ", bool constrained=false)
Definition: Array.cc:600
Array(const string &n, BaseType *v)
Array constructor.
Definition: Array.cc:100
virtual int dimension_stop(Dim_iter i, bool constrained=false)
Return the stop index of the constraint.
Definition: Array.cc:447
virtual void dump(ostream &strm) const
dumps information about this object
Definition: Array.cc:890
virtual int dimension_start(Dim_iter i, bool constrained=false)
Return the start index of a dimension.
Definition: Array.cc:423
virtual ~Array()
The Array destructor.
Definition: Array.cc:131
int size
The unconstrained dimension size.
Definition: Array.h:116
string name
The name of this dimension.
Definition: Array.h:117
const int DODS_MAX_ARRAY
Definition: Array.h:56
The basic data type for the DODS DAP types.
Definition: BaseType.h:190
Dim_iter dim_begin()
Definition: Array.cc:340
virtual void update_length(int size)
Definition: Array.cc:72
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:724
A multidimensional array of identical data types.
Definition: Array.h:101
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition: Array.cc:834
#define DODS_INT_MAX
Definition: dods-limits.h:49
virtual void clear_constraint()
Clears the projection; add each projected dimension explicitly using add_constraint.
Definition: Array.cc:282