50#include "Marshaller.h"
51#include "UnMarshaller.h"
53#include "D4StreamMarshaller.h"
54#include "D4StreamUnMarshaller.h"
59#include "dods-datatypes.h"
60#include "dods-limits.h"
63#include "InternalErr.h"
66#undef CLEAR_LOCAL_DATA
73void Vector::m_duplicate(
const Vector & v)
75 d_length = v.d_length;
76 d_length_ll = v.d_length_ll;
82 if (d_proto)
delete d_proto;
94 if (v.d_compound_buf.empty()) {
95 d_compound_buf = v.d_compound_buf;
100 d_compound_buf.resize(d_length);
101 for (
int i = 0; i < d_length; ++i) {
106 d_compound_buf[i] = v.d_compound_buf[i]->ptr_duplicate();
118 d_capacity = v.d_capacity;
119 d_capacity_ll = v.d_capacity_ll;
126bool Vector::m_is_cardinal_type()
const
133 switch (d_proto->
type()) {
158 case dods_structure_c:
159 case dods_sequence_c:
164 assert(
"Vector::var: Unrecognized type");
181int64_t Vector::m_create_cardinal_data_buffer_for_type(int64_t num_elements)
185 throw InternalErr(__FILE__, __LINE__,
186 "create_cardinal_data_buffer_for_type: Logic error: _var is null!");
190 if (!m_is_cardinal_type()) {
191 throw InternalErr(__FILE__, __LINE__,
192 "create_cardinal_data_buffer_for_type: incorrectly used on Vector whose type was not a cardinal (simple data types).");
196 if (num_elements == 0)
199 m_delete_cardinal_data_buffer();
203 unsigned int bytesPerElt = d_proto->
width();
204 unsigned int bytesNeeded = bytesPerElt * numEltsOfType;
206 int64_t bytesNeeded = d_proto->width_ll() * num_elements;
207 d_buf =
new char[bytesNeeded];
210 d_capacity = (
unsigned long long)num_elements;
212 set_value_capacity((uint64_t)num_elements);
217void Vector::m_delete_cardinal_data_buffer()
228template<
class CardType>
229void Vector::m_set_cardinal_values_internal(
const CardType* fromArray, int64_t numElts)
232 throw InternalErr(__FILE__, __LINE__,
"Logic error: Vector::set_cardinal_values_internal() called with negative numElts!");
235 throw InternalErr(__FILE__, __LINE__,
"Logic error: Vector::set_cardinal_values_internal() called with null fromArray!");
238 m_create_cardinal_data_buffer_for_type(numElts);
240 memcpy(d_buf, fromArray, numElts *
sizeof(CardType));
265 DBG2(cerr <<
"Entering Vector ctor for object: " <<
this << endl);
294 DBG2(cerr <<
"Entering Vector ctor for object: " <<
this << endl);
303 DBG2(cerr <<
"Entering Vector const ctor for object: " <<
this <<
304 endl); DBG2(cerr <<
"RHS: " << &rhs << endl);
318 catch (
const std::exception &) {
323Vector & Vector::operator=(
const Vector & rhs)
327 BaseType::operator=(rhs);
375 switch (d_proto->
type()) {
376 case dods_structure_c:
377 case dods_sequence_c:
379 if (d_compound_buf.size() > 0) {
380 for (
unsigned long long i = 0; i < (unsigned) d_length; ++i) {
381 if (d_compound_buf[i]) d_compound_buf[i]->set_send_p(state);
406 switch (d_proto->
type()) {
407 case dods_structure_c:
408 case dods_sequence_c:
410 if (d_compound_buf.size() > 0) {
411 for (
unsigned long long i = 0; i < (unsigned)d_length; ++i) {
412 if (d_compound_buf[i]) d_compound_buf[i]->set_read_p(state);
449 if (l <= DODS_INT_MAX)
453 d_too_big_for_dap2 =
true;
457void Vector::set_value_capacity(uint64_t l)
460 if (l <= DODS_UINT_MAX)
461 d_capacity = (
unsigned int)l;
464 d_too_big_for_dap2 =
true;
489 DBG2(cerr <<
"Vector::var: Looking for " <<
name << endl);
546 switch (d_proto->
type()) {
563 d_proto->
val2buf(d_buf + (i * (uint64_t)d_proto->width_ll()));
573 case dods_structure_c:
574 case dods_sequence_c:
576 return d_compound_buf[i];
579 throw Error (
"Vector::var: Unrecognized type");
591 switch (d_proto->
type()) {
608 d_proto->
val2buf(d_buf + (i * (uint64_t)d_proto->width_ll()));
618 case dods_structure_c:
619 case dods_sequence_c:
621 return d_compound_buf[i];
624 throw Error (
"Vector::var: Unrecognized type");
640 if (m_is_cardinal_type())
641 throw InternalErr(__FILE__, __LINE__,
"Vector::vec_resize() is applicable to compound types only");
646 d_compound_buf.resize(l, 0);
648 d_capacity = d_compound_buf.size();
650 set_value_capacity(d_compound_buf.size());
654void Vector::vec_resize_ll(int64_t l)
657 if (m_is_cardinal_type())
658 throw InternalErr(__FILE__, __LINE__,
"Vector::vec_resize() is applicable to compound types only");
663 d_compound_buf.resize(l,
nullptr);
665 d_capacity = d_compound_buf.size();
667 set_value_capacity(d_compound_buf.size());
688 DBG(cerr <<
"Vector::intern_data: " <<
name() << endl);
690 throw Error(
string(
"A method usable only with DAP2 variables was called on a DAP4 variable (").append(
name()).append(
")."), __FILE__, __LINE__);
698 switch (d_proto->
type()) {
718 throw InternalErr(__FILE__, __LINE__,
"Array of Array not supported.");
720 case dods_structure_c:
721 case dods_sequence_c:
723 DBG(cerr <<
"Vector::intern_data: found ctor" << endl);
729 if (d_compound_buf.capacity() < (
unsigned)num)
730 throw InternalErr(__FILE__, __LINE__,
"The capacity of this Vector is less than the number of elements.");
732 for (
int i = 0; i < num; ++i)
738 throw InternalErr(__FILE__, __LINE__,
"Unknown datatype.");
757 throw Error(
string(
"A method usable only with DAP2 variables was called on a DAP4 variable (").append(
name()).append(
")."), __FILE__, __LINE__);
759 if (d_too_big_for_dap2)
760 throw Error(
"Trying to send a variable that is too large for DAP2.", __FILE__, __LINE__);
780 switch (d_proto->
type()) {
782 m.put_vector(d_buf, num, *
this);
792 assert((
int)d_proto->width_ll() == d_proto->width_ll());
793 m.put_vector(d_buf, num, (
int)d_proto->width_ll(), *
this);
800 if (d_str.capacity() == 0)
801 throw InternalErr(__FILE__, __LINE__,
"The capacity of the string vector is 0");
805 for (
int i = 0; i < num; ++i)
812 case dods_structure_c:
813 case dods_sequence_c:
817 if (d_compound_buf.capacity() == 0)
818 throw InternalErr(__FILE__, __LINE__,
"The capacity of *this* vector is 0.");
822 for (
int i = 0; i < num && status; ++i)
823 status = status && d_compound_buf[i]->
serialize(eval, dds, m,
false);
828 throw InternalErr(__FILE__, __LINE__,
"Unknown datatype.");
831#ifdef CLEAR_LOCAL_DATA
861 throw Error(
string(
"A method usable only with DAP2 variables was called on a DAP4 variable (").append(
name()).append(
")."), __FILE__, __LINE__);
863 switch (d_proto->
type()) {
871 um.get_int((
int &) num);
873 DBG(cerr <<
"Vector::deserialize: num = " << num << endl);
874 DBG(cerr <<
"Vector::deserialize: length = " <<
length() << endl);
879 if (num != (
unsigned int)
length())
880 throw InternalErr(__FILE__, __LINE__,
"The server sent declarations and data with mismatched sizes for the variable '" +
name() +
"'.");
882 if (!d_buf || !reuse) {
885 m_create_cardinal_data_buffer_for_type(
length_ll());
895 if (d_proto->
type() == dods_byte_c)
896 um.get_vector((
char **) &d_buf, num, *
this);
898 assert((
int)d_proto->width_ll() == d_proto->width_ll());
899 um.get_vector((
char **) &d_buf, num, d_proto->width_ll(), *
this);
905 um.get_int((
int &) num);
910 if (num != (
unsigned int)
length())
911 throw InternalErr(__FILE__, __LINE__,
"The client sent declarations and data with mismatched sizes.");
913 d_str.resize((num > 0) ? num : 0);
917 set_value_capacity((uint64_t)num);
919 for (i = 0; i < num; ++i) {
930 throw InternalErr(__FILE__, __LINE__,
"Array of array!");
932 case dods_structure_c:
933 case dods_sequence_c:
935 um.get_int((
int &) num);
940 if (num != (
unsigned int)
length())
941 throw InternalErr(__FILE__, __LINE__,
"The client sent declarations and data with mismatched sizes.");
945 for (i = 0; i < num; ++i) {
947 d_compound_buf[i]->deserialize(um, dds);
953 throw InternalErr(__FILE__, __LINE__,
"Unknown type!");
961 switch (d_proto->
type()) {
979 checksum.
AddData(
reinterpret_cast<uint8_t*
>(d_buf),
length_ll() * d_proto->width_ll());
984 for (int64_t i = 0, e =
length(); i < e; ++i)
985 checksum.
AddData(
reinterpret_cast<const uint8_t*
>(d_str[i].data()), d_str[i].size());
989 case dods_structure_c:
990 case dods_sequence_c:
997 throw InternalErr(__FILE__, __LINE__,
"Unknown or unsupported datatype (" + d_proto->
type_name() +
").");
1006 switch (d_proto->
type()) {
1020 case dods_float32_c:
1021 case dods_float64_c:
1031 case dods_structure_c:
1032 case dods_sequence_c:
1035 assert(d_compound_buf.capacity() >= (
unsigned)
length());
1037 for (
int i = 0, e =
length(); i < e; ++i)
1044 throw InternalErr(__FILE__, __LINE__,
"Unknown or unsupported datatype (" + d_proto->
type_name() +
").");
1054 if (filter && !eval.eval_selection(dmr,
dataset()))
1059 DBG(cerr << __func__ <<
", num: " << num << endl);
1065 switch (d_proto->
type()) {
1070 m.put_vector(d_buf, num);
1079 m.put_vector(d_buf, num, (
int)d_proto->width_ll());
1083 if (d_proto->width_ll() == 1)
1084 m.put_vector(d_buf, num);
1086 m.put_vector(d_buf, num, (
int)d_proto->width_ll());
1089 case dods_float32_c:
1090 m.put_vector_float32(d_buf, num);
1093 case dods_float64_c:
1094 m.put_vector_float64(d_buf, num);
1099 assert((int64_t)d_str.capacity() >= num);
1101 for (int64_t i = 0; i < num; ++i)
1102 m.put_str(d_str[i]);
1107 throw InternalErr(__FILE__, __LINE__,
"Array of Array not allowed.");
1110 case dods_structure_c:
1111 case dods_sequence_c:
1112 assert(d_compound_buf.capacity() >= 0);
1114 for (int64_t i = 0; i < num; ++i) {
1115 DBG(cerr << __func__ <<
"d_compound_buf[" << i <<
"] " << d_compound_buf[i] << endl);
1116 d_compound_buf[i]->serialize(m, dmr, filter);
1122 throw InternalErr(__FILE__, __LINE__,
"Grid is not part of DAP4.");
1125 throw InternalErr(__FILE__, __LINE__,
"Unknown datatype.");
1128#ifdef CLEAR_LOCAL_DATA
1136 if (m_is_cardinal_type()) {
1138 m_delete_cardinal_data_buffer();
1140 m_create_cardinal_data_buffer_for_type(
length());
1143 DBG(cerr << __FUNCTION__ <<
name() <<
", length(): " <<
length() << endl);
1149 switch (d_proto->
type()) {
1154 um.get_vector((
char *)d_buf,
length_ll());
1163 um.get_vector((
char *)d_buf,
length_ll(), d_proto->width_ll());
1167 if (d_proto->width_ll() == 1)
1168 um.get_vector((
char *)d_buf,
length_ll());
1170 um.get_vector((
char *)d_buf,
length_ll(), d_proto->width_ll());
1173 case dods_float32_c:
1174 um.get_vector_float32((
char *)d_buf,
length_ll());
1177 case dods_float64_c:
1178 um.get_vector_float64((
char *)d_buf,
length_ll());
1184 d_str.resize((len > 0) ? len : 0);
1186 throw InternalErr(__FILE__,__LINE__,
"The number of string length is less than 0 ");
1190 set_value_capacity(len);
1191 for (int64_t i = 0; i < len; ++i) {
1192 um.get_str(d_str[i]);
1199 throw InternalErr(__FILE__, __LINE__,
"Array of Array not allowed.");
1202 case dods_structure_c:
1203 case dods_sequence_c: {
1206 for (int64_t i = 0, end =
length(); i < end; ++i) {
1208 d_compound_buf[i]->deserialize(um, dmr);
1215 throw InternalErr(__FILE__, __LINE__,
"Grid is not part of DAP4.");
1218 throw InternalErr(__FILE__, __LINE__,
"Unknown type.");
1255 if (!val &&
length() == 0)
1266 throw InternalErr(__FILE__, __LINE__,
"The incoming pointer does not contain any data.");
1268 switch (d_proto->
type()) {
1282 case dods_float32_c:
1283 case dods_float64_c:
1285 if (d_buf && !reuse)
1286 m_delete_cardinal_data_buffer();
1289 if (!d_buf || !reuse)
1290 m_create_cardinal_data_buffer_for_type(
length_ll());
1294 memcpy(d_buf, val, (uint64_t)
width_ll(
true));
1304 d_str.resize(d_length);
1305 d_capacity = d_length;
1306 for (
int i = 0; i < d_length; ++i)
1307 d_str[i] = *(
static_cast<string *
> (val) + i);
1311 throw InternalErr(__FILE__,__LINE__,
"The number of string length is less than 0 ");
1312 d_str.resize(str_len);
1313 set_value_capacity(str_len);
1314 for (int64_t i = 0; i < str_len; ++i)
1315 d_str[i] = *(
static_cast<string *
> (val) + i);
1321 throw InternalErr(__FILE__, __LINE__,
"Vector::val2buf: bad type");
1325 return (
unsigned int)
width_ll(
true);
1331 auto ret_value = (
unsigned int) val2buf_ll(val,reuse);
1335uint64_t Vector::val2buf_ll(
void *val,
bool reuse)
1340 if (!val &&
length() == 0)
1351 throw InternalErr(__FILE__, __LINE__,
"The incoming pointer does not contain any data.");
1353 switch (d_proto->
type()) {
1367 case dods_float32_c:
1368 case dods_float64_c:
1370 if (d_buf && !reuse)
1371 m_delete_cardinal_data_buffer();
1374 if (!d_buf || !reuse)
1375 m_create_cardinal_data_buffer_for_type(
length_ll());
1379 memcpy(d_buf, val, (uint64_t)
width_ll(
true));
1389 d_str.resize(d_length);
1390 d_capacity = d_length;
1391 for (
int i = 0; i < d_length; ++i)
1392 d_str[i] = *(
static_cast<string *
> (val) + i);
1396 throw InternalErr(__FILE__,__LINE__,
"The number of string length is less than 0 ");
1397 d_str.resize(str_len);
1398 set_value_capacity(str_len);
1399 for (int64_t i = 0; i < str_len; ++i)
1400 d_str[i] = *(
static_cast<string *
> (val) + i);
1406 throw InternalErr(__FILE__, __LINE__,
"Vector::val2buf: bad type");
1410 return (
unsigned int)
width_ll(
true);
1457 throw InternalErr(__FILE__, __LINE__,
"NULL pointer.");
1466 switch (d_proto->
type()) {
1480 case dods_float32_c:
1481 case dods_float64_c:
1483 throw InternalErr(__FILE__, __LINE__,
"Vector::buf2val: Logic error: called when cardinal type data buffer was empty!");
1485 *val =
new char[wid];
1487 memcpy(*val, d_buf, (uint64_t)wid);
1488 return (
unsigned int)wid;
1493 throw InternalErr(__FILE__, __LINE__,
"Vector::buf2val: Logic error: called when string data buffer was empty!");
1495 *val =
new string[d_length];
1497 for (
int i = 0; i < d_length; ++i)
1498 *(
static_cast<string *
> (*val) + i) = d_str[i];
1504 throw InternalErr(__FILE__, __LINE__,
"Vector::buf2val: bad type");
1508uint64_t Vector::buf2val_ll(
void **val)
1513 throw InternalErr(__FILE__, __LINE__,
"NULL pointer.");
1522 switch (d_proto->
type()) {
1536 case dods_float32_c:
1537 case dods_float64_c:
1539 throw InternalErr(__FILE__, __LINE__,
"Vector::buf2val: Logic error: called when cardinal type data buffer was empty!");
1541 *val =
new char[wid];
1543 memcpy(*val, d_buf, (uint64_t)wid);
1544 return (uint64_t)wid;
1549 throw InternalErr(__FILE__, __LINE__,
"Vector::buf2val: Logic error: called when string data buffer was empty!");
1551 *val =
new string[d_length_ll];
1553 for (int64_t i = 0; i < d_length_ll; ++i)
1554 *(
static_cast<string *
> (*val) + i) = d_str[i];
1560 throw InternalErr(__FILE__, __LINE__,
"Vector::buf2val: bad type");
1590void Vector::set_vec_ll(uint64_t i,
BaseType * val)
1592 Vector::set_vec_nocopy_ll(i, val->ptr_duplicate());
1612 if (i >=
static_cast<unsigned int> (d_length))
1613 throw InternalErr(__FILE__, __LINE__,
"Invalid data: index too large.");
1615 throw InternalErr(__FILE__, __LINE__,
"Invalid data: null pointer to BaseType object.");
1616 if (val->type() != d_proto->
type())
1617 throw InternalErr(__FILE__, __LINE__,
"invalid data: type of incoming object does not match *this* vector type.");
1627 if (i >= d_compound_buf.size()) {
1631 d_compound_buf[i] = val;
1634void Vector::set_vec_nocopy_ll(uint64_t i,
BaseType * val)
1640 if (i >=
static_cast<uint64_t
> (
length_ll()))
1641 throw InternalErr(__FILE__, __LINE__,
"Invalid data: index too large.");
1643 throw InternalErr(__FILE__, __LINE__,
"Invalid data: null pointer to BaseType object.");
1644 if (val->type() != d_proto->
type())
1645 throw InternalErr(__FILE__, __LINE__,
"invalid data: type of incoming object does not match *this* vector type.");
1655 if (i >= d_compound_buf.size()) {
1656 vec_resize_ll(d_compound_buf.size() + 100);
1659 d_compound_buf[i] = val;
1679 for (
unsigned int i = 0; i < d_compound_buf.size(); ++i) {
1680 delete d_compound_buf[i];
1681 d_compound_buf[i] = 0;
1685 d_compound_buf.resize(0);
1705uint64_t Vector::get_value_capacity_ll()
const
1707 return d_capacity_ll;
1721 throw InternalErr(__FILE__, __LINE__,
"reserve_value_capacity: Logic error: _var is null!");
1723 switch (d_proto->
type()) {
1737 case dods_float32_c:
1738 case dods_float64_c:
1740 m_create_cardinal_data_buffer_for_type(numElements);
1747 d_str.reserve(numElements);
1749 d_capacity = numElements;
1751 set_value_capacity(numElements);
1755 throw InternalErr(__FILE__, __LINE__,
"reserve_value_capacity: Arrays not supported!");
1758 case dods_structure_c:
1759 case dods_sequence_c:
1762 d_compound_buf.reserve(numElements);
1764 d_capacity = numElements;
1766 set_value_capacity(numElements);
1770 throw InternalErr(__FILE__, __LINE__,
"reserve_value_capacity: Unknown type!");
1797 throw InternalErr(__FILE__, __LINE__,
"reserve_value_capacity: Logic error: _var is null!");
1799 switch (d_proto->
type()) {
1813 case dods_float32_c:
1814 case dods_float64_c:
1816 m_create_cardinal_data_buffer_for_type(numElements);
1823 d_str.reserve(numElements);
1825 d_capacity = numElements;
1827 set_value_capacity(numElements);
1831 throw InternalErr(__FILE__, __LINE__,
"reserve_value_capacity: Arrays not supported!");
1834 case dods_structure_c:
1835 case dods_sequence_c:
1838 d_compound_buf.reserve(numElements);
1840 d_capacity = numElements;
1842 set_value_capacity(numElements);
1846 throw InternalErr(__FILE__, __LINE__,
"reserve_value_capacity: Unknown type!");
1869 d_buf =
new char[numBytes];
1903 static const string funcName =
"set_value_slice_from_row_major_vector:";
1906 Vector& rowMajorData =
const_cast<Vector&
>(rowMajorDataC);
1908 bool typesMatch = rowMajorData.
var() && d_proto && (rowMajorData.var()->type() == d_proto->
type());
1910 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: types do not match so cannot be copied!");
1914 if (!rowMajorData.read_p()) {
1916 funcName +
"Logic error: the Vector to copy data from has !read_p() and should have been read in!");
1920 if (rowMajorData.length_ll() < 0) {
1923 +
"Logic error: the Vector to copy data from has length_ll() < 0 and was probably not initialized!");
1928 if (rowMajorData.get_value_capacity_ll() <
static_cast<uint64_t
>(rowMajorData.length_ll())) {
1931 +
"Logic error: the Vector to copy from has a data capacity less than its length, can't copy!");
1936 if (d_capacity_ll < (startElement + rowMajorData.length_ll())) {
1938 funcName +
"Logic error: the capacity of this Vector cannot hold all the data in the from Vector!");
1942 switch (d_proto->
type()) {
1956 case dods_float32_c:
1957 case dods_float64_c: {
1959 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: this->_buf was unexpectedly null!");
1961 if (!rowMajorData.d_buf) {
1962 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: rowMajorData._buf was unexpectedly null!");
1965 int64_t varWidth = d_proto->width_ll();
1966 char* pFromBuf = rowMajorData.d_buf;
1967 int64_t numBytesToCopy = rowMajorData.width_ll(
true);
1968 char* pIntoBuf = d_buf + (startElement * varWidth);
1969 memcpy(pIntoBuf, pFromBuf, numBytesToCopy);
1976 for (uint64_t i = 0; i < static_cast<uint64_t>(rowMajorData.length_ll()); ++i) {
1977 d_str[startElement + i] = rowMajorData.d_str[i];
1983 case dods_structure_c:
1984 case dods_sequence_c:
1988 funcName +
"Unimplemented method for Vectors of type: array, opaque, structure, sequence or grid.");
1991 throw InternalErr(__FILE__, __LINE__, funcName +
": Unknown type!");
1995 return (uint64_t) rowMajorData.length_ll();
2006template <
typename T>
2007static bool types_match(
Type t, T *cpp_var)
2013 return typeid(cpp_var) ==
typeid(dods_byte*);
2016 return typeid(cpp_var) ==
typeid(dods_int8*);
2018 return typeid(cpp_var) ==
typeid(dods_int16*);
2020 return typeid(cpp_var) ==
typeid(dods_uint16*);
2022 return typeid(cpp_var) ==
typeid(dods_int32*);
2024 return typeid(cpp_var) ==
typeid(dods_uint32*);
2026 return typeid(cpp_var) ==
typeid(dods_int64*);
2028 return typeid(cpp_var) ==
typeid(dods_uint64*);
2030 case dods_float32_c:
2031 return typeid(cpp_var) ==
typeid(dods_float32*);
2032 case dods_float64_c:
2033 return typeid(cpp_var) ==
typeid(dods_float64*);
2041 case dods_structure_c:
2042 case dods_sequence_c:
2052template <
typename T>
2053bool Vector::set_value_worker(T *v,
int sz)
2055 if (!v || !types_match(d_proto->
type() == dods_enum_c ?
static_cast<D4Enum*
>(d_proto)->element_type() : d_proto->
type(), v))
2057 m_set_cardinal_values_internal(v, (int64_t)sz);
2061template <
typename T>
2062bool Vector::set_value_ll_worker(T *v, int64_t sz)
2064 if (!v || !types_match(d_proto->
type() == dods_enum_c ?
static_cast<D4Enum*
>(d_proto)->element_type() : d_proto->
type(), v))
2067 m_set_cardinal_values_internal(v, sz);
2072bool Vector::set_value(dods_byte *val,
int sz)
2074 return set_value_worker(val, sz);
2077bool Vector::set_value(dods_int8 *val,
int sz)
2079 return set_value_worker(val, sz);
2081bool Vector::set_value(dods_int16 *val,
int sz)
2083 return set_value_worker(val, sz);
2085bool Vector::set_value(dods_uint16 *val,
int sz)
2087 return set_value_worker(val, sz);
2089bool Vector::set_value(dods_int32 *val,
int sz)
2091 return set_value_worker(val, sz);
2093bool Vector::set_value(dods_uint32 *val,
int sz)
2095 return set_value_worker(val, sz);
2097bool Vector::set_value(dods_int64 *val,
int sz)
2099 return set_value_worker(val, sz);
2101bool Vector::set_value(dods_uint64 *val,
int sz)
2103 return set_value_worker(val, sz);
2105bool Vector::set_value(dods_float32 *val,
int sz)
2107 return set_value_worker(val, sz);
2109bool Vector::set_value(dods_float64 *val,
int sz)
2111 return set_value_worker(val, sz);
2114bool Vector::set_value_ll(dods_byte *val, int64_t sz)
2116 return set_value_ll_worker(val, sz);
2119bool Vector::set_value_ll(dods_int8 *val, int64_t sz)
2121 return set_value_ll_worker(val, sz);
2123bool Vector::set_value_ll(dods_int16 *val, int64_t sz)
2125 return set_value_ll_worker(val, sz);
2127bool Vector::set_value_ll(dods_uint16 *val, int64_t sz)
2129 return set_value_ll_worker(val, sz);
2131bool Vector::set_value_ll(dods_int32 *val, int64_t sz)
2133 return set_value_ll_worker(val, sz);
2135bool Vector::set_value_ll(dods_uint32 *val, int64_t sz)
2137 return set_value_ll_worker(val, sz);
2139bool Vector::set_value_ll(dods_int64 *val, int64_t sz)
2141 return set_value_ll_worker(val, sz);
2143bool Vector::set_value_ll(dods_uint64 *val, int64_t sz)
2145 return set_value_ll_worker(val, sz);
2147bool Vector::set_value_ll(dods_float32 *val, int64_t sz)
2149 return set_value_ll_worker(val, sz);
2151bool Vector::set_value_ll(dods_float64 *val, int64_t sz)
2153 return set_value_ll_worker(val, sz);
2164bool Vector::set_value(
string *val,
int sz)
2166 if ((
var()->
type() == dods_str_c ||
var()->
type() == dods_url_c) && val) {
2171 set_value_capacity(sz);
2172 for (
int t = 0; t < sz; t++) {
2184bool Vector::set_value_ll(
string *val, int64_t sz)
2186 if ((
var()->
type() == dods_str_c ||
var()->
type() == dods_url_c) && val) {
2191 set_value_capacity(sz);
2192 for (int64_t t = 0; t < sz; t++) {
2205bool Vector::set_value_worker(vector<T> &v,
int sz)
2207 return set_value(v.data(), sz);
2211bool Vector::set_value_ll_worker(vector<T> &v, int64_t sz)
2213 return set_value_ll(v.data(), sz);
2217bool Vector::set_value(vector<dods_byte> &val,
int sz)
2219 return set_value_worker(val, sz);
2221bool Vector::set_value(vector<dods_int8> &val,
int sz)
2223 return set_value_worker(val, sz);
2225bool Vector::set_value(vector<dods_int16> &val,
int sz)
2227 return set_value_worker(val, sz);
2229bool Vector::set_value(vector<dods_uint16> &val,
int sz)
2231 return set_value_worker(val, sz);
2233bool Vector::set_value(vector<dods_int32> &val,
int sz)
2235 return set_value_worker(val, sz);
2237bool Vector::set_value(vector<dods_uint32> &val,
int sz)
2239 return set_value_worker(val, sz);
2241bool Vector::set_value(vector<dods_int64> &val,
int sz)
2243 return set_value_worker(val, sz);
2245bool Vector::set_value(vector<dods_uint64> &val,
int sz)
2247 return set_value_worker(val, sz);
2249bool Vector::set_value(vector<dods_float32> &val,
int sz)
2251 return set_value_worker(val, sz);
2253bool Vector::set_value(vector<dods_float64> &val,
int sz)
2255 return set_value_worker(val, sz);
2258bool Vector::set_value_ll(vector<dods_byte> &val, int64_t sz)
2260 return set_value_ll_worker(val, sz);
2262bool Vector::set_value_ll(vector<dods_int8> &val, int64_t sz)
2264 return set_value_ll_worker(val, sz);
2266bool Vector::set_value_ll(vector<dods_int16> &val, int64_t sz)
2268 return set_value_ll_worker(val, sz);
2270bool Vector::set_value_ll(vector<dods_uint16> &val, int64_t sz)
2272 return set_value_ll_worker(val, sz);
2274bool Vector::set_value_ll(vector<dods_int32> &val, int64_t sz)
2276 return set_value_ll_worker(val, sz);
2278bool Vector::set_value_ll(vector<dods_uint32> &val, int64_t sz)
2280 return set_value_ll_worker(val, sz);
2282bool Vector::set_value_ll(vector<dods_int64> &val, int64_t sz)
2284 return set_value_ll_worker(val, sz);
2286bool Vector::set_value_ll(vector<dods_uint64> &val, int64_t sz)
2288 return set_value_ll_worker(val, sz);
2290bool Vector::set_value_ll(vector<dods_float32> &val, int64_t sz)
2292 return set_value_ll_worker(val, sz);
2294bool Vector::set_value_ll(vector<dods_float64> &val, int64_t sz)
2296 return set_value_ll_worker(val, sz);
2301bool Vector::set_value(vector<string> &val,
int sz)
2303 if (
var()->
type() == dods_str_c ||
var()->
type() == dods_url_c) {
2306 for (
int t = 0; t < sz; t++) {
2318bool Vector::set_value_ll(vector<string> &val, int64_t sz)
2320 if (
var()->
type() == dods_str_c ||
var()->
type() == dods_url_c) {
2323 for (int64_t t = 0; t < sz; t++) {
2355template <
typename T>
2356void Vector::value_worker(vector<unsigned int> *indices, T *b)
const
2360 for (vector<unsigned int>::iterator i = indices->begin(), e = indices->end(); i != e; ++i) {
2361 unsigned long currentIndex = *i;
2362 if(currentIndex > (
unsigned int)
length()){
2364 s <<
"Vector::value() - Subset index[" << i - subsetIndex->begin() <<
"] = " << currentIndex <<
" references a value that is " <<
2365 "outside the bounds of the internal storage [ length()= " <<
length() <<
" ] name: '" <<
name() <<
"'. ";
2366 throw Error(s.str());
2368 b[i - indices->begin()] =
reinterpret_cast<T*
>(d_buf )[currentIndex];
2371 for (
unsigned long i = 0, e = indices->size(); i < e; ++i) {
2372 unsigned long currentIndex = (*indices)[i];
2373 if (currentIndex > (
unsigned int)
length()) {
2375 s <<
"Vector::value() - Subset index[" << i <<
"] = " << currentIndex <<
" references a value that is " <<
2376 "outside the bounds of the internal storage [ length()= " <<
length() <<
" ] name: '" <<
name() <<
"'. ";
2377 throw Error(s.str());
2379 b[i] =
reinterpret_cast<T*
>(d_buf )[currentIndex];
2383template <
typename T>
2384void Vector::value_ll_worker(vector<uint64_t> *indices, T *b)
const
2388 for (vector<unsigned int>::iterator i = indices->begin(), e = indices->end(); i != e; ++i) {
2389 unsigned long currentIndex = *i;
2390 if(currentIndex > (
unsigned int)
length()){
2392 s <<
"Vector::value() - Subset index[" << i - subsetIndex->begin() <<
"] = " << currentIndex <<
" references a value that is " <<
2393 "outside the bounds of the internal storage [ length()= " <<
length() <<
" ] name: '" <<
name() <<
"'. ";
2394 throw Error(s.str());
2396 b[i - indices->begin()] =
reinterpret_cast<T*
>(d_buf )[currentIndex];
2399 for (uint64_t i = 0, e = indices->size(); i < e; ++i) {
2400 uint64_t currentIndex = (*indices)[i];
2401 if (currentIndex > (uint64_t)
length_ll()) {
2403 s <<
"Vector::value() - Subset index[" << i <<
"] = " << currentIndex <<
" references a value that is " <<
2404 "outside the bounds of the internal storage [ length_ll()= " <<
length_ll() <<
" ] name: '" <<
name() <<
"'. ";
2405 throw Error(s.str());
2407 b[i] =
reinterpret_cast<T*
>(d_buf )[currentIndex];
2411void Vector::value(vector<unsigned int> *indices, dods_byte *b)
const { value_worker(indices, b); }
2412void Vector::value(vector<unsigned int> *indices, dods_int8 *b)
const { value_worker(indices, b); }
2413void Vector::value(vector<unsigned int> *indices, dods_int16 *b)
const { value_worker(indices, b); }
2414void Vector::value(vector<unsigned int> *indices, dods_uint16 *b)
const { value_worker(indices, b); }
2415void Vector::value(vector<unsigned int> *indices, dods_int32 *b)
const { value_worker(indices, b); }
2416void Vector::value(vector<unsigned int> *indices, dods_uint32 *b)
const { value_worker(indices, b); }
2417void Vector::value(vector<unsigned int> *indices, dods_int64 *b)
const { value_worker(indices, b); }
2418void Vector::value(vector<unsigned int> *indices, dods_uint64 *b)
const { value_worker(indices, b); }
2419void Vector::value(vector<unsigned int> *indices, dods_float32 *b)
const { value_worker(indices, b); }
2420void Vector::value(vector<unsigned int> *indices, dods_float64 *b)
const { value_worker(indices, b); }
2422void Vector::value_ll(vector<uint64_t> *indices, dods_byte *b)
const { value_ll_worker(indices, b); }
2423void Vector::value_ll(vector<uint64_t> *indices, dods_int8 *b)
const { value_ll_worker(indices, b); }
2424void Vector::value_ll(vector<uint64_t> *indices, dods_int16 *b)
const { value_ll_worker(indices, b); }
2425void Vector::value_ll(vector<uint64_t> *indices, dods_uint16 *b)
const { value_ll_worker(indices, b); }
2426void Vector::value_ll(vector<uint64_t> *indices, dods_int32 *b)
const { value_ll_worker(indices, b); }
2427void Vector::value_ll(vector<uint64_t> *indices, dods_uint32 *b)
const { value_ll_worker(indices, b); }
2428void Vector::value_ll(vector<uint64_t> *indices, dods_int64 *b)
const { value_ll_worker(indices, b); }
2429void Vector::value_ll(vector<uint64_t> *indices, dods_uint64 *b)
const { value_ll_worker(indices, b); }
2430void Vector::value_ll(vector<uint64_t> *indices, dods_float32 *b)
const { value_ll_worker(indices, b); }
2431void Vector::value_ll(vector<uint64_t> *indices, dods_float64 *b)
const { value_ll_worker(indices, b); }
2435template void Vector::value(vector<unsigned int> *indices, dods_byte *b)
const;
2436template void Vector::value(vector<unsigned int> *indices, dods_int8 *b)
const;
2437template void Vector::value(vector<unsigned int> *indices, dods_int16 *b)
const;
2438template void Vector::value(vector<unsigned int> *indices, dods_uint16 *b)
const;
2439template void Vector::value(vector<unsigned int> *indices, dods_int32 *b)
const;
2440template void Vector::value(vector<unsigned int> *indices, dods_uint32 *b)
const;
2441template void Vector::value(vector<unsigned int> *indices, dods_int64 *b)
const;
2442template void Vector::value(vector<unsigned int> *indices, dods_uint64 *b)
const;
2443template void Vector::value(vector<unsigned int> *indices, dods_float32 *b)
const;
2444template void Vector::value(vector<unsigned int> *indices, dods_float64 *b)
const;
2450 unsigned long currentIndex;
2452 if (d_proto->
type() == dods_str_c || d_proto->
type() == dods_url_c){
2453 for(
unsigned long i=0; i<subsetIndex->size() ;++i){
2454 currentIndex = (*subsetIndex)[i] ;
2455 if(currentIndex > (
unsigned int)
length()){
2457 s <<
"Vector::value() - Subset index[" << i <<
"] = " << currentIndex <<
" references a value that is " <<
2458 "outside the bounds of the internal storage [ length()= " <<
length() <<
" ] name: '" <<
name() <<
"'. ";
2459 throw Error(s.str());
2461 b[i] = d_str[currentIndex];
2466void Vector::value_ll(vector<uint64_t> *subsetIndex, vector<string> &b)
const
2468 uint64_t currentIndex;
2470 if (d_proto->
type() == dods_str_c || d_proto->
type() == dods_url_c){
2471 for(uint64_t i=0; i<subsetIndex->size() ;++i){
2472 currentIndex = (*subsetIndex)[i] ;
2473 if(currentIndex > (uint64_t)
length_ll()){
2475 s <<
"Vector::value() - Subset index[" << i <<
"] = " << currentIndex <<
" references a value that is " <<
2476 "outside the bounds of the internal storage [ length_ll()= " <<
length_ll() <<
" ] name: '" <<
name() <<
"'. ";
2477 throw Error(s.str());
2479 b[i] = d_str[currentIndex];
2485template <
typename T>
2486void Vector::value_worker(T *v)
const
2490 if (v && types_match(d_proto->
type() == dods_enum_c ?
static_cast<D4Enum*
>(d_proto)->element_type() : d_proto->
type(), v))
2491 memcpy(v, d_buf,
length_ll() * sizeof(T));
2496void Vector::value(dods_uint16 *b)
const { value_worker(b); }
2498void Vector::value(dods_uint32 *b)
const { value_worker(b); }
2500void Vector::value(dods_uint64 *b)
const { value_worker(b); }
2501void Vector::value(dods_float32 *b)
const { value_worker(b); }
2502void Vector::value(dods_float64 *b)
const { value_worker(b); }
2521 if (d_proto->
type() == dods_str_c || d_proto->
type() == dods_url_c)
2529 void *buffer =
new char[
width_ll(
true)];
2531 memcpy(buffer, d_buf,
width_ll(
true));
2556 Vector::add_var_nocopy(v->ptr_duplicate());
2581 if (!v->name().empty())
2588 DBG(cerr <<
"Vector::add_var: Added variable " << v <<
" ("
2589 << v->name() <<
" " << v->type_name() <<
")" << endl);
2607 if (!v->name().empty())
2614 DBG(cerr <<
"Vector::add_var_no_copy: Added variable " << v <<
" ("
2615 << v->name() <<
" " << v->type_name() <<
")" << endl);
2633 bool has_projected_dap4 =
false;
2639 has_projected_dap4 = prototype()->is_dap4();
2640 if(has_projected_dap4) {
2641 inventory.emplace_back(prototype()->
type_name() +
" " +
FQN());
2643 has_projected_dap4 |=
attributes()->has_dap4_types(
FQN(), inventory);
2645 if(has_projected_dap4) {
2649 return has_projected_dap4;
2667 strm << DapIndent::LMarg <<
"Vector::dump - (" << (
void *)
this <<
")" << endl;
2668 DapIndent::Indent();
2670 strm << DapIndent::LMarg <<
"# elements in vector: " << d_length << endl;
2672 strm << DapIndent::LMarg <<
"base type:" << endl;
2673 DapIndent::Indent();
2674 d_proto->
dump(strm);
2675 DapIndent::UnIndent();
2678 strm << DapIndent::LMarg <<
"base type: not set" << endl;
2680 strm << DapIndent::LMarg <<
"vector contents:" << endl;
2681 DapIndent::Indent();
2682 for (
unsigned i = 0; i < d_compound_buf.size(); ++i) {
2683 if (d_compound_buf[i])
2684 d_compound_buf[i]->dump(strm);
2686 strm << DapIndent::LMarg <<
"vec[" << i <<
"] is null" << endl;
2688 DapIndent::UnIndent();
2689 strm << DapIndent::LMarg <<
"strings:" << endl;
2690 DapIndent::Indent();
2691 for (
unsigned i = 0; i < d_str.size(); i++) {
2692 strm << DapIndent::LMarg << d_str[i] << endl;
2694 DapIndent::UnIndent();
2696 switch (d_proto != 0 ? d_proto->
type() : 0) {
2699 strm << DapIndent::LMarg <<
"_buf: ";
2700 strm.write(d_buf, d_length);
2706 strm << DapIndent::LMarg <<
"_buf: " << (
void *) d_buf << endl;
2711 strm << DapIndent::LMarg <<
"_buf: EMPTY" << endl;
2714 DapIndent::UnIndent();
void AddData(const uint8_t *pData, const uint32_t length)
The basic data type for the DODS DAP types.
virtual bool is_dap4_projected(std::vector< string > &projected_dap4_inventory)
virtual string type_name() const
Returns the type of the class instance as a string.
virtual bool read()
Read data into a local buffer.
virtual string name() const
Returns the name of the class instance.
virtual bool read_p()
Has this variable been read?
virtual unsigned int width(bool constrained=false) const
How many bytes does this variable use Return the number of bytes of storage this variable uses....
virtual void set_read_p(bool state)
Sets the value of the read_p property.
virtual string dataset() const
Returns the name of the dataset used to create this instance.
virtual void set_parent(BaseType *parent)
virtual int element_count(bool leaves=false)
Count the members of constructor types.
void dump(ostream &strm) const override
dumps information about this object
virtual void set_name(const string &n)
Sets the name of the class instance.
virtual bool is_constructor_type() const
Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable.
virtual D4Attributes * attributes()
virtual std::string FQN() const
virtual bool send_p()
Should this variable be sent?
virtual void set_send_p(bool state)
virtual BaseType * ptr_duplicate()=0
virtual unsigned int val2buf(void *val, bool reuse=false)=0
Loads class data.
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 bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=nullptr)
Returns a pointer to a member of a constructor class.
virtual Type type() const
Returns the type of the class instance.
Evaluate a constraint expression.
bool eval_selection(DDS &dds, const std::string &dataset)
Evaluate a boolean-valued constraint expression. This is main method for the evaluator and is called ...
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
Read data from the stream made by D4StreamMarshaller.
A class for error processing.
A class for software fault reporting.
abstract base class used to marshal/serialize dap data objects
abstract base class used to unmarshall/deserialize dap data objects
Holds a one-dimensional collection of DAP2 data types.
virtual void reserve_value_capacity_ll_byte(uint64_t numBytes)
bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false) override
Receive data from the net.
void set_send_p(bool state) override
Indicates that the data is ready to send.
int64_t width_ll(bool constrained=false) const override
Return the number of bytes needed to hold the array data.
void dump(ostream &strm) const override
dumps information about this object
void compute_checksum(Crc32 &checksum) override
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
virtual unsigned int get_value_capacity() const
void set_vec_nocopy(unsigned int i, BaseType *val)
Sets element i to value val. Set the ith element to val. Extend the vector if needed.
void add_var(BaseType *v, Part p=nil) override
Add the BaseType pointer to this constructor type instance.
int length() const override
Returns the number of elements in the vector. Note that some child classes of Vector use the length o...
int64_t length_ll() const override
Get the number of elements in this Vector/Array This version of the function deprecates length() whic...
void set_read_p(bool state) override
Indicates that the data is ready to send.
int element_count(bool leaves) override
Count the members of constructor types.
void set_length_ll(int64_t l) override
Set the number of elements in this Vector/Array This version of the function deprecates set_length() ...
void set_vec(unsigned int i, BaseType *val)
Sets element i to value val.
bool is_dap4_projected(std::vector< std::string > &projected_dap4_inventory) override
void set_name(const std::string &name) override
Sets the name of the class instance.
bool check_semantics(string &msg, bool all=false) override
Compare an object's current state with the semantics of its type.
void intern_data() override
Read data into this variable.
virtual void reserve_value_capacity_ll()
unsigned int val2buf(void *val, bool reuse=false) override
Reads data into the Vector buffer.
BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=nullptr) override
virtual uint64_t set_value_slice_from_row_major_vector(const Vector &rowMajorData, uint64_t startElement)
bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true) override
Serialize a Vector.
virtual void reserve_value_capacity()
unsigned int buf2val(void **val) override
Copies data from the Vector buffer.
void clear_local_data() override
Vector(const string &n, BaseType *v, const Type &t, bool is_dap4=false)
The Vector constructor.
void set_length(int64_t l) override
Sets the length of the vector. This function does not allocate any new space.
top level DAP object to house generic methods
Type
Identifies the data type.
string www2id(const string &in, const string &escape, const string &except)
Part
Names the parts of multi-section constructor data types.