bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
Shape.h
1
2// This file is part of the "NcML Module" project, a BES module designed
3// to allow NcML files to be used to be used as a wrapper to add
4// AIS to existing datasets of any format.
5//
6// Copyright (c) 2009 OPeNDAP, Inc.
7// Author: Michael Johnson <m.johnson@opendap.org>
8//
9// For more information, please also see the main website: http://opendap.org/
10//
11// This library is free software; you can redistribute it and/or
12// modify it under the terms of the GNU Lesser General Public
13// License as published by the Free Software Foundation; either
14// version 2.1 of the License, or (at your option) any later version.
15//
16// This library is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19// Lesser General Public License for more details.
20//
21// You should have received a copy of the GNU Lesser General Public
22// License along with this library; if not, write to the Free Software
23// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24//
25// Please see the files COPYING and COPYRIGHT for more information on the GLPL.
26//
27// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
29
30#ifndef __NCML_MODULE__SHAPE_H__
31#define __NCML_MODULE__SHAPE_H__
32
33#include <iostream>
34#include <iterator>
35#include <libdap/Array.h>
36#include "NCMLDebug.h"
37#include <string>
38#include <vector>
39
40using libdap::Array;
41
42namespace ncml_module {
58class Shape {
59public:
60 // Indices into the space of the shape.
61 typedef std::vector<unsigned int> IndexTuple;
62
63public:
64 // Inner Classes
65
71 class IndexIterator: public std::iterator<std::forward_iterator_tag, IndexTuple> {
72 public:
74 IndexIterator(); // for uninitialized. Don't use it!
75 IndexIterator(const Shape& shape, bool isEnd = false);
76 IndexIterator(const IndexIterator& proto);
78 IndexIterator& operator=(const IndexIterator& rhs);
79 bool operator==(const IndexIterator& rhs) const;
80
81 inline bool operator!=(const IndexIterator& rhs) const
82 {
83 return (!((*this) == rhs));
84 }
85
86 inline IndexIterator& operator++() //prefix
87 {
88 advanceCurrent();
89 return *this;
90 }
91
92 inline IndexIterator operator++(int) // postfix...
93 {
94 // Copy it, this is why prefix increment is preferred in STL...
95 Shape::IndexIterator tmp(*this);
96 ++(*this);
97 return tmp;
98 }
99
100 // don't mutate the return, we use it to compute next element!
101 inline const Shape::IndexTuple& operator*()
102 {
103 NCML_ASSERT_MSG(!_end, "Can't reference end iterator!");
104 return _current;
105 }
106
107 private:
109 void advanceCurrent();
110
112 void setCurrentToStart();
113
114 private:
115 const Shape* _shape; // the shape of the space we are iterating on. It cannot change during an iteration!
116 IndexTuple _current; // the current point.
117 bool _end; // set to true when we reach the end since there's no other way to tell if we're at start or end.
118 }; // class IndexIterator
119
120public:
121 friend class IndexIterator;
122
123public:
125 Shape();
126 Shape(const Shape& proto);
128 Shape(const Array& copyDimsFrom);
129 ~Shape();
130 Shape& operator=(const Shape& rhs);
131
135 bool operator==(const Shape& rhs) const;
136
138 bool operator!=(const Shape& rhs) const
139 {
140 return !(*this == rhs);
141 }
142
144 bool isConstrained() const;
145
147 void setToUnconstrained();
148
149 inline unsigned int getNumDimensions() const
150 {
151 return _dims.size();
152 }
153
156 static bool areDimensionsEqual(const Array::dimension& lhs, const Array::dimension& rhs);
157
159 inline unsigned int getUnconstrainedSpaceSize() const
160 {
161 unsigned int size = 1;
162 for (unsigned int i = 0; i < _dims.size(); ++i) {
163 size *= _dims[i].size;
164 }
165 return size;
166 }
167
169 inline unsigned int getConstrainedSpaceSize() const
170 {
171 unsigned int c_size = 1;
172 for (unsigned int i = 0; i < _dims.size(); ++i) {
173 c_size *= _dims[i].c_size;
174 }
175 return c_size;
176 }
177
194 unsigned int getRowMajorIndex(const IndexTuple& indices, bool validate = true) const;
195
207
211
213 std::string toString() const;
214
216 void print(std::ostream& strm) const;
217
219 static void printDimension(std::ostream& strm, const Array::dimension& dim);
220
224 bool validateIndices(const IndexTuple& indices) const;
225
226private:
227 // Methods
228
229private:
230 std::vector<Array::dimension> _dims;
231
232};
233// class Shape
234
235}// namespace ncml_module
236
237inline std::ostream &
238operator<<(std::ostream &strm, const ncml_module::Shape& shape)
239{
240 shape.print(strm);
241 return strm;
242}
243#endif /* __NCML_MODULE__SHAPE_H__ */
A wrapper class for a vector of Array::dimension structs.
Definition Shape.h:58
Shape::IndexIterator endSpaceEnumeration() const
Definition Shape.cc:161
void setToUnconstrained()
Definition Shape.cc:109
unsigned int getConstrainedSpaceSize() const
Definition Shape.h:169
std::string toString() const
Definition Shape.cc:166
bool operator!=(const Shape &rhs) const
Definition Shape.h:138
static bool areDimensionsEqual(const Array::dimension &lhs, const Array::dimension &rhs)
Definition Shape.cc:120
bool validateIndices(const IndexTuple &indices) const
Definition Shape.cc:194
bool isConstrained() const
Definition Shape.cc:96
unsigned int getRowMajorIndex(const IndexTuple &indices, bool validate=true) const
Definition Shape.cc:141
Shape::IndexIterator beginSpaceEnumeration() const
Definition Shape.cc:156
bool operator==(const Shape &rhs) const
Definition Shape.cc:75
unsigned int getUnconstrainedSpaceSize() const
Definition Shape.h:159
static void printDimension(std::ostream &strm, const Array::dimension &dim)
Definition Shape.cc:183
void print(std::ostream &strm) const
Definition Shape.cc:173
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...