86class NCMLArray:
public NCMLBaseArray {
93 NCMLBaseArray(
""), _allValues(0)
97 explicit NCMLArray(
const string& name) :
98 NCMLBaseArray(name), _allValues(0)
102 explicit NCMLArray(
const NCMLArray<T>& proto) :
103 NCMLBaseArray(proto), _allValues(0)
105 copyLocalRepFrom(proto);
122 NCMLBaseArray::operator=(rhs);
125 copyLocalRepFrom(rhs);
133 return new NCMLArray(*
this);
146 VALID_PTR(from.var());
152 set_attr_table(from.get_attr_table());
154 add_var_nocopy(from.var()->ptr_duplicate());
157 Array::Dim_iter endIt = from.dim_end();
159 for (it = from.dim_begin(); it != endIt; ++it) {
160 Array::dimension& dim = *it;
161 append_dim(dim.size, dim.name);
166 _allValues =
new std::vector<T>(from.length());
167 NCML_ASSERT(_allValues->size() ==
static_cast<unsigned int>(from.length()));
170 T* pFirst = &((*_allValues)[0]);
171 from.buf2val(
reinterpret_cast<void**
>(&pFirst));
186#define NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(arrayValue, sz) \
187 if (typeid(arrayValue) != typeid(T*)) \
189 THROW_NCML_INTERNAL_ERROR("NCMLArray<T>::set_value(): got wrong type of value array, doesn't match type T!"); \
191 bool ret = Vector::set_value((arrayValue), (sz)); \
192 cacheSuperclassStateIfNeeded(); \
195#define NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(vecValue, sz) \
196 if (typeid(vecValue) != typeid(vector<T>&)) \
198 THROW_NCML_INTERNAL_ERROR("NCMLArray<T>::setValue(): got wrong type of value vector, doesn't match type T!"); \
200 bool ret = Vector::set_value((vecValue), (sz)); \
201 cacheSuperclassStateIfNeeded(); \
204 virtual bool set_value(dods_byte *val,
int sz)
206 NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(val, sz);
211 NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(val, sz);
214 virtual bool set_value(dods_int16 *val,
int sz)
216 NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(val, sz);
219 virtual bool set_value(vector<dods_int16> &val,
int sz)
221 NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(val, sz);
224 virtual bool set_value(dods_uint16 *val,
int sz)
226 NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(val, sz);
229 virtual bool set_value(vector<dods_uint16> &val,
int sz)
231 NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(val, sz);
234 virtual bool set_value(dods_int32 *val,
int sz)
236 NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(val, sz);
239 virtual bool set_value(vector<dods_int32> &val,
int sz)
241 NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(val, sz);
244 virtual bool set_value(dods_uint32 *val,
int sz)
246 NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(val, sz);
249 virtual bool set_value(vector<dods_uint32> &val,
int sz)
251 NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(val, sz);
254 virtual bool set_value(dods_float32 *val,
int sz)
256 NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(val, sz);
259 virtual bool set_value(vector<dods_float32> &val,
int sz)
261 NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(val, sz);
264 virtual bool set_value(dods_float64 *val,
int sz)
266 NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(val, sz);
269 virtual bool set_value(vector<dods_float64> &val,
int sz)
271 NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(val, sz);
274 virtual bool set_value(
string *val,
int sz)
276 NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER(val, sz);
279 virtual bool set_value(vector<string> &val,
int sz)
281 NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER(val, sz);
284#undef NCMLARRAY_CHECK_ARRAY_TYPE_THEN_CALL_SUPER
285#undef NCMLARRAY_CHECK_VECTOR_TYPE_THEN_CALL_SUPER
301 if (get_value_capacity() == 0) {
302 BESDEBUG(
"ncml",
"cacheValuesIfNeeded: the superclass Vector has no data so not copying...");
309 "NCMLArray<T>:: we don't have unconstrained values cached, caching from Vector now..." << endl);
310 unsigned int spaceSize = _noConstraints->getUnconstrainedSpaceSize();
314 oss <<
"NCMLArray expected superclass Vector size() to be the same as unconstrained space size, but it wasn't!";
315 oss <<
"size(): " << size() <<
"' spaceSize: " << spaceSize;
316 NCML_ASSERT_MSG(
static_cast<unsigned int>(length()) == spaceSize, oss.str());
318 NCML_ASSERT_MSG(
static_cast<unsigned int>(length()) == spaceSize,
319 "NCMLArray expected superclass Vector length() to be the same as unconstrained space size, but it wasn't!");
323 NCML_ASSERT(_allValues->size() == spaceSize);
326 T* pFirstElt = &((*_allValues)[0]);
328 unsigned int stored = buf2val(
reinterpret_cast<void**
>(&pFirstElt));
330 NCML_ASSERT((stored /
sizeof(T)) == spaceSize);
347 BESDEBUG(
"ncml",
"NCMLArray<T>::createAndSetConstrainedValueBuffer() called!" << endl);
351 const bool validateBounds =
false;
353 const bool validateBounds =
true;
357 VALID_PTR(_noConstraints);
358 VALID_PTR(_allValues);
361 unsigned int numVals = length();
363 values.reserve(numVals);
369 unsigned int count = 0;
370 for (it = shape.beginSpaceEnumeration(); it != endIt; ++it, ++count) {
372 values.push_back((*_allValues)[_noConstraints->getRowMajorIndex(*it, validateBounds)]);
376 if (count !=
static_cast<unsigned int>(length())) {
378 msg <<
"While adding points to hyperslab buffer we got differing number of points "
379 "from Shape space enumeration as expected from the constraints! "
380 "Shape::IndexIterator produced " << count <<
" points but we expected " << length();
381 THROW_NCML_INTERNAL_ERROR(msg.str());
384 if (count != shape.getConstrainedSpaceSize()) {
386 msg <<
"While adding points to hyperslab buffer we got differing number of points "
387 "from Shape space enumeration as expected from the shape.getConstrainedSpaceSize()! "
388 "Shape::IndexIterator produced " << count <<
" points but we expected "
389 << shape.getConstrainedSpaceSize();
390 THROW_NCML_INTERNAL_ERROR(msg.str());
395 val2buf(
static_cast<void*
>(&(values[0])),
true);
406 if (&proto ==
this) {
414 if (proto._allValues) {
415 _allValues =
new vector<T>(*(proto._allValues));
420 void destroy() noexcept
430 std::vector<T>* _allValues;