OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
NDimensionalArray.h
Go to the documentation of this file.
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 
26 
27 #ifndef NDIMENSIONALARRAY_H_
28 #define NDIMENSIONALARRAY_H_
29 
30 #include "BESDebug.h"
31 
32 #include "Array.h"
33 
34 
35 
36 namespace libdap {
37 
38 static string NDimensionalArray_debug_key = "ugrid";
39 
44 private:
45 
47 
48  libdap::Type _dapType;
49 
50  std::vector<unsigned int> *_shape;
51  unsigned int _currentLastDimensionSlabIndex;
52 
53  long _totalValueCount; // Number of elements
54  unsigned int _sizeOfValue;
55  void *_storage;
56 
57  void allocateStorage(long numValues, libdap::Type dapType);
58  void confirmStorage();
59  void confirmType(Type dapType);
60  void confirmLastDimSize(unsigned int n);
61  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, void *values, unsigned int byteCount);
62 
63  string toString_worker(vector<unsigned int> *index);
64 
65 public:
66 
67  NDimensionalArray(libdap::Array *arrayTemplate);
68  NDimensionalArray(std::vector<unsigned int> *shape, libdap::Type dapType);
69 
70  virtual ~NDimensionalArray();
71 
72  dods_byte setValue(std::vector<unsigned int> *location, dods_byte value);
73  dods_int16 setValue(std::vector<unsigned int> *location, dods_int16 value);
74  dods_uint16 setValue(std::vector<unsigned int> *location, dods_uint16 value);
75  dods_int32 setValue(std::vector<unsigned int> *location, dods_int32 value);
76  dods_uint32 setValue(std::vector<unsigned int> *location, dods_uint32 value);
77  dods_float32 setValue(std::vector<unsigned int> *location, dods_float32 value);
78  dods_float64 setValue(std::vector<unsigned int> *location, dods_float64 value);
79 
80  static void retrieveLastDimHyperSlabLocationFromConstrainedArrray(libdap::Array *a, vector<unsigned int> *location );
81  static long computeConstrainedShape(libdap::Array *a, vector<unsigned int> *shape );
82  static long computeArraySizeFromShapeVector(vector<unsigned int> *shape );
83  static long getStorageIndex(vector<unsigned int> *shape, vector<unsigned int> *location);
84 
85  long elementCount() { return _totalValueCount; }
86  unsigned int sizeOfElement() { return _sizeOfValue; }
87 
88  void *relinquishStorage();
89 
90  void *getStorage() { return _storage; }
91  void setAll(char val);
92 
94 
95 
96  Type getTypeTemplate(){ return _dapType; }
97 
98  void getLastDimensionHyperSlab(std::vector<unsigned int> *location,void **slab, unsigned int *elementCount);
99  void getNextLastDimensionHyperSlab(void **slab);
100  void resetSlabIndex(){ _currentLastDimensionSlabIndex = 0;}
101  unsigned int getCurrentLastDimensionHyperSlab(){ return _currentLastDimensionSlabIndex;}
102  void setCurrentLastDimensionHyperSlab(unsigned int newIndex){ _currentLastDimensionSlabIndex = newIndex;}
103 
104  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_byte *values, unsigned int numVal);
105  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_int16 *values, unsigned int numVal);
106  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_uint16 *values, unsigned int numVal);
107  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_int32 *values, unsigned int numVal);
108  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_uint32 *values, unsigned int numVal);
109  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_float32 *values, unsigned int numVal);
110  void setLastDimensionHyperSlab(std::vector<unsigned int> *location, dods_float64 *values, unsigned int numVal);
111 
112  libdap::Array *getArray(libdap::Array *templateArray);
113 
114  string toString();
115  static string vectorToIndices(vector<unsigned int> *v);
116 
117 }; //NdimensionalArray
118 
119 } /* namespace libdap */
120 #endif /* NDIMENSIONALARRAY_H_ */
libdap::Array * getArray(libdap::Array *templateArray)
unsigned int getCurrentLastDimensionHyperSlab()
void * relinquishStorage()
Returns a pointer to the underlying storage for the NDimensionalArray.
static long computeArraySizeFromShapeVector(vector< unsigned int > *shape)
Computes the total number of elements of the n-dimensional array described by the shape vector...
static class NCMLUtil overview
static void retrieveLastDimHyperSlabLocationFromConstrainedArrray(libdap::Array *a, vector< unsigned int > *location)
long getLastDimensionElementCount()
Returns the size, in elements, of the last dimension.
void setAll(char val)
Uses 'memset' to set ALL of the values in the NDimensionalArray to the passed char value...
static long getStorageIndex(vector< unsigned int > *shape, vector< unsigned int > *location)
Computes the element index in the underlying one dimensional array for the passed location based on a...
static string vectorToIndices(vector< unsigned int > *v)
static long computeConstrainedShape(libdap::Array *a, vector< unsigned int > *shape)
Computes and returns (via the returned value parameter 'shape') the constrained shape of the libdap::...
void getNextLastDimensionHyperSlab(void **slab)
dods_byte setValue(std::vector< unsigned int > *location, dods_byte value)
Sets the value of the array at the location specified by the passed location vector.
void setCurrentLastDimensionHyperSlab(unsigned int newIndex)
void getLastDimensionHyperSlab(std::vector< unsigned int > *location, void **slab, unsigned int *elementCount)
The return value parameters slab and elementCount are used to return a pointer to the first element o...