29 #ifndef __NCML_MODULE__NCMLARRAY_H__ 30 #define __NCML_MODULE__NCMLARRAY_H__ 32 #include <dods-datatypes.h> 38 #include "NCMLBaseArray.h" 39 #include "NCMLDebug.h" 47 using libdap::dods_byte;
48 using libdap::dods_int16;
49 using libdap::dods_uint16;
50 using libdap::dods_int32;
51 using libdap::dods_uint32;
52 using libdap::dods_float32;
53 using libdap::dods_float64;
108 copyLocalRepFrom(proto);
125 NCMLBaseArray::operator=(rhs);
128 copyLocalRepFrom(rhs);
149 VALID_PTR(from.var());
155 set_attr_table(from.get_attr_table());
157 add_var_nocopy(from.var()->ptr_duplicate());
160 Array::Dim_iter endIt = from.dim_end();
162 for (it = from.dim_begin(); it != endIt; ++it) {
163 Array::dimension& dim = *it;
164 append_dim(dim.size, dim.name);
169 _allValues =
new std::vector<T>(from.length());
170 NCML_ASSERT(_allValues->size() == static_cast<unsigned int>(from.length()));
173 T* pFirst = &((*_allValues)[0]);
174 from.buf2val(reinterpret_cast<void**>(&pFirst));
189 #define NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(arrayValue, sz) \ 190 if (typeid(arrayValue) != typeid(T*)) \ 192 THROW_NCML_INTERNAL_ERROR("NCMLArray<T>::set_value(): got wrong type of value array, doesn't match type T!"); \ 194 bool ret = Vector::set_value((arrayValue), (sz)); \ 195 cacheSuperclassStateIfNeeded(); \ 198 #define NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(vecValue, sz) \ 199 if (typeid(vecValue) != typeid(vector<T>&)) \ 201 THROW_NCML_INTERNAL_ERROR("NCMLArray<T>::setValue(): got wrong type of value vector, doesn't match type T!"); \ 203 bool ret = Vector::set_value((vecValue), (sz)); \ 204 cacheSuperclassStateIfNeeded(); \ 207 virtual bool set_value(dods_byte *val,
int sz)
209 NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(val, sz);
212 virtual bool set_value(vector<dods_byte> &val,
int sz)
214 NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(val, sz);
217 virtual bool set_value(dods_int16 *val,
int sz)
219 NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(val, sz);
222 virtual bool set_value(vector<dods_int16> &val,
int sz)
224 NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(val, sz);
227 virtual bool set_value(dods_uint16 *val,
int sz)
229 NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(val, sz);
232 virtual bool set_value(vector<dods_uint16> &val,
int sz)
234 NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(val, sz);
237 virtual bool set_value(dods_int32 *val,
int sz)
239 NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(val, sz);
242 virtual bool set_value(vector<dods_int32> &val,
int sz)
244 NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(val, sz);
247 virtual bool set_value(dods_uint32 *val,
int sz)
249 NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(val, sz);
252 virtual bool set_value(vector<dods_uint32> &val,
int sz)
254 NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(val, sz);
257 virtual bool set_value(dods_float32 *val,
int sz)
259 NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(val, sz);
262 virtual bool set_value(vector<dods_float32> &val,
int sz)
264 NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(val, sz);
267 virtual bool set_value(dods_float64 *val,
int sz)
269 NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(val, sz);
272 virtual bool set_value(vector<dods_float64> &val,
int sz)
274 NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(val, sz);
277 virtual bool set_value(
string *val,
int sz)
279 NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(val, sz);
282 virtual bool set_value(vector<string> &val,
int sz)
284 NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(val, sz);
287 #undef NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER 288 #undef NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER 304 if (get_value_capacity() == 0) {
305 BESDEBUG(
"ncml",
"cacheValuesIfNeeded: the superclass Vector has no data so not copying...");
312 "NCMLArray<T>:: we don't have unconstrained values cached, caching from Vector now..." << endl);
317 oss <<
"NCMLArray expected superclass Vector length() to be the same as unconstrained space size, but it wasn't!";
318 oss <<
"length(): " << length() <<
"' spaceSize: " << spaceSize;
319 NCML_ASSERT_MSG(static_cast<unsigned int>(length()) == spaceSize, oss.str());
321 NCML_ASSERT_MSG(static_cast<unsigned int>(length()) == spaceSize,
322 "NCMLArray expected superclass Vector length() to be the same as unconstrained space size, but it wasn't!");
325 _allValues =
new vector<T>(spaceSize);
326 NCML_ASSERT(_allValues->size() == spaceSize);
329 T* pFirstElt = &((*_allValues)[0]);
331 unsigned int stored = buf2val(reinterpret_cast<void**>(&pFirstElt));
333 NCML_ASSERT((stored /
sizeof(T)) == spaceSize);
350 BESDEBUG(
"ncml",
"NCMLArray<T>::createAndSetConstrainedValueBuffer() called!" << endl);
354 const bool validateBounds =
false;
356 const bool validateBounds =
true;
360 VALID_PTR(_noConstraints);
361 VALID_PTR(_allValues);
364 unsigned int numVals = length();
366 values.reserve(numVals);
372 unsigned int count = 0;
375 values.push_back((*_allValues)[_noConstraints->
getRowMajorIndex(*it, validateBounds)]);
379 if (count != static_cast<unsigned int>(length())) {
381 msg <<
"While adding points to hyperslab buffer we got differing number of points " 382 "from Shape space enumeration as expected from the constraints! " 383 "Shape::IndexIterator produced " << count <<
" points but we expected " << length();
384 THROW_NCML_INTERNAL_ERROR(msg.str());
389 msg <<
"While adding points to hyperslab buffer we got differing number of points " 390 "from Shape space enumeration as expected from the shape.getConstrainedSpaceSize()! " 391 "Shape::IndexIterator produced " << count <<
" points but we expected " 393 THROW_NCML_INTERNAL_ERROR(msg.str());
398 val2buf(static_cast<void*>(&(values[0])),
true);
409 if (&proto ==
this) {
417 if (proto._allValues) {
418 _allValues =
new vector<T>(*(proto._allValues));
423 void destroy() throw ()
433 std::vector<T>* _allValues;
virtual bool isDataCached() const
virtual void createAndSetConstrainedValueBuffer()
unsigned int getUnconstrainedSpaceSize() const
A parameterized subclass of libdap::Array that allows us to apply constraints on NcML-specified data ...
virtual Shape getSuperShape() const
virtual void cacheValuesIfNeeded()
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...
unsigned int getConstrainedSpaceSize() const
virtual void copyDataFrom(libdap::Array &from)
unsigned int getRowMajorIndex(const IndexTuple &indices, bool validate=true) const
Shape::IndexIterator endSpaceEnumeration() const
A wrapper class for a vector of Array::dimension structs.
virtual NCMLArray< T > * ptr_duplicate()
Shape::IndexIterator beginSpaceEnumeration() const