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 #ifndef XMLWRITER_H_
00052 #include "XMLWriter.h"
00053 #endif
00054 
00055 #define FILE_METHODS 1
00056 
00057 namespace libdap
00058 {
00059 
00060 const int DODS_MAX_ARRAY = DODS_INT_MAX;
00061 
00105 class Array: public Vector
00106 {
00107 public:
00118     struct dimension
00119     {
00120         int size;  
00121         string name;    
00122         int start;  
00123         int stop;  
00124         int stride;  
00125         int c_size;  
00126     };
00127 
00128 private:
00129     std::vector<dimension> _shape; // list of dimensions (i.e., the shape)
00130 
00131     friend class ArrayTest;
00132 
00133 protected:
00134     void _duplicate(const Array &a);
00135 
00136 #if FILE_METHODS
00137     unsigned int print_array(FILE *out, unsigned int index,
00138                              unsigned int dims, unsigned int shape[]);
00139 #endif
00140     unsigned int print_array(ostream &out, unsigned int index,
00141                              unsigned int dims, unsigned int shape[]);
00142 
00143 public:
00149     typedef std::vector<dimension>::const_iterator Dim_citer ;
00156     typedef std::vector<dimension>::iterator Dim_iter ;
00157 
00158     Array(const string &n, BaseType *v);
00159     Array(const string &n, const string &d, BaseType *v);
00160     Array(const Array &rhs);
00161     virtual ~Array();
00162 
00163     Array &operator=(const Array &rhs);
00164     virtual BaseType *ptr_duplicate();
00165 
00166     void add_var(BaseType *v, Part p = nil);
00167 
00168     void append_dim(int size, string name = "");
00169     void prepend_dim(int size, const string& name = "");
00170 
00171     virtual void add_constraint(Dim_iter i, int start, int stride, int stop);
00172     virtual void reset_constraint();
00173 
00174     virtual void clear_constraint();
00175 
00176     virtual void update_length(int size);
00177     virtual unsigned int width(bool constrained = true);
00178 
00179     Dim_iter dim_begin() ;
00180     Dim_iter dim_end() ;
00181 
00182     virtual int dimension_size(Dim_iter i, bool constrained = false);
00183     virtual int dimension_start(Dim_iter i, bool constrained = false);
00184     virtual int dimension_stop(Dim_iter i, bool constrained = false);
00185     virtual int dimension_stride(Dim_iter i, bool constrained = false);
00186     virtual string dimension_name(Dim_iter i);
00187 
00188     virtual unsigned int dimensions(bool constrained = false);
00189 
00190     virtual void print_decl(ostream &out, string space = "    ",
00191                             bool print_semi = true,
00192                             bool constraint_info = false,
00193                             bool constrained = false);
00194 
00195     virtual void print_xml(ostream &out, string space = "    ",
00196                            bool constrained = false);
00197 
00198     virtual void print_xml_writer(XMLWriter &xml, bool constrained = false);
00199     virtual void print_xml_writer_core(XMLWriter &out, bool constrained, string tag);
00200     virtual void print_as_map_xml_writer(XMLWriter &xml, bool constrained);
00201 
00202 #if FILE_METHODS
00203     virtual void print_xml_core(FILE *out, string space, bool constrained, string tag);
00204 #endif
00205     virtual void print_xml_core(ostream &out, string space, bool constrained, string tag);
00206 
00207     // not used (?)
00208     virtual void print_as_map_xml(ostream &out, string space = "    ",
00209                                   bool constrained = false);
00210 
00211     virtual void print_val(ostream &out, string space = "",
00212                            bool print_decl_p = true);
00213 
00214 #if FILE_METHODS
00215     virtual void print_xml(FILE *out, string space = "    ",
00216                            bool constrained = false);
00217     virtual void print_as_map_xml(FILE *out, string space = "    ",
00218                                   bool constrained = false);
00219     virtual void print_val(FILE *out, string space = "",
00220                            bool print_decl_p = true);
00221     virtual void print_decl(FILE *out, string space = "    ",
00222                             bool print_semi = true,
00223                             bool constraint_info = false,
00224                             bool constrained = false);
00225 #endif
00226 
00227     virtual bool check_semantics(string &msg, bool all = false);
00228 
00229     virtual void dump(ostream &strm) const ;
00230 };
00231 
00232 } // namespace libdap
00233 
00234 #endif // _array_h