Array.h
// -*- mode: c++; c-basic-offset:4 -*-
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.
// Copyright (c) 2002,2003 OPeNDAP, Inc.
// Author: James Gallagher <jgallagher@opendap.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
// (c) COPYRIGHT URI/MIT 1994-1999
// Please read the full copyright statement in the file COPYRIGHT_URI.
//
// Authors:
// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
// Class for array variables. The dimensions of the array are stored in the
// list SHAPE.
//
// jhrg 9/6/94
#ifndef _array_h
#define _array_h 1
#include <string>
#include <vector>
#ifndef _dods_limits_h
#include "dods-limits.h"
#endif
#ifndef _vector_h
#include "Vector.h"
#endif
//#include "D4Dimensions.h"
namespace libdap
{
class D4Group;
class D4Maps;
class XMLWriter;
class D4Dimension;
class D4Dimensions;
const int DODS_MAX_ARRAY = DODS_INT_MAX;
class Array: public Vector
{
public:
struct dimension
{
// In DAP2, the name and size of a dimension is stored here, along
// with information about any constraint. In DAP4, either the name
// and size are stored in the two fields below _or_ the name and
// size information comes from a dimension object defined in a
// group that is referenced by the 'dim' pointer. Do not free this
// pointer; it is shared between the array and the Group where the
// Dimension is defined. To keep Array manageable to implement, size
// will be set here using the value from 'dim' if it is not null.
int size;
string name;
D4Dimension *dim;
// when a DMR is printed for a data response, if an array uses shared
// dimensions and those sdims have been sliced, make sure to use those
// and get the syntax correct. That's what this field does - in every
// case the array records the sizes of its dimensions and their slices
// regardless of whether they were provided explicitly in a CE or inherited
// from a sliced sdim.
bool use_sdim_for_slice;
int start;
int stop;
int stride;
int c_size;
dimension() : size(0), name(""), dim(0), use_sdim_for_slice(false) {
// this information changes with each constraint expression
start = 0;
stop = 0;
stride = 1;
c_size = size;
}
dimension(unsigned long s, string n) : size(s), name(n), dim(0), use_sdim_for_slice(false) {
start = 0;
stop = size - 1;
stride = 1;
c_size = size;
}
dimension(D4Dimension *d);
};
D4Maps *d_maps;
private:
std::vector<dimension> _shape; // list of dimensions (i.e., the shape)
void update_dimension_pointers(D4Dimensions *old_dims, D4Dimensions *new_dims);
friend class ArrayTest;
friend class D4Group;
bool is_dap2_grid();
protected:
void _duplicate(const Array &a);
unsigned int print_array(FILE *out, unsigned int index,
unsigned int dims, unsigned int shape[]);
unsigned int print_array(ostream &out, unsigned int index,
unsigned int dims, unsigned int shape[]);
public:
typedef std::vector<dimension>::const_iterator Dim_citer;
typedef std::vector<dimension>::iterator Dim_iter;
Array(const string &n, BaseType *v, bool is_dap4 = false);
Array(const string &n, const string &d, BaseType *v, bool is_dap4 = false);
Array(const Array &rhs);
virtual ~Array();
Array &operator=(const Array &rhs);
virtual BaseType *ptr_duplicate();
virtual void transform_to_dap4(D4Group *root, Constructor *container);
virtual std::vector<BaseType *> *transform_to_dap2(AttrTable *parent_attr_table);
void add_var(BaseType *v, Part p = nil);
void add_var_nocopy(BaseType *v, Part p = nil);
void append_dim(int size, const string &name = "");
void append_dim(D4Dimension *dim);
void prepend_dim(int size, const string& name = "");
void prepend_dim(D4Dimension *dim);
void clear_all_dims();
void rename_dim(const string &oldName = "", const string &newName = "");
virtual void add_constraint(Dim_iter i, int start, int stride, int stop);
virtual void add_constraint(Dim_iter i, D4Dimension *dim);
virtual void reset_constraint();
virtual void clear_constraint(); // deprecated
virtual void update_length(int size = 0); // should be used internally only
Dim_iter dim_begin() ;
Dim_iter dim_end() ;
virtual int dimension_size(Dim_iter i, bool constrained = false);
virtual int dimension_start(Dim_iter i, bool constrained = false);
virtual int dimension_stop(Dim_iter i, bool constrained = false);
virtual int dimension_stride(Dim_iter i, bool constrained = false);
virtual string dimension_name(Dim_iter i);
virtual D4Dimension *dimension_D4dim(Dim_iter i);
virtual unsigned int dimensions(bool constrained = false);
virtual D4Maps *maps();
virtual void print_dap4(XMLWriter &xml, bool constrained = false);
// These are all DAP2 output methods
virtual void print_decl(ostream &out, string space = " ",
bool print_semi = true,
bool constraint_info = false,
bool constrained = false);
virtual void print_xml(ostream &out, string space = " ",
bool constrained = false);
virtual void print_xml_writer(XMLWriter &xml, bool constrained = false);
virtual void print_xml_writer_core(XMLWriter &out, bool constrained, string tag);
virtual void print_as_map_xml_writer(XMLWriter &xml, bool constrained);
virtual void print_xml_core(FILE *out, string space, bool constrained, string tag);
virtual void print_xml_core(ostream &out, string space, bool constrained, string tag);
// not used (?)
virtual void print_as_map_xml(ostream &out, string space = " ",
bool constrained = false);
virtual void print_val(ostream &out, string space = "",
bool print_decl_p = true);
virtual void print_xml(FILE *out, string space = " ",
bool constrained = false);
virtual void print_as_map_xml(FILE *out, string space = " ",
bool constrained = false);
virtual void print_val(FILE *out, string space = "",
bool print_decl_p = true);
virtual void print_decl(FILE *out, string space = " ",
bool print_semi = true,
bool constraint_info = false,
bool constrained = false);
virtual bool check_semantics(string &msg, bool all = false);
virtual void dump(ostream &strm) const ;
};
} // namespace libdap
#endif // _array_h
libdap::Array
A multidimensional array of identical data types.
Definition: Array.h:113
libdap::Array::dimension_start
virtual int dimension_start(Dim_iter i, bool constrained=false)
Return the start index of a dimension.
Definition: Array.cc:765
libdap::Array::clear_constraint
virtual void clear_constraint()
Clears the projection; add each projected dimension explicitly using add_constraint.
Definition: Array.cc:616
libdap::Array::dump
virtual void dump(ostream &strm) const
dumps information about this object
Definition: Array.cc:1325
libdap::Array::transform_to_dap2
virtual std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table)
Transforms this instance of a D4Array into the corresponding DAP2 object.
Definition: Array.cc:302
libdap::Array::dim_end
Dim_iter dim_end()
Definition: Array.cc:696
libdap::Array::transform_to_dap4
virtual void transform_to_dap4(D4Group *root, Constructor *container)
DAP2 to DAP4 transform.
Definition: Array.cc:192
libdap::Array::ptr_duplicate
virtual BaseType * ptr_duplicate()
Definition: Array.cc:175
libdap::Array::print_xml
virtual void print_xml(ostream &out, string space=" ", bool constrained=false)
Definition: Array.cc:1077
libdap::Array::print_array
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:1198
libdap::Array::dimension_stop
virtual int dimension_stop(Dim_iter i, bool constrained=false)
Return the stop index of the constraint.
Definition: Array.cc:788
libdap::Array::update_length
virtual void update_length(int size=0)
Definition: Array.cc:103
libdap::Array::add_constraint
virtual void add_constraint(Dim_iter i, int start, int stride, int stop)
Adds a constraint to an Array dimension.
Definition: Array.cc:647
libdap::Array::dimension_name
virtual string dimension_name(Dim_iter i)
Returns the name of the specified dimension.
Definition: Array.cc:827
libdap::Array::print_decl
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:1039
libdap::Array::append_dim
void append_dim(int size, const string &name="")
Add a dimension of a given size.
Definition: Array.cc:522
libdap::Array::Dim_iter
std::vector< dimension >::iterator Dim_iter
Definition: Array.h:206
libdap::Array::rename_dim
void rename_dim(const string &oldName="", const string &newName="")
Renames dimension.
Definition: Array.cc:574
libdap::Array::dimension_size
virtual int dimension_size(Dim_iter i, bool constrained=false)
Returns the size of the dimension.
Definition: Array.cc:733
libdap::Array::clear_all_dims
void clear_all_dims()
Definition: Array.cc:564
libdap::Array::print_dap4
virtual void print_dap4(XMLWriter &xml, bool constrained=false)
Print the DAP4 representation of an array.
Definition: Array.cc:958
libdap::Array::check_semantics
virtual bool check_semantics(string &msg, bool all=false)
Check semantic features of the Array.
Definition: Array.cc:1308
libdap::Array::Dim_citer
std::vector< dimension >::const_iterator Dim_citer
Definition: Array.h:198
libdap::Array::print_as_map_xml
virtual void print_as_map_xml(ostream &out, string space=" ", bool constrained=false)
Definition: Array.cc:1097
libdap::Array::reset_constraint
virtual void reset_constraint()
Reset constraint to select entire array.
Definition: Array.cc:593
libdap::Array::add_var
void add_var(BaseType *v, Part p=nil)
Add the BaseType pointer to this constructor type instance.
Definition: Array.cc:470
libdap::Array::~Array
virtual ~Array()
The Array destructor.
Definition: Array.cc:169
libdap::Array::print_xml_core
virtual void print_xml_core(FILE *out, string space, bool constrained, string tag)
Definition: Array.cc:1107
libdap::Array::prepend_dim
void prepend_dim(int size, const string &name="")
Definition: Array.cc:543
libdap::Array::dim_begin
Dim_iter dim_begin()
Definition: Array.cc:690
libdap::Array::Array
Array(const string &n, BaseType *v, bool is_dap4=false)
Array constructor.
Definition: Array.cc:136
libdap::Array::print_xml_writer
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
Definition: Array.cc:1124
libdap::Array::print_val
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition: Array.cc:1271
libdap::Array::dimensions
virtual unsigned int dimensions(bool constrained=false)
Return the total number of dimensions in the array.
Definition: Array.cc:711
libdap::Array::dimension_stride
virtual int dimension_stride(Dim_iter i, bool constrained=false)
Returns the stride value of the constraint.
Definition: Array.cc:812
libdap::AttrTable
Contains the attributes for a dataset.
Definition: AttrTable.h:143
libdap::BaseType
The basic data type for the DODS DAP types.
Definition: BaseType.h:118
libdap::BaseType::name
virtual string name() const
Returns the name of the class instance.
Definition: BaseType.cc:320
libdap::Constructor
Definition: Constructor.h:44
libdap::D4Dimension
Definition: D4Dimensions.h:41
libdap::D4Group
Definition: D4Group.h:44
libdap::D4Maps
Definition: D4Maps.h:84
libdap::Vector
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:81
libdap::XMLWriter
Definition: XMLWriter.h:39
libdap
top level DAP object to house generic methods
Definition: AlarmHandler.h:36
libdap::Part
Part
Names the parts of multi-section constructor data types.
Definition: Type.h:48
libdap::Array::dimension
Definition: Array.h:126
libdap::Array::dimension::stride
int stride
The constraint stride.
Definition: Array.h:150
libdap::Array::dimension::name
string name
The name of this dimension.
Definition: Array.h:136
libdap::Array::dimension::dim
D4Dimension * dim
If not null, a weak pointer to the D4Dimension.
Definition: Array.h:138
libdap::Array::dimension::use_sdim_for_slice
bool use_sdim_for_slice
Used to control printing the DMR in data responses.
Definition: Array.h:146
libdap::Array::dimension::start
int start
The constraint start index.
Definition: Array.h:148
libdap::Array::dimension::size
int size
The unconstrained dimension size.
Definition: Array.h:135
libdap::Array::dimension::stop
int stop
The constraint end index.
Definition: Array.h:149
libdap::Array::dimension::c_size
int c_size
Size of dimension once constrained.
Definition: Array.h:151