libdap++ Updated for version 3.8.2

Array.h

Go to the documentation of this file.
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 #define FILE_METHODS 1
00052 
00053 namespace libdap
00054 {
00055 
00056 const int DODS_MAX_ARRAY = DODS_INT_MAX;
00057 
00101 class Array: public Vector
00102 {
00103 public:
00114     struct dimension
00115     {
00116         int size;  
00117         string name;    
00118         int start;  
00119         int stop;  
00120         int stride;  
00121         int c_size;  
00122     };
00123 
00124 private:
00125     std::vector<dimension> _shape; // list of dimensions (i.e., the shape)
00126 
00127     friend class ArrayTest;
00128 
00129 protected:
00130     void _duplicate(const Array &a);
00131 
00132 #if FILE_METHODS
00133     unsigned int print_array(FILE *out, unsigned int index,
00134                              unsigned int dims, unsigned int shape[]);
00135 #endif
00136     unsigned int print_array(ostream &out, unsigned int index,
00137                              unsigned int dims, unsigned int shape[]);
00138 
00139 public:
00145     typedef std::vector<dimension>::const_iterator Dim_citer ;
00152     typedef std::vector<dimension>::iterator Dim_iter ;
00153 
00154     Array(const string &n, BaseType *v);
00155     Array(const string &n, const string &d, BaseType *v);
00156     Array(const Array &rhs);
00157     virtual ~Array();
00158 
00159     Array &operator=(const Array &rhs);
00160     virtual BaseType *ptr_duplicate();
00161 
00162     void add_var(BaseType *v, Part p = nil);
00163 
00164     void append_dim(int size, string name = "");
00165     void prepend_dim(int size, const string& name = "");
00166 
00167     virtual void add_constraint(Dim_iter i, int start, int stride, int stop);
00168     virtual void reset_constraint();
00169 
00170     virtual void clear_constraint();
00171 
00172     virtual void update_length(int size);
00173 
00174     Dim_iter dim_begin() ;
00175     Dim_iter dim_end() ;
00176 
00177     virtual int dimension_size(Dim_iter i, bool constrained = false);
00178     virtual int dimension_start(Dim_iter i, bool constrained = false);
00179     virtual int dimension_stop(Dim_iter i, bool constrained = false);
00180     virtual int dimension_stride(Dim_iter i, bool constrained = false);
00181     virtual string dimension_name(Dim_iter i);
00182 
00183     virtual unsigned int dimensions(bool constrained = false);
00184 
00185     virtual void print_decl(ostream &out, string space = "    ",
00186                             bool print_semi = true,
00187                             bool constraint_info = false,
00188                             bool constrained = false);
00189 
00190     virtual void print_xml(ostream &out, string space = "    ",
00191                            bool constrained = false);
00192 
00193 #if FILE_METHODS
00194     virtual void print_xml_core(FILE *out, string space, bool constrained, string tag);
00195 #endif
00196     virtual void print_xml_core(ostream &out, string space, bool constrained, string tag);
00197 
00198     // not used (?)
00199     virtual void print_as_map_xml(ostream &out, string space = "    ",
00200                                   bool constrained = false);
00201 
00202     virtual void print_val(ostream &out, string space = "",
00203                            bool print_decl_p = true);
00204 
00205 #if FILE_METHODS
00206     virtual void print_xml(FILE *out, string space = "    ",
00207                            bool constrained = false);
00208     virtual void print_as_map_xml(FILE *out, string space = "    ",
00209                                   bool constrained = false);
00210     virtual void print_val(FILE *out, string space = "",
00211                            bool print_decl_p = true);
00212     virtual void print_decl(FILE *out, string space = "    ",
00213                             bool print_semi = true,
00214                             bool constraint_info = false,
00215                             bool constrained = false);
00216 #endif
00217 
00218     virtual bool check_semantics(string &msg, bool all = false);
00219 
00220     virtual void dump(ostream &strm) const ;
00221 };
00222 
00223 } // namespace libdap
00224 
00225 #endif // _array_h