bes  Updated for version 3.20.6
NDimensionalArray.h
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
4 // Access Protocol.
5 
6 // Copyright (c) 2002,2003,2011,2012 OPeNDAP, Inc.
7 // Authors: Nathan Potter <ndp@opendap.org>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24 
25 #ifndef NDIMENSIONALARRAY_H_
26 #define NDIMENSIONALARRAY_H_
27 
28 #include "BESDebug.h"
29 
30 #include "Array.h"
31 
32 namespace libdap {
33 
34 static string NDimensionalArray_debug_key = "ugrid";
35 
40 private:
41 
43 
44  libdap::Type _dapType;
45 
46  std::vector<unsigned int> *_shape;
47  unsigned int _currentLastDimensionSlabIndex;
48 
49  long _totalValueCount; // Number of elements
50  unsigned int _sizeOfValue;
51  void *_storage;
52 
53  void allocateStorage(long numValues, libdap::Type dapType);
54  void confirmStorage();
55  void confirmType(Type dapType);
56  void confirmLastDimSize(unsigned int n);
57  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, void *values, unsigned int byteCount);
58 
59  string toString_worker(vector<unsigned int> *index);
60 
61 public:
62 
63  NDimensionalArray(libdap::Array *arrayTemplate);
64  NDimensionalArray(std::vector<unsigned int> *shape, libdap::Type dapType);
65 
66  virtual ~NDimensionalArray();
67 
68  dods_byte setValue(std::vector<unsigned int> *location, dods_byte value);
69  dods_int16 setValue(std::vector<unsigned int> *location, dods_int16 value);
70  dods_uint16 setValue(std::vector<unsigned int> *location, dods_uint16 value);
71  dods_int32 setValue(std::vector<unsigned int> *location, dods_int32 value);
72  dods_uint32 setValue(std::vector<unsigned int> *location, dods_uint32 value);
73  dods_float32 setValue(std::vector<unsigned int> *location, dods_float32 value);
74  dods_float64 setValue(std::vector<unsigned int> *location, dods_float64 value);
75 
76  static void retrieveLastDimHyperSlabLocationFromConstrainedArrray(libdap::Array *a, vector<unsigned int> *location);
77  static long computeConstrainedShape(libdap::Array *a, vector<unsigned int> *shape);
78  static long computeArraySizeFromShapeVector(vector<unsigned int> *shape);
79  static long getStorageIndex(vector<unsigned int> *shape, vector<unsigned int> *location);
80 
81  long elementCount()
82  {
83  return _totalValueCount;
84  }
85  unsigned int sizeOfElement()
86  {
87  return _sizeOfValue;
88  }
89 
90  void *relinquishStorage();
91 
92  void *getStorage()
93  {
94  return _storage;
95  }
96  void setAll(char val);
97 
99 
100  Type getTypeTemplate()
101  {
102  return _dapType;
103  }
104 
105  void getLastDimensionHyperSlab(std::vector<unsigned int> *location, void **slab, unsigned int *elementCount);
106  void getNextLastDimensionHyperSlab(void **slab);
107  void resetSlabIndex()
108  {
109  _currentLastDimensionSlabIndex = 0;
110  }
111  unsigned int getCurrentLastDimensionHyperSlab()
112  {
113  return _currentLastDimensionSlabIndex;
114  }
115  void setCurrentLastDimensionHyperSlab(unsigned int newIndex)
116  {
117  _currentLastDimensionSlabIndex = newIndex;
118  }
119 
120  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_byte *values, unsigned int numVal);
121  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_int16 *values, unsigned int numVal);
122  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_uint16 *values, unsigned int numVal);
123  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_int32 *values, unsigned int numVal);
124  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_uint32 *values, unsigned int numVal);
125  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_float32 *values, unsigned int numVal);
126  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_float64 *values, unsigned int numVal);
127 
128  libdap::Array *getArray(libdap::Array *templateArray);
129 
130  string toString();
131  static string vectorToIndices(vector<unsigned int> *v);
132 
133 };
134 //NdimensionalArray
135 
136 } /* namespace libdap */
137 #endif /* NDIMENSIONALARRAY_H_ */
libdap::NDimensionalArray::setAll
void setAll(char val)
Definition: NDimensionalArray.cc:653
libdap::NDimensionalArray::computeConstrainedShape
static long computeConstrainedShape(libdap::Array *a, vector< unsigned int > *shape)
Definition: NDimensionalArray.cc:131
libdap::NDimensionalArray
Definition: NDimensionalArray.h:39
Type
Type
Type of JSON value.
Definition: cmr_module/rapidjson/rapidjson.h:603
libdap
Definition: BESDapFunctionResponseCache.h:35
libdap::NDimensionalArray::setValue
dods_byte setValue(std::vector< unsigned int > *location, dods_byte value)
Definition: NDimensionalArray.cc:340
libdap::NDimensionalArray::getLastDimensionHyperSlab
void getLastDimensionHyperSlab(std::vector< unsigned int > *location, void **slab, unsigned int *elementCount)
Definition: NDimensionalArray.cc:461
libdap::NDimensionalArray::computeArraySizeFromShapeVector
static long computeArraySizeFromShapeVector(vector< unsigned int > *shape)
Definition: NDimensionalArray.cc:242
libdap::NDimensionalArray::relinquishStorage
void * relinquishStorage()
Definition: NDimensionalArray.cc:120
libdap::NDimensionalArray::getLastDimensionElementCount
long getLastDimensionElementCount()
Definition: NDimensionalArray.cc:663
libdap::NDimensionalArray::getStorageIndex
static long getStorageIndex(vector< unsigned int > *shape, vector< unsigned int > *location)
Definition: NDimensionalArray.cc:504