bes  Updated for version 3.20.10
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 <libdap/Array.h>
29 
30 namespace libdap {
31 
32 static string NDimensionalArray_debug_key = "ugrid";
33 
38 private:
39 
41 
42  libdap::Type _dapType;
43 
44  std::vector<unsigned int> *_shape;
45  unsigned int _currentLastDimensionSlabIndex;
46 
47  long _totalValueCount; // Number of elements
48  unsigned int _sizeOfValue;
49  void *_storage;
50 
51  void allocateStorage(long numValues, libdap::Type dapType);
52  void confirmStorage();
53  void confirmType(Type dapType);
54  void confirmLastDimSize(unsigned int n);
55  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, void *values, unsigned int byteCount);
56 
57  string toString_worker(vector<unsigned int> *index);
58 
59 public:
60 
61  NDimensionalArray(libdap::Array *arrayTemplate);
62  NDimensionalArray(std::vector<unsigned int> *shape, libdap::Type dapType);
63 
64  virtual ~NDimensionalArray();
65 
66  dods_byte setValue(std::vector<unsigned int> *location, dods_byte value);
67  dods_int16 setValue(std::vector<unsigned int> *location, dods_int16 value);
68  dods_uint16 setValue(std::vector<unsigned int> *location, dods_uint16 value);
69  dods_int32 setValue(std::vector<unsigned int> *location, dods_int32 value);
70  dods_uint32 setValue(std::vector<unsigned int> *location, dods_uint32 value);
71  dods_float32 setValue(std::vector<unsigned int> *location, dods_float32 value);
72  dods_float64 setValue(std::vector<unsigned int> *location, dods_float64 value);
73 
74  static void retrieveLastDimHyperSlabLocationFromConstrainedArrray(libdap::Array *a, vector<unsigned int> *location);
75  static long computeConstrainedShape(libdap::Array *a, vector<unsigned int> *shape);
76  static long computeArraySizeFromShapeVector(vector<unsigned int> *shape);
77  static long getStorageIndex(vector<unsigned int> *shape, vector<unsigned int> *location);
78 
79  long elementCount()
80  {
81  return _totalValueCount;
82  }
83  unsigned int sizeOfElement()
84  {
85  return _sizeOfValue;
86  }
87 
88  void *relinquishStorage();
89 
90  void *getStorage()
91  {
92  return _storage;
93  }
94  void setAll(char val);
95 
97 
98  Type getTypeTemplate()
99  {
100  return _dapType;
101  }
102 
103  void getLastDimensionHyperSlab(std::vector<unsigned int> *location, void **slab, unsigned int *elementCount);
104  void getNextLastDimensionHyperSlab(void **slab);
105  void resetSlabIndex()
106  {
107  _currentLastDimensionSlabIndex = 0;
108  }
109  unsigned int getCurrentLastDimensionHyperSlab()
110  {
111  return _currentLastDimensionSlabIndex;
112  }
113  void setCurrentLastDimensionHyperSlab(unsigned int newIndex)
114  {
115  _currentLastDimensionSlabIndex = newIndex;
116  }
117 
118  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_byte *values, unsigned int numVal);
119  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_int16 *values, unsigned int numVal);
120  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_uint16 *values, unsigned int numVal);
121  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_int32 *values, unsigned int numVal);
122  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_uint32 *values, unsigned int numVal);
123  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_float32 *values, unsigned int numVal);
124  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_float64 *values, unsigned int numVal);
125 
126  libdap::Array *getArray(libdap::Array *templateArray);
127 
128  string toString();
129  static string vectorToIndices(vector<unsigned int> *v);
130 
131 };
132 //NdimensionalArray
133 
134 } /* namespace libdap */
135 #endif /* NDIMENSIONALARRAY_H_ */
void getLastDimensionHyperSlab(std::vector< unsigned int > *location, void **slab, unsigned int *elementCount)
static long getStorageIndex(vector< unsigned int > *shape, vector< unsigned int > *location)
static long computeConstrainedShape(libdap::Array *a, vector< unsigned int > *shape)
static long computeArraySizeFromShapeVector(vector< unsigned int > *shape)
dods_byte setValue(std::vector< unsigned int > *location, dods_byte value)
Type
Type of JSON value.
Definition: rapidjson.h:664