libdap
Updated for version 3.17.0
|
00001 00002 // -*- mode: c++; c-basic-offset:4 -*- 00003 00004 // This file is part of libdap, A C++ implementation of the OPeNDAP Data 00005 // Access Protocol. 00006 00007 // Copyright (c) 2002,2003 OPeNDAP, Inc. 00008 // Author: James Gallagher <jgallagher@opendap.org> 00009 // 00010 // This library is free software; you can redistribute it and/or 00011 // modify it under the terms of the GNU Lesser General Public 00012 // License as published by the Free Software Foundation; either 00013 // version 2.1 of the License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00023 // 00024 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112. 00025 00026 // (c) COPYRIGHT URI/MIT 1994-1999 00027 // Please read the full copyright statement in the file COPYRIGHT_URI. 00028 // 00029 // Authors: 00030 // jhrg,jimg James Gallagher <jgallagher@gso.uri.edu> 00031 00032 // Class for array variables. The dimensions of the array are stored in the 00033 // list SHAPE. 00034 // 00035 // jhrg 9/6/94 00036 00037 #ifndef _array_h 00038 #define _array_h 1 00039 00040 #include <string> 00041 #include <vector> 00042 00043 #ifndef _dods_limits_h 00044 #include "dods-limits.h" 00045 #endif 00046 00047 #ifndef _vector_h 00048 #include "Vector.h" 00049 #endif 00050 00051 //#include "D4Dimensions.h" 00052 00053 namespace libdap 00054 { 00055 class D4Group; 00056 class D4Maps; 00057 class XMLWriter; 00058 class D4Dimension; 00059 class D4Dimensions; 00060 00061 const int DODS_MAX_ARRAY = DODS_INT_MAX; 00062 00112 class Array: public Vector 00113 { 00114 public: 00125 struct dimension 00126 { 00127 // In DAP2, the name and size of a dimension is stored here, along 00128 // with information about any constraint. In DAP4, either the name 00129 // and size are stored in the two fields below _or_ the name and 00130 // size information comes from a dimension object defined in a 00131 // group that is referenced by the 'dim' pointer. Do not free this 00132 // pointer; it is shared between the array and the Group where the 00133 // Dimension is defined. To keep Array manageable to implement, size 00134 // will be set here using the value from 'dim' if it is not null. 00135 int size; 00136 string name; 00137 00138 D4Dimension *dim; 00139 00140 // when a DMR is printed for a data response, if an array uses shared 00141 // dimensions and those sdims have been sliced, make sure to use those 00142 // and get the syntax correct. That's what this field does - in every 00143 // case the array records the sizes of its dimensions and their slices 00144 // regardless of whether they were provided explicitly in a CE or inherited 00145 // from a sliced sdim. 00146 bool use_sdim_for_slice; 00147 00148 int start; 00149 int stop; 00150 int stride; 00151 int c_size; 00152 00153 dimension() : size(0), name(""), dim(0), use_sdim_for_slice(false) { 00154 // this information changes with each constraint expression 00155 start = 0; 00156 stop = 0; 00157 stride = 1; 00158 c_size = size; 00159 } 00160 00161 dimension(unsigned long s, string n) : size(s), name(n), dim(0), use_sdim_for_slice(false) { 00162 start = 0; 00163 stop = size - 1; 00164 stride = 1; 00165 c_size = size; 00166 } 00167 00168 dimension(D4Dimension *d); 00169 #if 0 00170 dimension(D4Dimension *d) : dim(d), use_sdim_for_slice(true) { 00171 size = d->size(); 00172 name = d->name(); 00173 00174 start = 0; 00175 stop = size - 1; 00176 stride = 1; 00177 c_size = size; 00178 } 00179 #endif 00180 }; 00181 00182 D4Maps *d_maps; 00183 00184 private: 00185 std::vector<dimension> _shape; // list of dimensions (i.e., the shape) 00186 00187 void update_dimension_pointers(D4Dimensions *old_dims, D4Dimensions *new_dims); 00188 00189 friend class ArrayTest; 00190 friend class D4Group; 00191 00192 protected: 00193 void _duplicate(const Array &a); 00194 00195 unsigned int print_array(FILE *out, unsigned int index, 00196 unsigned int dims, unsigned int shape[]); 00197 00198 unsigned int print_array(ostream &out, unsigned int index, 00199 unsigned int dims, unsigned int shape[]); 00200 00201 public: 00207 typedef std::vector<dimension>::const_iterator Dim_citer ; 00214 typedef std::vector<dimension>::iterator Dim_iter ; 00215 00216 Array(const string &n, BaseType *v, bool is_dap4 = false); 00217 Array(const string &n, const string &d, BaseType *v, bool is_dap4 = false); 00218 Array(const Array &rhs); 00219 virtual ~Array(); 00220 00221 Array &operator=(const Array &rhs); 00222 virtual BaseType *ptr_duplicate(); 00223 00224 virtual BaseType *transform_to_dap4(D4Group *root, Constructor *container); 00225 00226 void add_var(BaseType *v, Part p = nil); 00227 void add_var_nocopy(BaseType *v, Part p = nil); 00228 00229 void append_dim(int size, const string &name = ""); 00230 void append_dim(D4Dimension *dim); 00231 void prepend_dim(int size, const string& name = ""); 00232 void prepend_dim(D4Dimension *dim); 00233 void clear_all_dims(); 00234 00235 virtual void add_constraint(Dim_iter i, int start, int stride, int stop); 00236 virtual void add_constraint(Dim_iter i, D4Dimension *dim); 00237 virtual void reset_constraint(); 00238 00239 virtual void clear_constraint(); // deprecated 00240 00241 virtual void update_length(int size = 0); // should be used internally only 00242 00243 Dim_iter dim_begin() ; 00244 Dim_iter dim_end() ; 00245 00246 virtual int dimension_size(Dim_iter i, bool constrained = false); 00247 virtual int dimension_start(Dim_iter i, bool constrained = false); 00248 virtual int dimension_stop(Dim_iter i, bool constrained = false); 00249 virtual int dimension_stride(Dim_iter i, bool constrained = false); 00250 virtual string dimension_name(Dim_iter i); 00251 virtual D4Dimension *dimension_D4dim(Dim_iter i); 00252 00253 virtual unsigned int dimensions(bool constrained = false); 00254 00255 virtual D4Maps *maps(); 00256 00257 virtual void print_dap4(XMLWriter &xml, bool constrained = false); 00258 00259 // These are all DAP2 output methods 00260 00261 virtual void print_decl(ostream &out, string space = " ", 00262 bool print_semi = true, 00263 bool constraint_info = false, 00264 bool constrained = false); 00265 00266 virtual void print_xml(ostream &out, string space = " ", 00267 bool constrained = false); 00268 00269 virtual void print_xml_writer(XMLWriter &xml, bool constrained = false); 00270 virtual void print_xml_writer_core(XMLWriter &out, bool constrained, string tag); 00271 virtual void print_as_map_xml_writer(XMLWriter &xml, bool constrained); 00272 00273 virtual void print_xml_core(FILE *out, string space, bool constrained, string tag); 00274 virtual void print_xml_core(ostream &out, string space, bool constrained, string tag); 00275 00276 // not used (?) 00277 virtual void print_as_map_xml(ostream &out, string space = " ", 00278 bool constrained = false); 00279 00280 virtual void print_val(ostream &out, string space = "", 00281 bool print_decl_p = true); 00282 00283 virtual void print_xml(FILE *out, string space = " ", 00284 bool constrained = false); 00285 virtual void print_as_map_xml(FILE *out, string space = " ", 00286 bool constrained = false); 00287 virtual void print_val(FILE *out, string space = "", 00288 bool print_decl_p = true); 00289 virtual void print_decl(FILE *out, string space = " ", 00290 bool print_semi = true, 00291 bool constraint_info = false, 00292 bool constrained = false); 00293 00294 virtual bool check_semantics(string &msg, bool all = false); 00295 00296 virtual void dump(ostream &strm) const ; 00297 }; 00298 00299 } // namespace libdap 00300 00301 #endif // _array_h