63 d_length = v.d_length;
85 _vec.resize(d_length);
86 for (
int i = 0; i < d_length; ++i) {
91 _vec[i] = v._vec[i]->ptr_duplicate();
103 _capacity = v._capacity;
117 switch (_var->
type()) {
140 cerr <<
"Vector::var: Unrecognized type" << endl;
161 throw InternalErr(__FILE__, __LINE__,
"create_cardinal_data_buffer_for_type: Logic error: _var is null!");
166 throw InternalErr(__FILE__, __LINE__,
"create_cardinal_data_buffer_for_type: incorrectly used on Vector whose type was not a cardinal (simple data types).");
172 unsigned int bytesPerElt = _var->
width();
173 unsigned int bytesNeeded = bytesPerElt * numEltsOfType;
174 _buf =
new char[bytesNeeded];
177 oss <<
"create_cardinal_data_buffer_for_type: new char[] failed to allocate " << bytesNeeded <<
" bytes! Out of memory or too large a buffer required!";
180 _capacity = numEltsOfType;
197 template<
class CardType>
201 throw InternalErr(__FILE__, __LINE__,
"Logic error: Vector::set_cardinal_values_internal() called with negative numElts!");
204 throw InternalErr(__FILE__, __LINE__,
"Logic error: Vector::set_cardinal_values_internal() called with null fromArray!");
208 memcpy(_buf, fromArray, numElts *
sizeof(CardType));
229 BaseType(n, t), d_length(-1), _var(0), _buf(0), _vec(0), _capacity(0)
234 DBG2(cerr <<
"Entering Vector ctor for object: " <<
this << endl);
259 BaseType(n, d, t), d_length(-1), _var(0), _buf(0), _vec(0), _capacity(0)
264 DBG2(cerr <<
"Entering Vector ctor for object: " <<
this << endl);
273 DBG2(cerr <<
"Entering Vector const ctor for object: " <<
this <<
274 endl);
DBG2(cerr <<
"RHS: " << &rhs << endl);
281 DBG2(cerr <<
"Entering ~Vector (" <<
this <<
")" << endl);
289 DBG2(cerr <<
"Exiting ~Vector" << endl);
297 dynamic_cast<BaseType &
> (*this) = rhs;
383 DBG(cerr <<
"Vector::var: Looking for " << n << endl);
389 if (name ==
"" || _var->
name() ==
name) {
421 return _var->
var(name, s);
451 switch (_var->
type()) {
462 unsigned int sz = _var->
width();
463 _var->
val2buf((
char *) _buf + (i * sz));
482 throw Error (
"Vector::var: Unrecognized type");
507 throw InternalErr(__FILE__, __LINE__,
"Cannot get width since *this* object is not holding data.");
545 _vec.resize((l > 0) ? l : 0, 0);
566 DBG(cerr <<
"Vector::intern_data: " <<
name() << endl);
573 switch (_var->
type()) {
594 throw InternalErr(__FILE__, __LINE__,
"Array of Array not supported.");
600 DBG(cerr <<
"Vector::intern_data: found ctor" << endl);
603 if (_vec.capacity() == 0)
604 throw InternalErr(__FILE__, __LINE__,
"The capacity of *this* vector is 0.");
606 for (
int i = 0; i < num; ++i)
612 throw InternalErr(__FILE__, __LINE__,
"Unknown datatype.");
647 switch (_var->
type()) {
662 if (d_str.capacity() == 0)
663 throw InternalErr(__FILE__, __LINE__,
"The capacity of the string vector is 0");
667 for (i = 0; i < num; ++i)
678 if (_vec.capacity() == 0)
679 throw InternalErr(__FILE__, __LINE__,
"The capacity of *this* vector is 0.");
683 for (i = 0; i < num; ++i)
689 throw InternalErr(__FILE__, __LINE__,
"Unknown datatype.");
718 switch (_var->
type()) {
726 if (_buf && !reuse) {
732 DBG(cerr <<
"Vector::deserialize: num = " << num << endl);
733 DBG(cerr <<
"Vector::deserialize: length = " <<
length() << endl);
738 if (num != (
unsigned int)
length())
739 throw InternalErr(__FILE__, __LINE__,
"The server sent declarations and data with mismatched sizes.");
744 DBG(cerr <<
"Vector::deserialize: allocating "
745 <<
width() <<
" bytes for an array of "
754 DBG(cerr <<
"Vector::deserialize: read " << num <<
" elements\n");
765 if (num != (
unsigned int)
length())
766 throw InternalErr(__FILE__, __LINE__,
"The client sent declarations and data with mismatched sizes.");
768 d_str.resize((num > 0) ? num : 0);
771 for (i = 0; i < num; ++i) {
789 if (num != (
unsigned int)
length())
790 throw InternalErr(__FILE__, __LINE__,
"The client sent declarations and data with mismatched sizes.");
794 for (i = 0; i < num; ++i) {
796 _vec[i]->deserialize(um, dds);
802 throw InternalErr(__FILE__, __LINE__,
"Unknown type!");
848 throw InternalErr(__FILE__, __LINE__,
"The incoming pointer does not contain any data.");
850 switch (_var->
type()) {
859 unsigned int array_wid =
width(
true);
860 if (_buf && !reuse) {
868 memcpy(_buf, val, array_wid);
876 d_str.resize(d_length);
877 _capacity = d_length;
878 for (
int i = 0; i < d_length; ++i)
879 d_str[i] = *(static_cast<string *> (val) + i);
885 throw InternalErr(__FILE__, __LINE__,
"Vector::val2buf: bad type");
927 throw InternalErr(__FILE__, __LINE__,
"NULL pointer.");
929 unsigned int wid =
static_cast<unsigned int> (
width(
true ));
935 switch (_var->
type()) {
944 *val =
new char[wid];
948 throw InternalErr(__FILE__, __LINE__,
"Vector::buf2val: Logic error: called when _buf was null!");
951 (void) memcpy(*val, _buf, wid);
958 *val =
new string[d_length];
960 for (
int i = 0; i < d_length; ++i)
961 *(static_cast<string *> (*val) + i) = d_str[i];
967 throw InternalErr(__FILE__, __LINE__,
"Vector::buf2val: bad type");
1000 if (i >= static_cast<unsigned int> (d_length))
1001 throw InternalErr(__FILE__, __LINE__,
"Invalid data: index too large.");
1003 throw InternalErr(__FILE__, __LINE__,
"Invalid data: null pointer to BaseType object.");
1005 throw InternalErr(__FILE__, __LINE__,
"invalid data: type of incoming object does not match *this* vector type.");
1007 if (i >= _vec.capacity())
1029 for (
unsigned int i = 0; i < _vec.size(); ++i) {
1066 throw InternalErr(__FILE__, __LINE__,
"reserve_value_capacity: Logic error: _var is null!");
1068 switch (_var->
type()) {
1085 d_str.reserve(numElements);
1086 _capacity = numElements;
1095 _vec.reserve(numElements);
1096 _capacity = numElements;
1101 throw InternalErr(__FILE__, __LINE__,
"reserve_value_capacity: Unknown type!");
1150 static const string funcName =
"set_value_slice_from_row_major_vector:";
1153 Vector& rowMajorData =
const_cast<Vector&
> (rowMajorDataC);
1155 bool typesMatch = rowMajorData.
var() && _var && (rowMajorData.
var()->
type() == _var->
type());
1157 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: types do not match so cannot be copied!");
1161 if (!rowMajorData.
read_p()) {
1162 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: the Vector to copy data from has !read_p() and should have been read in!");
1166 if (rowMajorData.
length() < 0) {
1167 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: the Vector to copy data from has length() < 0 and was probably not initialized!");
1173 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: the Vector to copy from has a data capacity less than its length, can't copy!");
1178 if (_capacity < (startElement + rowMajorData.
length())) {
1179 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: the capacity of this Vector cannot hold all the data in the from Vector!");
1183 switch (_var->
type()) {
1192 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: this->_buf was unexpectedly null!");
1194 if (!rowMajorData._buf) {
1195 throw InternalErr(__FILE__, __LINE__, funcName +
"Logic error: rowMajorData._buf was unexpectedly null!");
1198 int varWidth = _var->
width();
1199 char* pFromBuf = rowMajorData._buf;
1200 int numBytesToCopy = rowMajorData.
width(
true);
1201 char* pIntoBuf = _buf + (startElement * varWidth);
1202 memcpy(pIntoBuf, pFromBuf, numBytesToCopy);
1209 for (
unsigned int i = 0; i < static_cast<unsigned int> (rowMajorData.
length()); ++i) {
1210 d_str[startElement + i] = rowMajorData.d_str[i];
1221 throw InternalErr(__FILE__, __LINE__, funcName +
"Unimplemented method for Vectors of type: dods_array_c, dods_structure_c, dods_sequence_c and dods_grid_c.");
1226 throw InternalErr(__FILE__, __LINE__, funcName +
": Unknown type!");
1233 return (
unsigned int) rowMajorData.
length();
1241 set_cardinal_values_internal<dods_byte> (val, sz);
1259 set_cardinal_values_internal<dods_int16> (val, sz);
1277 set_cardinal_values_internal<dods_int32> (val, sz);
1295 set_cardinal_values_internal<dods_uint16> (val, sz);
1313 set_cardinal_values_internal<dods_uint32> (val, sz);
1331 set_cardinal_values_internal<dods_float32> (val, sz);
1349 set_cardinal_values_internal<dods_float64> (val, sz);
1369 for (
register int t = 0; t < sz; t++) {
1387 for (
register int t = 0; t < sz; t++) {
1412 unsigned long currentIndex;
1414 for(
unsigned long i=0; i<subsetIndex->size() ;++i){
1415 currentIndex = (*subsetIndex)[i] ;
1416 if(currentIndex> (
unsigned int)
length()){
1418 s <<
"Vector::value() - Subset index[" << i <<
"] = " << currentIndex <<
" references a value that is " <<
1419 "outside the bounds of the internal storage [ length()= " <<
length() <<
" ] name: '" <<
name() <<
"'. ";
1420 throw Error(s.str());
1422 b[i] =
reinterpret_cast<dods_byte*
>(_buf )[currentIndex];
1430 unsigned long currentIndex;
1432 for(
unsigned long i=0; i<subsetIndex->size() ;++i){
1433 currentIndex = (*subsetIndex)[i] ;
1434 if(currentIndex> (
unsigned int)
length()){
1436 s <<
"Vector::value() - Subset index[" << i <<
"] = " << currentIndex <<
" references a value that is " <<
1437 "outside the bounds of the internal storage [ length()= " <<
length() <<
" ] name: '" <<
name() <<
"'. ";
1438 throw Error(s.str());
1440 b[i] =
reinterpret_cast<dods_uint16*
>(_buf )[currentIndex];
1448 unsigned long currentIndex;
1450 for(
unsigned long i=0; i<subsetIndex->size() ;++i){
1451 currentIndex = (*subsetIndex)[i] ;
1452 if(currentIndex> (
unsigned int)
length()){
1454 s <<
"Vector::value() - Subset index[" << i <<
"] = " << currentIndex <<
" references a value that is " <<
1455 "outside the bounds of the internal storage [ length()= " <<
length() <<
" ] name: '" <<
name() <<
"'. ";
1456 throw Error(s.str());
1458 b[i] =
reinterpret_cast<dods_int16*
>(_buf )[currentIndex];
1465 unsigned long currentIndex;
1467 for(
unsigned long i=0; i<subsetIndex->size() ;++i){
1468 currentIndex = (*subsetIndex)[i] ;
1469 if(currentIndex> (
unsigned int)
length()){
1471 s <<
"Vector::value() - Subset index[" << i <<
"] = " << currentIndex <<
" references a value that is " <<
1472 "outside the bounds of the internal storage [ length()= " <<
length() <<
" ] name: '" <<
name() <<
"'. ";
1473 throw Error(s.str());
1475 b[i] =
reinterpret_cast<dods_uint32*
>(_buf )[currentIndex];
1482 unsigned long currentIndex;
1484 for(
unsigned long i=0; i<subsetIndex->size() ;++i){
1485 currentIndex = (*subsetIndex)[i] ;
1486 if(currentIndex> (
unsigned int)
length()){
1488 s <<
"Vector::value() - Subset index[" << i <<
"] = " << currentIndex <<
" references a value that is " <<
1489 "outside the bounds of the internal storage [ length()= " <<
length() <<
" ] name: '" <<
name() <<
"'. ";
1490 throw Error(s.str());
1492 b[i] =
reinterpret_cast<dods_int32*
>(_buf )[currentIndex];
1499 unsigned long currentIndex;
1501 for(
unsigned long i=0; i<subsetIndex->size() ;++i){
1502 currentIndex = (*subsetIndex)[i] ;
1504 if(currentIndex> (
unsigned int)
length()){
1506 s <<
"Vector::value() - Subset index[" << i <<
"] = " << currentIndex <<
" references a value that is " <<
1507 "outside the bounds of the internal storage [ length()= " <<
length() <<
" ] name: '" <<
name() <<
"'. ";
1508 throw Error(s.str());
1514 b[i] =
reinterpret_cast<dods_float32*
>(_buf )[currentIndex];
1523 unsigned long currentIndex;
1525 for(
unsigned long i=0; i<subsetIndex->size() ;++i){
1526 currentIndex = (*subsetIndex)[i] ;
1527 if(currentIndex> (
unsigned int)
length()){
1529 s <<
"Vector::value() - Subset index[" << i <<
"] = " << currentIndex <<
" references a value that is " <<
1530 "outside the bounds of the internal storage [ length()= " <<
length() <<
" ] name: '" <<
name() <<
"'. ";
1531 throw Error(s.str());
1533 b[i] =
reinterpret_cast<dods_float64*
>(_buf )[currentIndex];
1541 unsigned long currentIndex;
1544 for(
unsigned long i=0; i<subsetIndex->size() ;++i){
1545 currentIndex = (*subsetIndex)[i] ;
1546 if(currentIndex > (
unsigned int)
length()){
1548 s <<
"Vector::value() - Subset index[" << i <<
"] = " << currentIndex <<
" references a value that is " <<
1549 "outside the bounds of the internal storage [ length()= " <<
length() <<
" ] name: '" <<
name() <<
"'. ";
1550 throw Error(s.str());
1552 b[i] = d_str[currentIndex];
1636 void *buffer =
new char[
width(
true)];
1638 memcpy(buffer, _buf,
width(
true));
1662 if (v && v->is_dap4_only_type())
1663 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 Vector.");
1684 if (!v->
name().empty())
1691 DBG(cerr <<
"Vector::add_var: Added variable " << v <<
" ("
1699 if (v && v->is_dap4_only_type())
1700 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 Vector.");
1718 if (!v->
name().empty())
1725 DBG(cerr <<
"Vector::add_var: Added variable " << v <<
" ("
1750 if (!v->
name().empty())
1757 DBG(cerr <<
"Vector::add_var: Added variable " << v <<
" ("
1778 strm <<
DapIndent::LMarg <<
"Vector::dump - (" << (
void *)
this <<
")" << endl;
1793 for (
unsigned i = 0; i < _vec.size(); ++i) {
1795 _vec[i]->dump(strm);
1802 for (
unsigned i = 0; i < d_str.size(); i++) {
1807 switch (_var->
type()) {
1810 strm.write(_buf, d_length);
virtual bool read()
Read data into a local buffer.
virtual bool read_p()
Has this variable been read?
virtual void put_int(int val)=0
abstract base class used to unmarshall/deserialize dap data objects
virtual void add_var_nocopy(BaseType *v, Part p=nil)
virtual unsigned int get_value_capacity() const
void set_vec(unsigned int i, BaseType *val)
Sets element i to value val.
Part
Names the parts of multi-section constructor data types.
virtual void set_name(const string &n)
Sets the name of the class instance.
virtual void put_str(const string &val)=0
void _duplicate(const Vector &v)
Holds a one-dimensional collection of DAP2 data types.
virtual bool is_dap2_only_type()
virtual void dump(ostream &strm) const
dumps information about this object
virtual unsigned int width(bool constrained=false)
Returns the width of the data, in bytes.
virtual int length() const
virtual void set_read_p(bool state)
Indicates that the data is ready to send.
virtual void add_var(BaseType *v, Part p=nil)
Add the BaseType pointer to this constructor type instance.
virtual int element_count(bool leaves)
Count the members of constructor types.
virtual unsigned int set_value_slice_from_row_major_vector(const Vector &rowMajorData, unsigned int startElement)
Type
Identifies the data type.
Type type() const
Returns the type of the class instance.
stack< BaseType * > btp_stack
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Serialize a Vector.
virtual void set_parent(BaseType *parent)
A class for software fault reporting.
virtual bool is_constructor_type()
Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable...
string dataset() const
Returns the name of the dataset used to create this instance.
bool eval_selection(DDS &dds, const string &dataset)
Evaluate a boolean-valued constraint expression. This is main method for the evaluator ans is called ...
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
virtual void get_str(string &val)=0
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
Returns a pointer to a member of a constructor class.
string type_name() const
Returns the type of the class instance as a string.
virtual int element_count(bool leaves=false)
Count the members of constructor types.
virtual void set_send_p(bool state)
virtual void dump(ostream &strm) const
dumps information about this object
bool m_is_cardinal_type() const
virtual void reserve_value_capacity()
Vector & operator=(const Vector &rhs)
virtual void set_read_p(bool state)
Sets the value of the read_p property.
void set_cardinal_values_internal(const CardType *fromArray, int numElts)
virtual unsigned int val2buf(void *val, bool reuse=false)
Reads data into the Vector buffer. Thrown if called for Structure, Sequence or Grid.
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
void m_delete_cardinal_data_buffer()
virtual unsigned int val2buf(void *val, bool reuse=false)=0
Loads class data.
string name() const
Returns the name of the class instance.
virtual void put_vector(char *val, int num, Vector &vec)=0
virtual BaseType * ptr_duplicate()=0
string www2id(const string &in, const string &escape, const string &except)
Vector(const string &n, BaseType *v, const Type &t)
The Vector constructor.
Evaluate a constraint expression.
static ostream & LMarg(ostream &strm)
virtual void set_send_p(bool state)
Indicates that the data is ready to send.
unsigned int m_create_cardinal_data_buffer_for_type(unsigned int numEltsOfType)
The basic data type for the DODS DAP types.
abstract base class used to marshal/serialize dap data objects
virtual void set_name(const std::string &name)
virtual unsigned int buf2val(void **val)
virtual void get_int(int &val)=0
virtual unsigned int width(bool constrained=false)
virtual void set_length(int l)
virtual bool set_value(dods_byte *val, int sz)
set the value of a byte array
A class for error processing.
virtual void intern_data(ConstraintEvaluator &eval, DDS &dds)
read data into a variable for later use
virtual void get_vector(char **val, unsigned int &num, Vector &vec)=0
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.