42 {
"$Id: Vector.cc 24281 2011-03-09 00:22:31Z jimg $"
86 for (
int i = 0; i < _length; ++i) {
91 _vec[i] = v._vec[i]->ptr_duplicate();
103 _capacity = v._capacity;
118 switch (_var->
type()) {
141 cerr <<
"Vector::var: Unrecognized type" << endl;
164 "create_cardinal_data_buffer_for_type: Logic error: _var is null!");
170 "create_cardinal_data_buffer_for_type: incorrectly used on Vector whose type was not a cardinal (simple data types).");
176 unsigned int bytesPerElt = _var->
width();
177 unsigned int bytesNeeded = bytesPerElt * numEltsOfType;
178 _buf =
new char[bytesNeeded];
181 oss <<
"create_cardinal_data_buffer_for_type: new char[] failed to allocate " <<
183 " bytes! Out of memory or too large a buffer required!";
186 _capacity = numEltsOfType;
204 template <
class CardType>
210 "Logic error: Vector::set_cardinal_values_internal() called with negative numElts!");
214 "Logic error: Vector::set_cardinal_values_internal() called with null fromArray!");
218 memcpy(_buf, fromArray, numElts *
sizeof(CardType) );
240 :
BaseType(n, t), _length(-1), _var(0), _buf(0), _vec(0), _capacity(0)
245 DBG2(cerr <<
"Entering Vector ctor for object: " <<
this << endl);
270 :
BaseType(n, d, t), _length(-1), _var(0), _buf(0), _vec(0), _capacity(0)
275 DBG2(cerr <<
"Entering Vector ctor for object: " <<
this << endl);
283 DBG2(cerr <<
"Entering Vector const ctor for object: " <<
this <<
285 DBG2(cerr <<
"RHS: " << &rhs << endl);
292 DBG2(cerr <<
"Entering ~Vector (" <<
this <<
")" << endl);
300 DBG2(cerr <<
"Exiting ~Vector" << endl);
308 dynamic_cast <
BaseType & >(*this) = rhs;
386 DBG(cerr <<
"Vector::var: Looking for " << n << endl);
391 if (name ==
"" || _var->
name() ==
name) {
423 return _var->
var(name, s);
457 switch (_var->
type()) {
468 unsigned int sz = _var->
width();
469 _var->
val2buf((
char *) _buf + (i * sz));
488 cerr <<
"Vector::var: Unrecognized type" << endl;
512 "Cannot get width since *this* object is not holding data.");
550 _vec.resize((l > 0) ? l : 0, 0);
572 DBG(cerr <<
"Vector::intern_data: " <<
name() << endl);
579 switch (_var->
type()) {
600 throw InternalErr(__FILE__, __LINE__,
"Array of Array not supported.");
606 DBG(cerr <<
"Vector::intern_data: found ctor" << endl);
609 if (_vec.capacity() == 0)
611 "The capacity of *this* vector is 0.");
613 for (
int i = 0; i < num; ++i)
619 throw InternalErr(__FILE__, __LINE__,
"Unknown datatype.");
656 switch (_var->
type()) {
671 if (d_str.capacity() == 0)
673 "The capacity of the string vector is 0");
677 for (i = 0; i < num; ++i)
688 if (_vec.capacity() == 0)
690 "The capacity of *this* vector is 0.");
694 for (i = 0; i < num; ++i)
700 throw InternalErr(__FILE__, __LINE__,
"Unknown datatype.");
729 switch (_var->
type()) {
737 if (_buf && !reuse) {
743 DBG(cerr <<
"Vector::deserialize: num = " << num << endl);
744 DBG(cerr <<
"Vector::deserialize: length = " <<
length() << endl);
749 if (num != (
unsigned int)
length())
750 throw InternalErr(__FILE__, __LINE__,
"The server sent declarations and data with mismatched sizes.");
755 DBG(cerr <<
"Vector::deserialize: allocating "
756 <<
width() <<
" bytes for an array of "
765 DBG(cerr <<
"Vector::deserialize: read " << num <<
" elements\n");
776 if (num != (
unsigned int)
length())
778 "The client sent declarations and data with mismatched sizes.");
780 d_str.resize((num > 0) ? num : 0);
783 for (i = 0; i < num; ++i) {
801 if (num != (
unsigned int)
length())
802 throw InternalErr(__FILE__, __LINE__,
"The client sent declarations and data with mismatched sizes.");
806 for (i = 0; i < num; ++i) {
808 _vec[i]->deserialize(um, dds);
814 throw InternalErr(__FILE__, __LINE__,
"Unknown type!");
861 "The incoming pointer does not contain any data.");
863 switch (_var->
type()) {
872 unsigned int array_wid =
width();
873 if (_buf && !reuse) {
881 memcpy(_buf, val, array_wid);
889 d_str.resize(_length);
891 for (
int i = 0; i < _length; ++i)
892 d_str[i] = *(static_cast < string * >(val) + i);
898 throw InternalErr(__FILE__, __LINE__,
"Vector::val2buf: bad type");
940 throw InternalErr(__FILE__, __LINE__,
"NULL pointer.");
942 unsigned int wid =
static_cast<unsigned int>(
width());
948 switch (_var->
type()) {
957 *val =
new char[wid];
961 throw InternalErr(__FILE__, __LINE__,
"Vector::buf2val: Logic error: called when _buf was null!");
964 (void) memcpy(*val, _buf, wid);
971 *val =
new string[_length];
973 for (
int i = 0; i < _length; ++i)
974 *(static_cast < string * >(*val) + i) = d_str[i];
980 throw InternalErr(__FILE__, __LINE__,
"Vector::buf2val: bad type");
1013 if (i >= static_cast < unsigned int >(_length))
1015 "Invalid data: index too large.");
1018 "Invalid data: null pointer to BaseType object.");
1021 "invalid data: type of incoming object does not match *this* vector type.");
1023 if (i >= _vec.capacity())
1046 for (
unsigned int i = 0; i < _vec.size(); ++i) {
1088 "reserve_value_capacity: Logic error: _var is null!");
1090 switch (_var->
type()) {
1107 d_str.reserve(numElements);
1108 _capacity = numElements;
1118 _vec.reserve(numElements);
1119 _capacity = numElements;
1124 throw InternalErr(__FILE__, __LINE__,
"reserve_value_capacity: Unknown type!");
1175 static const string funcName =
"set_value_slice_from_row_major_vector:";
1178 Vector& rowMajorData =
const_cast<Vector&
>(rowMajorDataC);
1180 bool typesMatch = rowMajorData.
var() && _var && (rowMajorData.
var()->
type() == _var->
type());
1183 funcName +
"Logic error: types do not match so cannot be copied!");
1187 if (!rowMajorData.
read_p()) {
1189 funcName +
"Logic error: the Vector to copy data from has !read_p() and should have been read in!");
1193 if (rowMajorData.
length() < 0) {
1195 funcName +
"Logic error: the Vector to copy data from has length() < 0 and was probably not initialized!");
1202 funcName +
"Logic error: the Vector to copy from has a data capacity less than its length, can't copy!");
1207 if (_capacity < (startElement + rowMajorData.
length())) {
1209 funcName +
"Logic error: the capacity of this Vector cannot hold all the data in the from Vector!");
1213 switch (_var->
type()) {
1222 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: this->_buf was unexpectedly null!");
1224 if (!rowMajorData._buf) {
1225 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: rowMajorData._buf was unexpectedly null!");
1228 int varWidth = _var->
width();
1229 char* pFromBuf = rowMajorData._buf;
1230 int numBytesToCopy = rowMajorData.
width();
1231 char* pIntoBuf = _buf + (startElement * varWidth);
1241 for (
unsigned int i = 0; i < static_cast<unsigned int>(rowMajorData.
length()); ++i) {
1242 d_str[startElement + i] = rowMajorData.d_str[i];
1254 funcName +
"Unimplemented method for Vectors of type: dods_array_c, dods_structure_c, dods_sequence_c and dods_grid_c.");
1259 throw InternalErr(__FILE__, __LINE__, funcName +
": Unknown type!");
1266 return (
unsigned int)rowMajorData.
length();
1275 set_cardinal_values_internal<dods_byte>(val, sz);
1295 set_cardinal_values_internal<dods_int16>(val, sz);
1315 set_cardinal_values_internal<dods_int32>(val, sz);
1335 set_cardinal_values_internal<dods_uint16>(val, sz);
1355 set_cardinal_values_internal<dods_uint32>(val, sz);
1375 set_cardinal_values_internal<dods_float32>(val, sz);
1395 set_cardinal_values_internal<dods_float64>(val, sz);
1417 for (
register int t = 0; t < sz; t++) {
1436 for (
register int t = 0; t < sz; t++) {
1523 void *buffer =
new char[
width()];
1525 memcpy(buffer, _buf,
width());
1565 if (!v->
name().empty())
1572 DBG(cerr <<
"Vector::add_var: Added variable " << v <<
" ("
1594 << (
void *)
this <<
")" << endl ;
1609 for (
unsigned i = 0; i < _vec.size(); ++i) {
1611 _vec[i]->dump(strm) ;
1618 for (
unsigned i = 0; i < d_str.size(); i++) {
1624 switch( _var->
type() )
1629 strm.write( _buf, _length ) ;