49#include "Marshaller.h"
50#include "UnMarshaller.h"
53#include "D4StreamMarshaller.h"
54#include "D4StreamUnMarshaller.h"
59#include "InternalErr.h"
62#include "dods-datatypes.h"
63#include "dods-limits.h"
66#undef CLEAR_LOCAL_DATA
73void Vector::m_duplicate(
const Vector &v) {
74 d_length = v.d_length;
75 d_length_ll = v.d_length_ll;
83 d_proto = v.d_proto->ptr_duplicate();
84 d_proto->set_parent(
this);
93 if (v.d_compound_buf.empty()) {
94 d_compound_buf = v.d_compound_buf;
98 d_compound_buf.resize(d_length);
99 for (
int i = 0; i < d_length; ++i) {
104 d_compound_buf[i] = v.d_compound_buf[i]->ptr_duplicate();
116 d_capacity = v.d_capacity;
117 d_capacity_ll = v.d_capacity_ll;
124bool Vector::m_is_cardinal_type()
const {
130 switch (d_proto->type()) {
155 case dods_structure_c:
156 case dods_sequence_c:
161 assert(
"Vector::var: Unrecognized type");
178int64_t Vector::m_create_cardinal_data_buffer_for_type(int64_t num_elements) {
181 throw InternalErr(__FILE__, __LINE__,
"create_cardinal_data_buffer_for_type: Logic error: _var is null!");
185 if (!m_is_cardinal_type()) {
187 "create_cardinal_data_buffer_for_type: incorrectly used on Vector whose type was not a "
188 "cardinal (simple data types).");
192 if (num_elements == 0)
195 m_delete_cardinal_data_buffer();
199 unsigned int bytesPerElt = d_proto->width();
200 unsigned int bytesNeeded = bytesPerElt * numEltsOfType;
202 int64_t bytesNeeded = d_proto->width_ll() * num_elements;
203 d_buf =
new char[bytesNeeded];
206 d_capacity = (
unsigned long long)num_elements;
208 set_value_capacity((uint64_t)num_elements);
213void Vector::m_delete_cardinal_data_buffer() {
223template <
class CardType>
void Vector::m_set_cardinal_values_internal(
const CardType *fromArray, int64_t numElts) {
226 "Logic error: Vector::set_cardinal_values_internal() called with negative numElts!");
230 "Logic error: Vector::set_cardinal_values_internal() called with null fromArray!");
233 m_create_cardinal_data_buffer_for_type(numElts);
235 memcpy(d_buf, fromArray, numElts *
sizeof(CardType));
254Vector::Vector(
const string &n, BaseType *v,
const Type &t,
bool is_dap4 )
255 : BaseType(n, t, is_dap4) {
259 DBG2(cerr <<
"Entering Vector ctor for object: " <<
this << endl);
261 d_proto->set_parent(
this);
282Vector::Vector(
const string &n,
const string &d,
BaseType *v,
const Type &t,
bool is_dap4 )
287 DBG2(cerr <<
"Entering Vector ctor for object: " <<
this << endl);
289 d_proto->set_parent(
this);
293Vector::Vector(
const Vector &rhs)
297 DBG2(cerr <<
"Entering Vector const ctor for object: " <<
this << endl);
298 DBG2(cerr <<
"RHS: " << &rhs << endl);
309 Vector::clear_local_data();
310 }
catch (
const std::exception &) {
318 BaseType::operator=(rhs);
323void Vector::set_name(
const std::string &name) {
324 BaseType::set_name(name);
328 d_proto->set_name(name);
332int Vector::element_count(
bool leaves) {
336 return d_proto->element_count(leaves);
352void Vector::set_send_p(
bool state) {
354 d_proto->set_send_p(state);
363 switch (d_proto->type()) {
364 case dods_structure_c:
365 case dods_sequence_c:
367 if (d_compound_buf.size() > 0) {
368 for (
unsigned long long i = 0; i < (unsigned)d_length; ++i) {
369 if (d_compound_buf[i])
370 d_compound_buf[i]->set_send_p(state);
380 BaseType::set_send_p(state);
389void Vector::set_read_p(
bool state) {
391 d_proto->set_read_p(state);
394 switch (d_proto->type()) {
395 case dods_structure_c:
396 case dods_sequence_c:
398 if (d_compound_buf.size() > 0) {
399 for (
unsigned long long i = 0; i < (unsigned)d_length; ++i) {
400 if (d_compound_buf[i])
401 d_compound_buf[i]->set_read_p(state);
411 BaseType::set_read_p(state);
423void Vector::set_length(int64_t l) { Vector::set_length_ll(l); }
432void Vector::set_length_ll(int64_t l) {
434 if (l <= DODS_INT_MAX)
438 d_too_big_for_dap2 =
true;
442void Vector::set_value_capacity(uint64_t l) {
444 if (l <= DODS_UINT_MAX)
445 d_capacity = (
unsigned int)l;
448 d_too_big_for_dap2 =
true;
469BaseType *Vector::var(
const string &n,
bool exact, btp_stack *s) {
471 DBG2(cerr <<
"Vector::var: Looking for " << name << endl);
473 if (name.empty() || d_proto->name() == name) {
482 if (d_proto->is_constructor_type()) {
483 BaseType *result = d_proto->var(name, exact, s);
502BaseType *Vector::var(
const string &n, btp_stack &s) {
505 if (d_proto->is_constructor_type())
506 return d_proto->var(name, s);
508 s.push((BaseType *)
this);
525BaseType *Vector::var(
unsigned int i)
527 switch (d_proto->type()) {
544 d_proto->val2buf(d_buf + (i * (uint64_t)d_proto->width_ll()));
549 d_proto->val2buf(&d_str[i]);
554 case dods_structure_c:
555 case dods_sequence_c:
557 return d_compound_buf[i];
560 throw Error (
"Vector::var: Unrecognized type");
565BaseType *Vector::var(
unsigned int i) {
return var_ll(i); }
567BaseType *Vector::var_ll(uint64_t i) {
568 switch (d_proto->type()) {
585 d_proto->val2buf(d_buf + (i * (uint64_t)d_proto->width_ll()));
590 d_proto->val2buf(&d_str[i]);
595 case dods_structure_c:
596 case dods_sequence_c:
598 return d_compound_buf[i];
601 throw Error(
"Vector::var: Unrecognized type");
613void Vector::vec_resize(
int l) {
615 if (m_is_cardinal_type())
616 throw InternalErr(__FILE__, __LINE__,
"Vector::vec_resize() is applicable to compound types only");
621 d_compound_buf.resize(l, 0);
623 d_capacity = d_compound_buf.size();
625 set_value_capacity(d_compound_buf.size());
628void Vector::vec_resize_ll(int64_t l) {
630 if (m_is_cardinal_type())
631 throw InternalErr(__FILE__, __LINE__,
"Vector::vec_resize() is applicable to compound types only");
636 d_compound_buf.resize(l,
nullptr);
638 d_capacity = d_compound_buf.size();
640 set_value_capacity(d_compound_buf.size());
658void Vector::intern_data(ConstraintEvaluator &eval, DDS &dds) {
659 DBG(cerr <<
"Vector::intern_data: " << name() << endl);
661 throw Error(
string(
"A method usable only with DAP2 variables was called on a DAP4 variable (")
672 switch (d_proto->type()) {
692 throw InternalErr(__FILE__, __LINE__,
"Array of Array not supported.");
694 case dods_structure_c:
695 case dods_sequence_c:
697 DBG(cerr <<
"Vector::intern_data: found ctor" << endl);
703 if (d_compound_buf.capacity() < (
unsigned)num)
704 throw InternalErr(__FILE__, __LINE__,
"The capacity of this Vector is less than the number of elements.");
706 for (
int i = 0; i < num; ++i)
712 throw InternalErr(__FILE__, __LINE__,
"Unknown datatype.");
726bool Vector::serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m,
bool ce_eval) {
730 throw Error(
string(
"A method usable only with DAP2 variables was called on a DAP4 variable (")
735 if (d_too_big_for_dap2)
736 throw Error(
"Trying to send a variable that is too large for DAP2.", __FILE__, __LINE__);
748 if (ce_eval && !eval.eval_selection(dds,
dataset()))
756 switch (d_proto->type()) {
758 m.put_vector(d_buf, num, *
this);
768 assert((
int)d_proto->width_ll() == d_proto->width_ll());
769 m.put_vector(d_buf, num, (
int)d_proto->width_ll(), *
this);
776 if (d_str.capacity() == 0)
777 throw InternalErr(__FILE__, __LINE__,
"The capacity of the string vector is 0");
781 for (
int i = 0; i < num; ++i)
788 case dods_structure_c:
789 case dods_sequence_c:
793 if (d_compound_buf.capacity() == 0)
794 throw InternalErr(__FILE__, __LINE__,
"The capacity of *this* vector is 0.");
798 for (
int i = 0; i < num && status; ++i)
799 status = status && d_compound_buf[i]->
serialize(eval, dds, m,
false);
804 throw InternalErr(__FILE__, __LINE__,
"Unknown datatype.");
807#ifdef CLEAR_LOCAL_DATA
831bool Vector::deserialize(UnMarshaller &um, DDS *dds,
bool reuse) {
836 throw Error(
string(
"A method usable only with DAP2 variables was called on a DAP4 variable (")
841 switch (d_proto->type()) {
849 um.get_int((
int &)num);
851 DBG(cerr <<
"Vector::deserialize: num = " << num << endl);
852 DBG(cerr <<
"Vector::deserialize: length = " <<
length() << endl);
857 if (num != (
unsigned int)
length())
858 throw InternalErr(__FILE__, __LINE__,
859 "The server sent declarations and data with mismatched sizes for the variable '" +
862 if (!d_buf || !reuse) {
865 m_create_cardinal_data_buffer_for_type(
length_ll());
875 if (d_proto->type() == dods_byte_c)
876 um.get_vector((
char **)&d_buf, num, *
this);
878 assert((
int)d_proto->width_ll() == d_proto->width_ll());
879 um.get_vector((
char **)&d_buf, num, d_proto->width_ll(), *
this);
885 um.get_int((
int &)num);
890 if (num != (
unsigned int)
length())
891 throw InternalErr(__FILE__, __LINE__,
"The client sent declarations and data with mismatched sizes.");
893 d_str.resize((num > 0) ? num : 0);
897 set_value_capacity((uint64_t)num);
899 for (i = 0; i < num; ++i) {
910 throw InternalErr(__FILE__, __LINE__,
"Array of array!");
912 case dods_structure_c:
913 case dods_sequence_c:
915 um.get_int((
int &)num);
920 if (num != (
unsigned int)
length())
921 throw InternalErr(__FILE__, __LINE__,
"The client sent declarations and data with mismatched sizes.");
925 for (i = 0; i < num; ++i) {
926 d_compound_buf[i] = d_proto->ptr_duplicate();
927 d_compound_buf[i]->deserialize(um, dds);
933 throw InternalErr(__FILE__, __LINE__,
"Unknown type!");
939void Vector::compute_checksum(
Crc32 &checksum) {
940 switch (d_proto->type()) {
958 checksum.
AddData(
reinterpret_cast<uint8_t *
>(d_buf),
length_ll() * d_proto->width_ll());
963 for (int64_t i = 0, e =
length(); i < e; ++i)
964 checksum.
AddData(
reinterpret_cast<const uint8_t *
>(d_str[i].data()), d_str[i].size());
968 case dods_structure_c:
969 case dods_sequence_c:
970 d_proto->compute_checksum(checksum);
976 throw InternalErr(__FILE__, __LINE__,
"Unknown or unsupported datatype (" + d_proto->type_name() +
").");
980void Vector::intern_data() {
984 switch (d_proto->type()) {
1009 case dods_structure_c:
1010 case dods_sequence_c:
1013 assert(d_compound_buf.capacity() >= (
unsigned)
length());
1015 for (
int i = 0, e =
length(); i < e; ++i)
1022 throw InternalErr(__FILE__, __LINE__,
"Unknown or unsupported datatype (" + d_proto->type_name() +
").");
1026void Vector::serialize(D4StreamMarshaller &m, DMR &dmr,
bool filter ) {
1030 if (filter && !eval.eval_selection(dmr,
dataset()))
1035 DBG(cerr << __func__ <<
", num: " << num << endl);
1041 switch (d_proto->type()) {
1046 m.put_vector(d_buf, num);
1055 m.put_vector(d_buf, num, (
int)d_proto->width_ll());
1059 if (d_proto->width_ll() == 1)
1060 m.put_vector(d_buf, num);
1062 m.put_vector(d_buf, num, (
int)d_proto->width_ll());
1065 case dods_float32_c:
1066 m.put_vector_float32(d_buf, num);
1069 case dods_float64_c:
1070 m.put_vector_float64(d_buf, num);
1075 assert((int64_t)d_str.capacity() >= num);
1077 for (int64_t i = 0; i < num; ++i)
1078 m.put_str(d_str[i]);
1083 throw InternalErr(__FILE__, __LINE__,
"Array of Array not allowed.");
1086 case dods_structure_c:
1087 case dods_sequence_c:
1088 assert(d_compound_buf.capacity() >= 0);
1090 for (int64_t i = 0; i < num; ++i) {
1091 DBG(cerr << __func__ <<
"d_compound_buf[" << i <<
"] " << d_compound_buf[i] << endl);
1092 d_compound_buf[i]->serialize(m, dmr, filter);
1098 throw InternalErr(__FILE__, __LINE__,
"Grid is not part of DAP4.");
1101 throw InternalErr(__FILE__, __LINE__,
"Unknown datatype.");
1104#ifdef CLEAR_LOCAL_DATA
1109void Vector::deserialize(D4StreamUnMarshaller &um, DMR &dmr) {
1110 if (m_is_cardinal_type()) {
1112 m_delete_cardinal_data_buffer();
1114 m_create_cardinal_data_buffer_for_type(
length());
1117 DBG(cerr << __FUNCTION__ << name() <<
", length(): " <<
length() << endl);
1123 switch (d_proto->type()) {
1128 um.get_vector((
char *)d_buf,
length_ll());
1137 um.get_vector((
char *)d_buf,
length_ll(), d_proto->width_ll());
1141 if (d_proto->width_ll() == 1)
1142 um.get_vector((
char *)d_buf,
length_ll());
1144 um.get_vector((
char *)d_buf,
length_ll(), d_proto->width_ll());
1147 case dods_float32_c:
1148 um.get_vector_float32((
char *)d_buf,
length_ll());
1151 case dods_float64_c:
1152 um.get_vector_float64((
char *)d_buf,
length_ll());
1158 d_str.resize((len > 0) ? len : 0);
1160 throw InternalErr(__FILE__, __LINE__,
"The number of string length is less than 0 ");
1164 set_value_capacity(len);
1165 for (int64_t i = 0; i < len; ++i) {
1166 um.get_str(d_str[i]);
1173 throw InternalErr(__FILE__, __LINE__,
"Array of Array not allowed.");
1176 case dods_structure_c:
1177 case dods_sequence_c: {
1180 for (int64_t i = 0, end =
length(); i < end; ++i) {
1181 d_compound_buf[i] = d_proto->ptr_duplicate();
1182 d_compound_buf[i]->deserialize(um, dmr);
1189 throw InternalErr(__FILE__, __LINE__,
"Grid is not part of DAP4.");
1192 throw InternalErr(__FILE__, __LINE__,
"Unknown type.");
1224unsigned int Vector::val2buf(
void *val,
bool reuse)
1229 if (!val &&
length() == 0)
1240 throw InternalErr(__FILE__, __LINE__,
"The incoming pointer does not contain any data.");
1242 switch (d_proto->type()) {
1256 case dods_float32_c:
1257 case dods_float64_c:
1259 if (d_buf && !reuse)
1260 m_delete_cardinal_data_buffer();
1263 if (!d_buf || !reuse)
1264 m_create_cardinal_data_buffer_for_type(
length_ll());
1268 memcpy(d_buf, val, (uint64_t)
width_ll(
true));
1278 d_str.resize(d_length);
1279 d_capacity = d_length;
1280 for (
int i = 0; i < d_length; ++i)
1281 d_str[i] = *(
static_cast<string *
> (val) + i);
1285 throw InternalErr(__FILE__,__LINE__,
"The number of string length is less than 0 ");
1286 d_str.resize(str_len);
1287 set_value_capacity(str_len);
1288 for (int64_t i = 0; i < str_len; ++i)
1289 d_str[i] = *(
static_cast<string *
> (val) + i);
1295 throw InternalErr(__FILE__, __LINE__,
"Vector::val2buf: bad type");
1299 return (
unsigned int)
width_ll(
true);
1303unsigned int Vector::val2buf(
void *val,
bool reuse) {
1305 auto ret_value = (
unsigned int)val2buf_ll(val, reuse);
1309uint64_t Vector::val2buf_ll(
void *val,
bool reuse) {
1313 if (!val &&
length() == 0)
1324 throw InternalErr(__FILE__, __LINE__,
"The incoming pointer does not contain any data.");
1326 switch (d_proto->type()) {
1340 case dods_float32_c:
1341 case dods_float64_c:
1343 if (d_buf && !reuse)
1344 m_delete_cardinal_data_buffer();
1347 if (!d_buf || !reuse)
1348 m_create_cardinal_data_buffer_for_type(
length_ll());
1352 memcpy(d_buf, val, (uint64_t)
width_ll(
true));
1361 d_str.resize(d_length);
1362 d_capacity = d_length;
1363 for (
int i = 0; i < d_length; ++i)
1364 d_str[i] = *(
static_cast<string *
> (val) + i);
1368 throw InternalErr(__FILE__, __LINE__,
"The number of string length is less than 0 ");
1369 d_str.resize(str_len);
1370 set_value_capacity(str_len);
1371 for (int64_t i = 0; i < str_len; ++i)
1372 d_str[i] = *(
static_cast<string *
>(val) + i);
1378 throw InternalErr(__FILE__, __LINE__,
"Vector::val2buf: bad type");
1381 return (
unsigned int)
width_ll(
true);
1422unsigned int Vector::buf2val(
void **val) {
1426 throw InternalErr(__FILE__, __LINE__,
"NULL pointer.");
1435 switch (d_proto->type()) {
1449 case dods_float32_c:
1450 case dods_float64_c:
1452 throw InternalErr(__FILE__, __LINE__,
1453 "Vector::buf2val: Logic error: called when cardinal type data buffer was empty!");
1455 *val =
new char[wid];
1457 memcpy(*val, d_buf, (uint64_t)wid);
1458 return (
unsigned int)wid;
1463 throw InternalErr(__FILE__, __LINE__,
1464 "Vector::buf2val: Logic error: called when string data buffer was empty!");
1466 *val =
new string[d_length];
1468 for (
int i = 0; i < d_length; ++i)
1469 *(
static_cast<string *
>(*val) + i) = d_str[i];
1475 throw InternalErr(__FILE__, __LINE__,
"Vector::buf2val: bad type");
1479uint64_t Vector::buf2val_ll(
void **val) {
1483 throw InternalErr(__FILE__, __LINE__,
"NULL pointer.");
1492 switch (d_proto->type()) {
1506 case dods_float32_c:
1507 case dods_float64_c:
1509 throw InternalErr(__FILE__, __LINE__,
1510 "Vector::buf2val: Logic error: called when cardinal type data buffer was empty!");
1512 *val =
new char[wid];
1514 memcpy(*val, d_buf, (uint64_t)wid);
1515 return (uint64_t)wid;
1520 throw InternalErr(__FILE__, __LINE__,
1521 "Vector::buf2val: Logic error: called when string data buffer was empty!");
1523 *val =
new string[d_length_ll];
1525 for (int64_t i = 0; i < d_length_ll; ++i)
1526 *(
static_cast<string *
>(*val) + i) = d_str[i];
1532 throw InternalErr(__FILE__, __LINE__,
"Vector::buf2val: bad type");
1556void Vector::set_vec(
unsigned int i,
BaseType *val) { Vector::set_vec_nocopy(i, val->ptr_duplicate()); }
1558void Vector::set_vec_ll(uint64_t i,
BaseType *val) { Vector::set_vec_nocopy_ll(i, val->ptr_duplicate()); }
1571void Vector::set_vec_nocopy(
unsigned int i,
BaseType *val) {
1576 if (i >=
static_cast<unsigned int>(d_length))
1577 throw InternalErr(__FILE__, __LINE__,
"Invalid data: index too large.");
1579 throw InternalErr(__FILE__, __LINE__,
"Invalid data: null pointer to BaseType object.");
1580 if (val->type() != d_proto->type())
1582 "invalid data: type of incoming object does not match *this* vector type.");
1592 if (i >= d_compound_buf.size()) {
1596 d_compound_buf[i] = val;
1599void Vector::set_vec_nocopy_ll(uint64_t i,
BaseType *val) {
1604 if (i >=
static_cast<uint64_t
>(length_ll()))
1605 throw InternalErr(__FILE__, __LINE__,
"Invalid data: index too large.");
1607 throw InternalErr(__FILE__, __LINE__,
"Invalid data: null pointer to BaseType object.");
1608 if (val->type() != d_proto->type())
1609 throw InternalErr(__FILE__, __LINE__,
1610 "invalid data: type of incoming object does not match *this* vector type.");
1620 if (i >= d_compound_buf.size()) {
1621 vec_resize_ll(d_compound_buf.size() + 100);
1624 d_compound_buf[i] = val;
1636void Vector::clear_local_data() {
1642 for (
unsigned int i = 0; i < d_compound_buf.size(); ++i) {
1643 delete d_compound_buf[i];
1644 d_compound_buf[i] = 0;
1648 d_compound_buf.resize(0);
1663unsigned int Vector::get_value_capacity()
const {
return d_capacity; }
1665uint64_t Vector::get_value_capacity_ll()
const {
return d_capacity_ll; }
1675void Vector::reserve_value_capacity(
unsigned int numElements) {
1677 throw InternalErr(__FILE__, __LINE__,
"reserve_value_capacity: Logic error: _var is null!");
1679 switch (d_proto->type()) {
1693 case dods_float32_c:
1694 case dods_float64_c:
1696 m_create_cardinal_data_buffer_for_type(numElements);
1703 d_str.reserve(numElements);
1705 d_capacity = numElements;
1707 set_value_capacity(numElements);
1711 throw InternalErr(__FILE__, __LINE__,
"reserve_value_capacity: Arrays not supported!");
1714 case dods_structure_c:
1715 case dods_sequence_c:
1718 d_compound_buf.reserve(numElements);
1720 d_capacity = numElements;
1722 set_value_capacity(numElements);
1726 throw InternalErr(__FILE__, __LINE__,
"reserve_value_capacity: Unknown type!");
1735void Vector::reserve_value_capacity() {
1748void Vector::reserve_value_capacity_ll(uint64_t numElements) {
1750 throw InternalErr(__FILE__, __LINE__,
"reserve_value_capacity: Logic error: _var is null!");
1752 switch (d_proto->type()) {
1766 case dods_float32_c:
1767 case dods_float64_c:
1769 m_create_cardinal_data_buffer_for_type(numElements);
1776 d_str.reserve(numElements);
1778 d_capacity = numElements;
1780 set_value_capacity(numElements);
1784 throw InternalErr(__FILE__, __LINE__,
"reserve_value_capacity: Arrays not supported!");
1787 case dods_structure_c:
1788 case dods_sequence_c:
1791 d_compound_buf.reserve(numElements);
1793 d_capacity = numElements;
1795 set_value_capacity(numElements);
1799 throw InternalErr(__FILE__, __LINE__,
"reserve_value_capacity: Unknown type!");
1808void Vector::reserve_value_capacity_ll() {
1818void Vector::reserve_value_capacity_ll_byte(uint64_t numBytes) { d_buf =
new char[numBytes]; }
1847uint64_t Vector::set_value_slice_from_row_major_vector(
const Vector &rowMajorDataC, uint64_t startElement) {
1848 static const string funcName =
"set_value_slice_from_row_major_vector:";
1851 Vector &rowMajorData =
const_cast<Vector &
>(rowMajorDataC);
1853 bool typesMatch = rowMajorData.var() && d_proto && (rowMajorData.var()->type() == d_proto->type());
1855 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: types do not match so cannot be copied!");
1859 if (!rowMajorData.read_p()) {
1862 "Logic error: the Vector to copy data from has !read_p() and should have been read in!");
1866 if (rowMajorData.length_ll() < 0) {
1870 "Logic error: the Vector to copy data from has length_ll() < 0 and was probably not initialized!");
1876 if (rowMajorData.get_value_capacity_ll() <
static_cast<uint64_t
>(rowMajorData.length_ll())) {
1879 funcName +
"Logic error: the Vector to copy from has a data capacity less than its length, can't copy!");
1884 if (d_capacity_ll < (startElement + rowMajorData.length_ll())) {
1887 "Logic error: the capacity of this Vector cannot hold all the data in the from Vector!");
1891 switch (d_proto->type()) {
1905 case dods_float32_c:
1906 case dods_float64_c: {
1908 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: this->_buf was unexpectedly null!");
1910 if (!rowMajorData.d_buf) {
1911 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: rowMajorData._buf was unexpectedly null!");
1914 int64_t varWidth = d_proto->width_ll();
1915 char *pFromBuf = rowMajorData.d_buf;
1916 int64_t numBytesToCopy = rowMajorData.width_ll(
true);
1917 char *pIntoBuf = d_buf + (startElement * varWidth);
1918 memcpy(pIntoBuf, pFromBuf, numBytesToCopy);
1925 for (uint64_t i = 0; i < static_cast<uint64_t>(rowMajorData.length_ll()); ++i) {
1926 d_str[startElement + i] = rowMajorData.d_str[i];
1932 case dods_structure_c:
1933 case dods_sequence_c:
1938 "Unimplemented method for Vectors of type: array, opaque, structure, sequence or grid.");
1941 throw InternalErr(__FILE__, __LINE__, funcName +
": Unknown type!");
1945 return (uint64_t)rowMajorData.length_ll();
1956template <
typename T>
static bool types_match(Type t, T *cpp_var) {
1961 return typeid(cpp_var) ==
typeid(dods_byte *);
1964 return typeid(cpp_var) ==
typeid(dods_int8 *);
1966 return typeid(cpp_var) ==
typeid(dods_int16 *);
1968 return typeid(cpp_var) ==
typeid(dods_uint16 *);
1970 return typeid(cpp_var) ==
typeid(dods_int32 *);
1972 return typeid(cpp_var) ==
typeid(dods_uint32 *);
1974 return typeid(cpp_var) ==
typeid(dods_int64 *);
1976 return typeid(cpp_var) ==
typeid(dods_uint64 *);
1978 case dods_float32_c:
1979 return typeid(cpp_var) ==
typeid(dods_float32 *);
1980 case dods_float64_c:
1981 return typeid(cpp_var) ==
typeid(dods_float64 *);
1989 case dods_structure_c:
1990 case dods_sequence_c:
2000template <
typename T>
bool Vector::set_value_worker(T *v,
int sz) {
2001 if (!v || !types_match(
2002 d_proto->type() == dods_enum_c ?
static_cast<D4Enum *
>(d_proto)->element_type() : d_proto->type(), v))
2004 m_set_cardinal_values_internal(v, (int64_t)sz);
2008template <
typename T>
bool Vector::set_value_ll_worker(T *v, int64_t sz) {
2009 if (!v || !types_match(
2010 d_proto->type() == dods_enum_c ?
static_cast<D4Enum *
>(d_proto)->element_type() : d_proto->type(), v))
2013 m_set_cardinal_values_internal(v, sz);
2017bool Vector::set_value(dods_byte *val,
int sz) {
return set_value_worker(val, sz); }
2019bool Vector::set_value(dods_int8 *val,
int sz) {
return set_value_worker(val, sz); }
2020bool Vector::set_value(dods_int16 *val,
int sz) {
return set_value_worker(val, sz); }
2021bool Vector::set_value(dods_uint16 *val,
int sz) {
return set_value_worker(val, sz); }
2022bool Vector::set_value(dods_int32 *val,
int sz) {
return set_value_worker(val, sz); }
2023bool Vector::set_value(dods_uint32 *val,
int sz) {
return set_value_worker(val, sz); }
2024bool Vector::set_value(dods_int64 *val,
int sz) {
return set_value_worker(val, sz); }
2025bool Vector::set_value(dods_uint64 *val,
int sz) {
return set_value_worker(val, sz); }
2026bool Vector::set_value(dods_float32 *val,
int sz) {
return set_value_worker(val, sz); }
2027bool Vector::set_value(dods_float64 *val,
int sz) {
return set_value_worker(val, sz); }
2029bool Vector::set_value_ll(dods_byte *val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2031bool Vector::set_value_ll(dods_int8 *val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2032bool Vector::set_value_ll(dods_int16 *val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2033bool Vector::set_value_ll(dods_uint16 *val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2034bool Vector::set_value_ll(dods_int32 *val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2035bool Vector::set_value_ll(dods_uint32 *val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2036bool Vector::set_value_ll(dods_int64 *val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2037bool Vector::set_value_ll(dods_uint64 *val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2038bool Vector::set_value_ll(dods_float32 *val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2039bool Vector::set_value_ll(dods_float64 *val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2048bool Vector::set_value(
string *val,
int sz) {
2049 if ((
var()->type() == dods_str_c ||
var()->type() == dods_url_c) && val) {
2054 set_value_capacity(sz);
2055 for (
int t = 0; t < sz; t++) {
2066bool Vector::set_value_ll(
string *val, int64_t sz) {
2067 if ((
var()->type() == dods_str_c ||
var()->type() == dods_url_c) && val) {
2072 set_value_capacity(sz);
2073 for (int64_t t = 0; t < sz; t++) {
2084template <
typename T>
bool Vector::set_value_worker(vector<T> &v,
int sz) {
return set_value(v.data(), sz); }
2086template <
typename T>
bool Vector::set_value_ll_worker(vector<T> &v, int64_t sz) {
return set_value_ll(v.data(), sz); }
2088bool Vector::set_value(vector<dods_byte> &val,
int sz) {
return set_value_worker(val, sz); }
2089bool Vector::set_value(vector<dods_int8> &val,
int sz) {
return set_value_worker(val, sz); }
2090bool Vector::set_value(vector<dods_int16> &val,
int sz) {
return set_value_worker(val, sz); }
2091bool Vector::set_value(vector<dods_uint16> &val,
int sz) {
return set_value_worker(val, sz); }
2092bool Vector::set_value(vector<dods_int32> &val,
int sz) {
return set_value_worker(val, sz); }
2093bool Vector::set_value(vector<dods_uint32> &val,
int sz) {
return set_value_worker(val, sz); }
2094bool Vector::set_value(vector<dods_int64> &val,
int sz) {
return set_value_worker(val, sz); }
2095bool Vector::set_value(vector<dods_uint64> &val,
int sz) {
return set_value_worker(val, sz); }
2096bool Vector::set_value(vector<dods_float32> &val,
int sz) {
return set_value_worker(val, sz); }
2097bool Vector::set_value(vector<dods_float64> &val,
int sz) {
return set_value_worker(val, sz); }
2099bool Vector::set_value_ll(vector<dods_byte> &val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2100bool Vector::set_value_ll(vector<dods_int8> &val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2101bool Vector::set_value_ll(vector<dods_int16> &val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2102bool Vector::set_value_ll(vector<dods_uint16> &val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2103bool Vector::set_value_ll(vector<dods_int32> &val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2104bool Vector::set_value_ll(vector<dods_uint32> &val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2105bool Vector::set_value_ll(vector<dods_int64> &val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2106bool Vector::set_value_ll(vector<dods_uint64> &val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2107bool Vector::set_value_ll(vector<dods_float32> &val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2108bool Vector::set_value_ll(vector<dods_float64> &val, int64_t sz) {
return set_value_ll_worker(val, sz); }
2111bool Vector::set_value(vector<string> &val,
int sz) {
2112 if (
var()->type() == dods_str_c ||
var()->type() == dods_url_c) {
2115 for (
int t = 0; t < sz; t++) {
2126bool Vector::set_value_ll(vector<string> &val, int64_t sz) {
2127 if (
var()->type() == dods_str_c ||
var()->type() == dods_url_c) {
2130 for (int64_t t = 0; t < sz; t++) {
2161template <
typename T>
void Vector::value_worker(vector<unsigned int> *indices, T *b)
const {
2164 for (vector<unsigned int>::iterator i = indices->begin(), e = indices->end(); i != e; ++i) {
2165 unsigned long currentIndex = *i;
2166 if(currentIndex > (
unsigned int)
length()){
2168 s <<
"Vector::value() - Subset index[" << i - subsetIndex->begin() <<
"] = " << currentIndex <<
" references a value that is " <<
2169 "outside the bounds of the internal storage [ length()= " <<
length() <<
" ] name: '" << name() <<
"'. ";
2170 throw Error(s.str());
2172 b[i - indices->begin()] =
reinterpret_cast<T*
>(d_buf )[currentIndex];
2175 for (
unsigned long i = 0, e = indices->size(); i < e; ++i) {
2176 unsigned long currentIndex = (*indices)[i];
2177 if (currentIndex > (
unsigned int)
length()) {
2179 s <<
"Vector::value() - Subset index[" << i <<
"] = " << currentIndex <<
" references a value that is "
2180 <<
"outside the bounds of the internal storage [ length()= " <<
length() <<
" ] name: '" << name()
2182 throw Error(s.str());
2184 b[i] =
reinterpret_cast<T *
>(d_buf)[currentIndex];
2188template <
typename T>
void Vector::value_ll_worker(vector<uint64_t> *indices, T *b)
const {
2191 for (vector<unsigned int>::iterator i = indices->begin(), e = indices->end(); i != e; ++i) {
2192 unsigned long currentIndex = *i;
2193 if(currentIndex > (
unsigned int)
length()){
2195 s <<
"Vector::value() - Subset index[" << i - subsetIndex->begin() <<
"] = " << currentIndex <<
" references a value that is " <<
2196 "outside the bounds of the internal storage [ length()= " <<
length() <<
" ] name: '" << name() <<
"'. ";
2197 throw Error(s.str());
2199 b[i - indices->begin()] =
reinterpret_cast<T*
>(d_buf )[currentIndex];
2202 for (uint64_t i = 0, e = indices->size(); i < e; ++i) {
2203 uint64_t currentIndex = (*indices)[i];
2204 if (currentIndex > (uint64_t)
length_ll()) {
2206 s <<
"Vector::value() - Subset index[" << i <<
"] = " << currentIndex <<
" references a value that is "
2207 <<
"outside the bounds of the internal storage [ length_ll()= " <<
length_ll() <<
" ] name: '" << name()
2209 throw Error(s.str());
2211 b[i] =
reinterpret_cast<T *
>(d_buf)[currentIndex];
2215void Vector::value(vector<unsigned int> *indices, dods_byte *b)
const { value_worker(indices, b); }
2216void Vector::value(vector<unsigned int> *indices, dods_int8 *b)
const { value_worker(indices, b); }
2217void Vector::value(vector<unsigned int> *indices, dods_int16 *b)
const { value_worker(indices, b); }
2218void Vector::value(vector<unsigned int> *indices, dods_uint16 *b)
const { value_worker(indices, b); }
2219void Vector::value(vector<unsigned int> *indices, dods_int32 *b)
const { value_worker(indices, b); }
2220void Vector::value(vector<unsigned int> *indices, dods_uint32 *b)
const { value_worker(indices, b); }
2221void Vector::value(vector<unsigned int> *indices, dods_int64 *b)
const { value_worker(indices, b); }
2222void Vector::value(vector<unsigned int> *indices, dods_uint64 *b)
const { value_worker(indices, b); }
2223void Vector::value(vector<unsigned int> *indices, dods_float32 *b)
const { value_worker(indices, b); }
2224void Vector::value(vector<unsigned int> *indices, dods_float64 *b)
const { value_worker(indices, b); }
2226void Vector::value_ll(vector<uint64_t> *indices, dods_byte *b)
const { value_ll_worker(indices, b); }
2227void Vector::value_ll(vector<uint64_t> *indices, dods_int8 *b)
const { value_ll_worker(indices, b); }
2228void Vector::value_ll(vector<uint64_t> *indices, dods_int16 *b)
const { value_ll_worker(indices, b); }
2229void Vector::value_ll(vector<uint64_t> *indices, dods_uint16 *b)
const { value_ll_worker(indices, b); }
2230void Vector::value_ll(vector<uint64_t> *indices, dods_int32 *b)
const { value_ll_worker(indices, b); }
2231void Vector::value_ll(vector<uint64_t> *indices, dods_uint32 *b)
const { value_ll_worker(indices, b); }
2232void Vector::value_ll(vector<uint64_t> *indices, dods_int64 *b)
const { value_ll_worker(indices, b); }
2233void Vector::value_ll(vector<uint64_t> *indices, dods_uint64 *b)
const { value_ll_worker(indices, b); }
2234void Vector::value_ll(vector<uint64_t> *indices, dods_float32 *b)
const { value_ll_worker(indices, b); }
2235void Vector::value_ll(vector<uint64_t> *indices, dods_float64 *b)
const { value_ll_worker(indices, b); }
2238template void Vector::value(vector<unsigned int> *indices, dods_byte *b)
const;
2239template void Vector::value(vector<unsigned int> *indices, dods_int8 *b)
const;
2240template void Vector::value(vector<unsigned int> *indices, dods_int16 *b)
const;
2241template void Vector::value(vector<unsigned int> *indices, dods_uint16 *b)
const;
2242template void Vector::value(vector<unsigned int> *indices, dods_int32 *b)
const;
2243template void Vector::value(vector<unsigned int> *indices, dods_uint32 *b)
const;
2244template void Vector::value(vector<unsigned int> *indices, dods_int64 *b)
const;
2245template void Vector::value(vector<unsigned int> *indices, dods_uint64 *b)
const;
2246template void Vector::value(vector<unsigned int> *indices, dods_float32 *b)
const;
2247template void Vector::value(vector<unsigned int> *indices, dods_float64 *b)
const;
2252void Vector::value(vector<unsigned int> *subsetIndex, vector<string> &b)
const {
2253 unsigned long currentIndex;
2255 if (d_proto->type() == dods_str_c || d_proto->type() == dods_url_c) {
2256 for (
unsigned long i = 0; i < subsetIndex->size(); ++i) {
2257 currentIndex = (*subsetIndex)[i];
2258 if (currentIndex > (
unsigned int)
length()) {
2260 s <<
"Vector::value() - Subset index[" << i <<
"] = " << currentIndex <<
" references a value that is "
2261 <<
"outside the bounds of the internal storage [ length()= " <<
length() <<
" ] name: '" << name()
2263 throw Error(s.str());
2265 b[i] = d_str[currentIndex];
2270void Vector::value_ll(vector<uint64_t> *subsetIndex, vector<string> &b)
const {
2271 uint64_t currentIndex;
2273 if (d_proto->type() == dods_str_c || d_proto->type() == dods_url_c) {
2274 for (uint64_t i = 0; i < subsetIndex->size(); ++i) {
2275 currentIndex = (*subsetIndex)[i];
2276 if (currentIndex > (uint64_t)
length_ll()) {
2278 s <<
"Vector::value() - Subset index[" << i <<
"] = " << currentIndex <<
" references a value that is "
2279 <<
"outside the bounds of the internal storage [ length_ll()= " <<
length_ll() <<
" ] name: '"
2281 throw Error(s.str());
2283 b[i] = d_str[currentIndex];
2288template <
typename T>
void Vector::value_worker(T *v)
const {
2291 if (v && types_match(
2292 d_proto->type() == dods_enum_c ?
static_cast<D4Enum *
>(d_proto)->element_type() : d_proto->type(), v))
2293 memcpy(v, d_buf,
length_ll() *
sizeof(T));
2295void Vector::value(dods_byte *b)
const { value_worker(b); }
2296void Vector::value(dods_int8 *b)
const { value_worker(b); }
2297void Vector::value(dods_int16 *b)
const { value_worker(b); }
2298void Vector::value(dods_uint16 *b)
const { value_worker(b); }
2299void Vector::value(dods_int32 *b)
const { value_worker(b); }
2300void Vector::value(dods_uint32 *b)
const { value_worker(b); }
2301void Vector::value(dods_int64 *b)
const { value_worker(b); }
2302void Vector::value(dods_uint64 *b)
const { value_worker(b); }
2303void Vector::value(dods_float32 *b)
const { value_worker(b); }
2304void Vector::value(dods_float64 *b)
const { value_worker(b); }
2307template void Vector::value(dods_byte *v)
const;
2308template void Vector::value(dods_int8 *v)
const;
2309template void Vector::value(dods_int16 *v)
const;
2310template void Vector::value(dods_uint16 *v)
const;
2311template void Vector::value(dods_int32 *v)
const;
2312template void Vector::value(dods_uint32 *v)
const;
2313template void Vector::value(dods_int64 *v)
const;
2314template void Vector::value(dods_uint64 *v)
const;
2315template void Vector::value(dods_float32 *v)
const;
2316template void Vector::value(dods_float64 *v)
const;
2320void Vector::value(vector<string> &b)
const {
2321 if (d_proto->type() == dods_str_c || d_proto->type() == dods_url_c)
2327void *Vector::value() {
2328 void *buffer =
new char[
width_ll(
true)];
2330 memcpy(buffer, d_buf,
width_ll(
true));
2351void Vector::add_var(
BaseType *v, Part ) {
2354 Vector::add_var_nocopy(v->ptr_duplicate());
2373 d_proto = v->ptr_duplicate();
2378 if (!v->name().empty())
2379 set_name(v->name());
2381 d_proto->set_name(name());
2383 d_proto->set_parent(
this);
2385 DBG(cerr <<
"Vector::add_var: Added variable " << v <<
" (" << v->name() <<
" " << v->type_name() <<
")"
2391void Vector::add_var_nocopy(
BaseType *v, Part) {
2403 if (!v->name().empty())
2404 set_name(v->name());
2406 d_proto->set_name(name());
2408 d_proto->set_parent(
this);
2410 DBG(cerr <<
"Vector::add_var_no_copy: Added variable " << v <<
" (" << v->name() <<
" " << v->type_name() <<
")"
2415bool Vector::check_semantics(
string &msg,
bool) {
return BaseType::check_semantics(msg); }
2424bool Vector::is_dap4_projected(std::vector<std::string> &inventory) {
2425 bool has_projected_dap4 =
false;
2427 if (d_proto->is_constructor_type()) {
2428 has_projected_dap4 =
2429 d_proto->is_dap4_projected(inventory) || attributes()->
has_dap4_types(FQN(), inventory);
2431 has_projected_dap4 = prototype()->is_dap4();
2432 if (has_projected_dap4) {
2433 inventory.emplace_back(prototype()->
type_name() +
" " + FQN());
2435 has_projected_dap4 |= attributes()->
has_dap4_types(FQN(), inventory);
2437 if (has_projected_dap4) {
2438 inventory.emplace_back(
type_name() +
" " + FQN());
2441 return has_projected_dap4;
2452void Vector::dump(ostream &strm)
const {
2453 strm << DapIndent::LMarg <<
"Vector::dump - (" << (
void *)
this <<
")" << endl;
2454 DapIndent::Indent();
2455 BaseType::dump(strm);
2456 strm << DapIndent::LMarg <<
"# elements in vector: " << d_length << endl;
2458 strm << DapIndent::LMarg <<
"base type:" << endl;
2459 DapIndent::Indent();
2460 d_proto->dump(strm);
2461 DapIndent::UnIndent();
2463 strm << DapIndent::LMarg <<
"base type: not set" << endl;
2465 strm << DapIndent::LMarg <<
"vector contents:" << endl;
2466 DapIndent::Indent();
2467 for (
unsigned i = 0; i < d_compound_buf.size(); ++i) {
2468 if (d_compound_buf[i])
2469 d_compound_buf[i]->dump(strm);
2471 strm << DapIndent::LMarg <<
"vec[" << i <<
"] is null" << endl;
2473 DapIndent::UnIndent();
2474 strm << DapIndent::LMarg <<
"strings:" << endl;
2475 DapIndent::Indent();
2476 for (
unsigned i = 0; i < d_str.size(); i++) {
2477 strm << DapIndent::LMarg << d_str[i] << endl;
2479 DapIndent::UnIndent();
2481 switch (d_proto != 0 ? d_proto->type() : 0) {
2484 strm << DapIndent::LMarg <<
"_buf: ";
2485 strm.write(d_buf, d_length);
2491 strm << DapIndent::LMarg <<
"_buf: " << (
void *)d_buf << endl;
2495 strm << DapIndent::LMarg <<
"_buf: EMPTY" << endl;
2498 DapIndent::UnIndent();
void AddData(const uint8_t *pData, const uint32_t length)
bool has_dap4_types(const std::string &path, std::vector< std::string > &inventory) const
A class for software fault reporting.
top level DAP object to house generic methods
virtual void set_length(int64_t)
Set the number of elements for this variable. use -1 to indicate nothing set.
Type
Identifies the data type.
virtual int64_t length_ll() const
Get the number of elements in this variable This version of the function deprecates length() which is...
virtual void reserve_value_capacity_ll(uint64_t numElements)
virtual bool read_p()
Has this variable been read?
virtual string type_name() const
Returns the type of the class instance as a string.
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=nullptr)
Returns a pointer to a member of a constructor class.
string www2id(const string &in, const string &escape, const string &except)
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Move data to the net, then remove them from the object.
virtual int length() const
How many elements are in this variable? Uses -1 in places.
virtual void intern_data(ConstraintEvaluator &eval, DDS &dds)
virtual int64_t width_ll(bool constrained=false) const
Return the number of bytes needed to hold the array data.
virtual void reserve_value_capacity(unsigned int numElements)
virtual bool send_p()
Should this variable be sent?
virtual void set_value(D4SeqValues &values)
Set the internal value. The 'values' of a D4Sequence is a vector of vectors of BaseType* objects....
virtual void set_length_ll(int64_t)
Set the number of elements in this variable This version of the function deprecates set_length() whic...
virtual void compute_checksum(Crc32 &checksum)=0
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
virtual string dataset() const
Returns the name of the dataset used to create this instance.
virtual void clear_local_data()
The basic data type for the DODS DAP types. */.
virtual unsigned int val2buf(void *val, bool reuse=false)=0
Loads class data.