42 {
"$Id: Vector.cc 21976 2010-01-12 17:16:22Z 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 ) ;
virtual bool read()
Read data into a local buffer.
virtual bool read_p()
Has this variable been read?
string name() const
Returns the name of the class instance.
virtual void put_int(int val)=0
abstract base class used to unmarshall/deserialize dap data objects
void set_vec(unsigned int i, BaseType *val)
Sets element i to value val.
virtual void dump(ostream &strm) const
dumps information about this object
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 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 unsigned int width()=0
Returns the size of the class instance data.
void delete_cardinal_data_buffer()
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.
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...
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.
virtual int element_count(bool leaves=false)
Count the members of constructor types.
virtual void set_send_p(bool state)
Type type() const
Returns the type of the class instance.
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.
unsigned int create_cardinal_data_buffer_for_type(unsigned int numEltsOfType)
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.
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
virtual unsigned int val2buf(void *val, bool reuse=false)=0
Loads class data.
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.
virtual unsigned int get_value_capacity() const
Evaluate a constraint expression.
static ostream & LMarg(ostream &strm)
virtual void set_send_p(bool state)
Indicates that the data is ready to send.
The basic data type for the DODS DAP types.
abstract base class used to marshal/serialize dap data objects
string type_name() const
Returns the type of the class instance as a string.
virtual void set_name(const std::string &name)
virtual int length() const
virtual unsigned int buf2val(void **val)
virtual void get_int(int &val)=0
bool is_cardinal_type() const
virtual void set_length(int l)
virtual unsigned int width()
Returns the width of the data, in bytes.
virtual bool set_value(dods_byte *val, int sz)
set the value of a byte array
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 void dump(ostream &strm) const
dumps information about this object
string dataset() const
Returns the name of the dataset used to create this instance.
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.