81 for (
int i = 0; i < _length; ++i) {
86 _vec[i] = v._vec[i]->ptr_duplicate();
98 _capacity = v._capacity;
112 switch (_var->
type()) {
135 cerr <<
"Vector::var: Unrecognized type" << endl;
156 throw InternalErr(__FILE__, __LINE__,
"create_cardinal_data_buffer_for_type: Logic error: _var is null!");
161 throw InternalErr(__FILE__, __LINE__,
"create_cardinal_data_buffer_for_type: incorrectly used on Vector whose type was not a cardinal (simple data types).");
167 unsigned int bytesPerElt = _var->
width();
168 unsigned int bytesNeeded = bytesPerElt * numEltsOfType;
169 _buf =
new char[bytesNeeded];
172 oss <<
"create_cardinal_data_buffer_for_type: new char[] failed to allocate " << bytesNeeded <<
" bytes! Out of memory or too large a buffer required!";
175 _capacity = numEltsOfType;
192 template<
class CardType>
196 throw InternalErr(__FILE__, __LINE__,
"Logic error: Vector::set_cardinal_values_internal() called with negative numElts!");
199 throw InternalErr(__FILE__, __LINE__,
"Logic error: Vector::set_cardinal_values_internal() called with null fromArray!");
203 memcpy(_buf, fromArray, numElts *
sizeof(CardType));
224 BaseType(n, t), _length(-1), _var(0), _buf(0), _vec(0), _capacity(0)
229 DBG2(cerr <<
"Entering Vector ctor for object: " <<
this << endl);
254 BaseType(n, d, t), _length(-1), _var(0), _buf(0), _vec(0), _capacity(0)
259 DBG2(cerr <<
"Entering Vector ctor for object: " <<
this << endl);
268 DBG2(cerr <<
"Entering Vector const ctor for object: " <<
this <<
269 endl);
DBG2(cerr <<
"RHS: " << &rhs << endl);
276 DBG2(cerr <<
"Entering ~Vector (" <<
this <<
")" << endl);
284 DBG2(cerr <<
"Exiting ~Vector" << endl);
292 dynamic_cast<BaseType &
> (*this) = rhs;
369 DBG(cerr <<
"Vector::var: Looking for " << n << endl);
374 if (name ==
"" || _var->
name() ==
name) {
406 return _var->
var(name, s);
436 switch (_var->
type()) {
447 unsigned int sz = _var->
width();
448 _var->
val2buf((
char *) _buf + (i * sz));
467 cerr <<
"Vector::var: Unrecognized type" << endl;
490 throw InternalErr(__FILE__, __LINE__,
"Cannot get width since *this* object is not holding data.");
528 _vec.resize((l > 0) ? l : 0, 0);
549 DBG(cerr <<
"Vector::intern_data: " <<
name() << endl);
556 switch (_var->
type()) {
577 throw InternalErr(__FILE__, __LINE__,
"Array of Array not supported.");
583 DBG(cerr <<
"Vector::intern_data: found ctor" << endl);
586 if (_vec.capacity() == 0)
587 throw InternalErr(__FILE__, __LINE__,
"The capacity of *this* vector is 0.");
589 for (
int i = 0; i < num; ++i)
595 throw InternalErr(__FILE__, __LINE__,
"Unknown datatype.");
630 switch (_var->
type()) {
645 if (d_str.capacity() == 0)
646 throw InternalErr(__FILE__, __LINE__,
"The capacity of the string vector is 0");
650 for (i = 0; i < num; ++i)
661 if (_vec.capacity() == 0)
662 throw InternalErr(__FILE__, __LINE__,
"The capacity of *this* vector is 0.");
666 for (i = 0; i < num; ++i)
672 throw InternalErr(__FILE__, __LINE__,
"Unknown datatype.");
701 switch (_var->
type()) {
709 if (_buf && !reuse) {
715 DBG(cerr <<
"Vector::deserialize: num = " << num << endl);
716 DBG(cerr <<
"Vector::deserialize: length = " <<
length() << endl);
721 if (num != (
unsigned int)
length())
722 throw InternalErr(__FILE__, __LINE__,
"The server sent declarations and data with mismatched sizes.");
727 DBG(cerr <<
"Vector::deserialize: allocating "
728 <<
width() <<
" bytes for an array of "
737 DBG(cerr <<
"Vector::deserialize: read " << num <<
" elements\n");
748 if (num != (
unsigned int)
length())
749 throw InternalErr(__FILE__, __LINE__,
"The client sent declarations and data with mismatched sizes.");
751 d_str.resize((num > 0) ? num : 0);
754 for (i = 0; i < num; ++i) {
772 if (num != (
unsigned int)
length())
773 throw InternalErr(__FILE__, __LINE__,
"The client sent declarations and data with mismatched sizes.");
777 for (i = 0; i < num; ++i) {
779 _vec[i]->deserialize(um, dds);
785 throw InternalErr(__FILE__, __LINE__,
"Unknown type!");
831 throw InternalErr(__FILE__, __LINE__,
"The incoming pointer does not contain any data.");
833 switch (_var->
type()) {
842 unsigned int array_wid =
width();
843 if (_buf && !reuse) {
851 memcpy(_buf, val, array_wid);
859 d_str.resize(_length);
861 for (
int i = 0; i < _length; ++i)
862 d_str[i] = *(static_cast<string *> (val) + i);
868 throw InternalErr(__FILE__, __LINE__,
"Vector::val2buf: bad type");
910 throw InternalErr(__FILE__, __LINE__,
"NULL pointer.");
912 unsigned int wid =
static_cast<unsigned int> (
width());
918 switch (_var->
type()) {
927 *val =
new char[wid];
931 throw InternalErr(__FILE__, __LINE__,
"Vector::buf2val: Logic error: called when _buf was null!");
934 (void) memcpy(*val, _buf, wid);
941 *val =
new string[_length];
943 for (
int i = 0; i < _length; ++i)
944 *(static_cast<string *> (*val) + i) = d_str[i];
950 throw InternalErr(__FILE__, __LINE__,
"Vector::buf2val: bad type");
983 if (i >= static_cast<unsigned int> (_length))
984 throw InternalErr(__FILE__, __LINE__,
"Invalid data: index too large.");
986 throw InternalErr(__FILE__, __LINE__,
"Invalid data: null pointer to BaseType object.");
988 throw InternalErr(__FILE__, __LINE__,
"invalid data: type of incoming object does not match *this* vector type.");
990 if (i >= _vec.capacity())
1012 for (
unsigned int i = 0; i < _vec.size(); ++i) {
1049 throw InternalErr(__FILE__, __LINE__,
"reserve_value_capacity: Logic error: _var is null!");
1051 switch (_var->
type()) {
1068 d_str.reserve(numElements);
1069 _capacity = numElements;
1078 _vec.reserve(numElements);
1079 _capacity = numElements;
1084 throw InternalErr(__FILE__, __LINE__,
"reserve_value_capacity: Unknown type!");
1133 static const string funcName =
"set_value_slice_from_row_major_vector:";
1136 Vector& rowMajorData =
const_cast<Vector&
> (rowMajorDataC);
1138 bool typesMatch = rowMajorData.
var() && _var && (rowMajorData.
var()->
type() == _var->
type());
1140 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: types do not match so cannot be copied!");
1144 if (!rowMajorData.
read_p()) {
1145 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: the Vector to copy data from has !read_p() and should have been read in!");
1149 if (rowMajorData.
length() < 0) {
1150 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: the Vector to copy data from has length() < 0 and was probably not initialized!");
1156 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: the Vector to copy from has a data capacity less than its length, can't copy!");
1161 if (_capacity < (startElement + rowMajorData.
length())) {
1162 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: the capacity of this Vector cannot hold all the data in the from Vector!");
1166 switch (_var->
type()) {
1175 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: this->_buf was unexpectedly null!");
1177 if (!rowMajorData._buf) {
1178 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: rowMajorData._buf was unexpectedly null!");
1181 int varWidth = _var->
width();
1182 char* pFromBuf = rowMajorData._buf;
1183 int numBytesToCopy = rowMajorData.
width();
1184 char* pIntoBuf = _buf + (startElement * varWidth);
1185 memcpy(pIntoBuf, pFromBuf, numBytesToCopy);
1192 for (
unsigned int i = 0; i < static_cast<unsigned int> (rowMajorData.
length()); ++i) {
1193 d_str[startElement + i] = rowMajorData.d_str[i];
1204 throw InternalErr(__FILE__, __LINE__, funcName +
"Unimplemented method for Vectors of type: dods_array_c, dods_structure_c, dods_sequence_c and dods_grid_c.");
1209 throw InternalErr(__FILE__, __LINE__, funcName +
": Unknown type!");
1216 return (
unsigned int) rowMajorData.
length();
1224 set_cardinal_values_internal<dods_byte> (val, sz);
1242 set_cardinal_values_internal<dods_int16> (val, sz);
1260 set_cardinal_values_internal<dods_int32> (val, sz);
1278 set_cardinal_values_internal<dods_uint16> (val, sz);
1296 set_cardinal_values_internal<dods_uint32> (val, sz);
1314 set_cardinal_values_internal<dods_float32> (val, sz);
1332 set_cardinal_values_internal<dods_float64> (val, sz);
1352 for (
register int t = 0; t < sz; t++) {
1370 for (
register int t = 0; t < sz; t++) {
1457 void *buffer =
new char[
width()];
1459 memcpy(buffer, _buf,
width());
1498 if (!v->
name().empty())
1505 DBG(cerr <<
"Vector::add_var: Added variable " << v <<
" ("
1528 if (!v->
name().empty())
1535 DBG(cerr <<
"Vector::add_var: Added variable " << v <<
" ("
1555 strm <<
DapIndent::LMarg <<
"Vector::dump - (" << (
void *)
this <<
")" << endl;
1570 for (
unsigned i = 0; i < _vec.size(); ++i) {
1572 _vec[i]->dump(strm);
1579 for (
unsigned i = 0; i < d_str.size(); i++) {
1584 switch (_var->
type()) {
1587 strm.write(_buf, _length);