libdap++  Updated for version 3.13.3
Vector.cc
Go to the documentation of this file.
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
4 // Access Protocol.
5 
6 // Copyright (c) 2002,2003 OPeNDAP, Inc.
7 // Author: James Gallagher <jgallagher@opendap.org>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24 
25 // (c) COPYRIGHT URI/MIT 1995-1999
26 // Please read the full copyright statement in the file COPYRIGHT_URI.
27 //
28 // Authors:
29 // jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
30 
31 // Implementation for class Vector. This class is the basis for all the
32 // vector-type classes in libdap's <Array, List>.
33 //
34 // 11/21/95 jhrg
35 
36 #include "config.h"
37 
38 #include <cstring>
39 
40 //#define DODS_DEBUG
41 
42 #include <sstream>
43 #include <vector>
44 #include <algorithm>
45 
46 #include "Vector.h"
47 #include "Marshaller.h"
48 #include "UnMarshaller.h"
49 
50 #include "dods-datatypes.h"
51 #include "escaping.h"
52 #include "util.h"
53 #include "debug.h"
54 #include "InternalErr.h"
55 
56 using std::cerr;
57 using std::endl;
58 
59 namespace libdap {
60 
61 void Vector::_duplicate(const Vector & v)
62 {
63  d_length = v.d_length;
64 
65  // _var holds the type of the elements. That is, it holds a BaseType
66  // which acts as a template for the type of each element.
67  if (v._var) {
68  _var = v._var->ptr_duplicate(); // use ptr_duplicate()
69  _var->set_parent(this); // ptr_duplicate does not set d_parent.
70  }
71  else {
72  _var = 0;
73  }
74 
75  // _vec and _buf (further down) hold the values of the Vector. The field
76  // _vec is used when the Vector holds non-numeric data (including strings
77  // although it used to be that was not the case jhrg 2/10/05) while _buf
78  // holds numeric values.
79  if (v._vec.empty()) {
80  _vec = v._vec;
81  }
82  else {
83  // Failure to set the size will make the [] operator barf on the LHS
84  // of the assignment inside the loop.
85  _vec.resize(d_length);
86  for (int i = 0; i < d_length; ++i) {
87  // There's no need to call set_parent() for each element; we
88  // maintain the back pointer using the _var member. These
89  // instances are used to hold _values_ only while the _var
90  // field holds the type of the elements.
91  _vec[i] = v._vec[i]->ptr_duplicate();
92  }
93  }
94 
95  // copy the strings. This copies the values.
96  d_str = v.d_str;
97 
98  // copy numeric values if there are any.
99  _buf = 0; // init to null
100  if (v._buf) // only copy if data present
101  val2buf(v._buf); // store v's value in this's _BUF.
102 
103  _capacity = v._capacity;
104 }
105 
111 {
112  // Not cardinal if no _var at all!
113  if (!_var) {
114  return false;
115  }
116 
117  switch (_var->type()) {
118  case dods_byte_c:
119  case dods_int16_c:
120  case dods_uint16_c:
121  case dods_int32_c:
122  case dods_uint32_c:
123  case dods_float32_c:
124  case dods_float64_c: {
125  return true;
126  break;
127  }
128 
129  // These must be handled differently.
130  case dods_str_c:
131  case dods_url_c:
132  case dods_array_c:
133  case dods_structure_c:
134  case dods_sequence_c:
135  case dods_grid_c:
136  return false;
137  break;
138 
139  default:
140  cerr << "Vector::var: Unrecognized type" << endl;
141  return false;
142  } // switch
143 }
144 
157 unsigned int Vector::m_create_cardinal_data_buffer_for_type(unsigned int numEltsOfType)
158 {
159  // Make sure we HAVE a _var, or we cannot continue.
160  if (!_var) {
161  throw InternalErr(__FILE__, __LINE__, "create_cardinal_data_buffer_for_type: Logic error: _var is null!");
162  }
163 
164  // Make sure we only do this for the correct data types.
165  if (!m_is_cardinal_type()) {
166  throw InternalErr(__FILE__, __LINE__, "create_cardinal_data_buffer_for_type: incorrectly used on Vector whose type was not a cardinal (simple data types).");
167  }
168 
170 
171  // Actually new up the array with enough bytes to hold numEltsOfType of the actual type.
172  unsigned int bytesPerElt = _var->width();
173  unsigned int bytesNeeded = bytesPerElt * numEltsOfType;
174  _buf = new char[bytesNeeded];
175  if (!_buf) {
176  ostringstream oss;
177  oss << "create_cardinal_data_buffer_for_type: new char[] failed to allocate " << bytesNeeded << " bytes! Out of memory or too large a buffer required!";
178  throw InternalErr(__FILE__, __LINE__, oss.str());
179  }
180  _capacity = numEltsOfType;
181  return bytesNeeded;
182 }
183 
186 {
187  if (_buf) {
188  delete[] _buf;
189  _buf = 0;
190  _capacity = 0;
191  }
192 }
193 
197 template<class CardType>
198 void Vector::set_cardinal_values_internal(const CardType* fromArray, int numElts)
199 {
200  if (numElts < 0) {
201  throw InternalErr(__FILE__, __LINE__, "Logic error: Vector::set_cardinal_values_internal() called with negative numElts!");
202  }
203  if (!fromArray) {
204  throw InternalErr(__FILE__, __LINE__, "Logic error: Vector::set_cardinal_values_internal() called with null fromArray!");
205  }
206  set_length(numElts);
208  memcpy(_buf, fromArray, numElts * sizeof(CardType));
209  set_read_p(true);
210 }
211 
228 Vector::Vector(const string & n, BaseType * v, const Type & t) :
229  BaseType(n, t), d_length(-1), _var(0), _buf(0), _vec(0), _capacity(0)
230 {
231  if (v)
232  add_var(v);
233 
234  DBG2(cerr << "Entering Vector ctor for object: " << this << endl);
235  if (_var)
236  _var->set_parent(this);
237 }
238 
258 Vector::Vector(const string & n, const string &d, BaseType * v, const Type & t) :
259  BaseType(n, d, t), d_length(-1), _var(0), _buf(0), _vec(0), _capacity(0)
260 {
261  if (v)
262  add_var(v);
263 
264  DBG2(cerr << "Entering Vector ctor for object: " << this << endl);
265  if (_var)
266  _var->set_parent(this);
267 }
268 
270 Vector::Vector(const Vector & rhs) :
271  BaseType(rhs)
272 {
273  DBG2(cerr << "Entering Vector const ctor for object: " << this <<
274  endl); DBG2(cerr << "RHS: " << &rhs << endl);
275 
276  _duplicate(rhs);
277 }
278 
280 {
281  DBG2(cerr << "Entering ~Vector (" << this << ")" << endl);
282 
283  delete _var;
284  _var = 0;
285 
286  // Clears all buffers
288 
289  DBG2(cerr << "Exiting ~Vector" << endl);
290 }
291 
293 {
294  if (this == &rhs)
295  return *this;
296 
297  dynamic_cast<BaseType &> (*this) = rhs;
298 
299  _duplicate(rhs);
300 
301  return *this;
302 }
303 
309 {
310  return true;
311 }
312 
313 void Vector::set_name(const std::string& name)
314 {
315  BaseType::set_name(name);
316  // We need to set the template variable name as well since
317  // this is what gets output in the dds! Otherwise, there's a mismatch.
318  if (_var) {
319  _var->set_name(name);
320  }
321 }
322 
323 int Vector::element_count(bool leaves)
324 {
325  if (!leaves)
326  return 1;
327  else
328  // var() only works for simple types!
329  return var(0)->element_count(leaves);
330 }
331 
332 // These mfuncs set the _send_p and _read_p fields of BaseType. They differ
333 // from BaseType's version in that they set both the Vector object's copy of
334 // _send_p (_read_p) but also _VAR's copy. This does not matter much when _VAR
335 // is a scalar, but does matter when it is an aggregate.
336 
343 void Vector::set_send_p(bool state)
344 {
345  _var->set_send_p(state);
346  BaseType::set_send_p(state);
347 }
348 
355 void Vector::set_read_p(bool state)
356 {
357  if (_var) {
358  _var->set_read_p(state);
359  }
360  BaseType::set_read_p(state);
361 }
362 
380 BaseType *Vector::var(const string &n, bool exact, btp_stack *s)
381 {
382  string name = www2id(n);
383  DBG(cerr << "Vector::var: Looking for " << n << endl);
384 
385  // If this is a Vector of constructor types, look for 'name' recursively.
386  // Make sure to check for the case where name is the default (the empty
387  // string). 9/1/98 jhrg
388  if (_var->is_constructor_type()) {
389  if (name == "" || _var->name() == name) {
390  if (s)
391  s->push(this);
392  return _var;
393  }
394  else {
395  BaseType * result = _var->var(name, exact, s);
396  if (result && s)
397  s->push(this);
398  return result;
399  }
400  }
401  else {
402  return _var;
403  }
404 }
405 
416 BaseType *Vector::var(const string & n, btp_stack & s)
417 {
418  string name = www2id(n);
419 
420  if (_var->is_constructor_type())
421  return _var->var(name, s);
422  else {
423  s.push((BaseType *) this);
424  return _var;
425  }
426 }
427 
428 // Return a pointer the the BaseType object for element I. If the Vector is
429 // of a cardinal type, store the ith element's value in the BaseType
430 // object. If it is a Vector of a non-cardinal type, then this mfunc returns
431 // _vec[i].
432 //
433 // NB: I defaults to zero.
434 //
435 // Returns: A BaseType pointer to the ith element of the Vector.
436 
448 BaseType *Vector::var(unsigned int i)
449 {
450 
451  switch (_var->type()) {
452  case dods_byte_c:
453  case dods_int16_c:
454  case dods_uint16_c:
455  case dods_int32_c:
456  case dods_uint32_c:
457  case dods_float32_c:
458  case dods_float64_c: {
459  // Transfer the ith value to the BaseType *_var; There are more
460  // efficient ways to get a whole array using buf2val() but this is
461  // an OK way to get a single value or several non-contiguous values.
462  unsigned int sz = _var->width();
463  _var->val2buf((char *) _buf + (i * sz));
464  return _var;
465  break;
466  }
467 
468  case dods_str_c:
469  case dods_url_c:
470  _var->val2buf(&d_str[i]);
471  return _var;
472  break;
473 
474  case dods_array_c:
475  case dods_structure_c:
476  case dods_sequence_c:
477  case dods_grid_c:
478  return _vec[i];
479  break;
480 
481  default:
482  throw Error ("Vector::var: Unrecognized type");
483  //cerr << "Vector::var: Unrecognized type" << endl;
484  break;
485  }
486 
487  return 0;
488 }
489 
490 // Return: The number of bytes required to store the vector `in a C
491 // program'. For an array of cardinal types this is the same as the storage
492 // used by _BUF. For anything else, it is the product of length() and the
493 // element width(). It turns out that both values can be computed the same
494 // way.
495 //
496 // Returns: The number of bytes used to store the vector.
497 
503 unsigned int Vector::width(bool constrained)
504 {
505  // Jose Garcia
506  if (!_var) {
507  throw InternalErr(__FILE__, __LINE__, "Cannot get width since *this* object is not holding data.");
508  }
509 
510  return length() * _var->width(constrained);
511 }
512 
513 // Returns: the number of elements in the vector.
514 
519 int Vector::length() const
520 {
521  return d_length;
522 }
523 
524 // set the number of elements in the vector.
525 //
526 // Returns: void
527 
531 {
532  d_length = l;
533 }
534 
535 // \e l is the number of elements the vector can hold (e.g., if l == 20, then
536 // the vector can hold elements 0, .., 19).
537 
544 {
545  _vec.resize((l > 0) ? l : 0, 0); // Fill with NULLs
546  _capacity = l; // capacity in terms of number of elements.
547 }
548 
565 {
566  DBG(cerr << "Vector::intern_data: " << name() << endl);
567  if (!read_p())
568  read(); // read() throws Error and InternalErr
569 
570  // length() is not capacity; it must be set explicitly in read().
571  int num = length();
572 
573  switch (_var->type()) {
574  case dods_byte_c:
575  case dods_int16_c:
576  case dods_uint16_c:
577  case dods_int32_c:
578  case dods_uint32_c:
579  case dods_float32_c:
580  case dods_float64_c:
581  // For these cases, read() puts the data into _buf, which is what we
582  // need to do 'stuff' with the data.
583  break;
584 
585  case dods_str_c:
586  case dods_url_c:
587  // For these cases, read() will put the data into d_str[], which is
588  // what the transformation classes need.
589  break;
590 
591  case dods_array_c:
592  // I think this is an error since there can never be an Array of
593  // Array.
594  throw InternalErr(__FILE__, __LINE__, "Array of Array not supported.");
595  break;
596 
597  case dods_structure_c:
598  case dods_sequence_c:
599  case dods_grid_c:
600  DBG(cerr << "Vector::intern_data: found ctor" << endl);
601  // For these cases, we need to call read() for each of the 'num'
602  // elements in the '_vec[]' array of BaseType object pointers.
603  if (_vec.capacity() == 0)
604  throw InternalErr(__FILE__, __LINE__, "The capacity of *this* vector is 0.");
605 
606  for (int i = 0; i < num; ++i)
607  _vec[i]->intern_data(eval, dds);
608 
609  break;
610 
611  default:
612  throw InternalErr(__FILE__, __LINE__, "Unknown datatype.");
613  break;
614  }
615 }
616 
628 bool Vector::serialize(ConstraintEvaluator & eval, DDS & dds, Marshaller &m, bool ce_eval)
629 {
630  int i = 0;// TODO move closer to use
631 
632  dds.timeout_on();
633 
634  if (!read_p())
635  read(); // read() throws Error and InternalErr
636 
637 #if EVAL
638  if (ce_eval && !eval.eval_selection(dds, dataset()))
639  return true;
640 #endif
641 
642  dds.timeout_off();
643 
644  // length() is not capacity; it must be set explicitly in read().
645  int num = length();
646 
647  switch (_var->type()) {
648  case dods_byte_c:
649  m.put_vector(_buf, num, *this);
650  break;
651  case dods_int16_c:
652  case dods_uint16_c:
653  case dods_int32_c:
654  case dods_uint32_c:
655  case dods_float32_c:
656  case dods_float64_c:
657  m.put_vector(_buf, num, _var->width(), *this);
658  break;
659 
660  case dods_str_c:
661  case dods_url_c:
662  if (d_str.capacity() == 0)
663  throw InternalErr(__FILE__, __LINE__, "The capacity of the string vector is 0");
664 
665  m.put_int(num);
666 
667  for (i = 0; i < num; ++i)
668  m.put_str(d_str[i]);
669 
670  break;
671 
672  case dods_array_c:
673  case dods_structure_c:
674  case dods_sequence_c:
675  case dods_grid_c:
676  //Jose Garcia
677  // Not setting the capacity of _vec is an internal error.
678  if (_vec.capacity() == 0)
679  throw InternalErr(__FILE__, __LINE__, "The capacity of *this* vector is 0.");
680 
681  m.put_int(num);
682 
683  for (i = 0; i < num; ++i)
684  _vec[i]->serialize(eval, dds, m, false);
685 
686  break;
687 
688  default:
689  throw InternalErr(__FILE__, __LINE__, "Unknown datatype.");
690  break;
691  }
692 
693  return true;
694 }
695 
696 // Read an object from the network and internalize it. For a Vector this is
697 // handled differently for a `cardinal' type. Vectors of Cardinals are
698 // stored using the `C' representations because these objects often are used
699 // to build huge arrays (e.g., an array of 1024 by 1024 bytes). However,
700 // arrays of non-cardinal types are stored as Vectors of the C++ objects or
701 // DAP2 objects (Str and Url are vectors of the string class, Structure, ...,
702 // Grid are vectors of the libdap Structure, ... classes).
703 //
704 // The boolean parameter REUSE determines whether internal storage is reused
705 // or not. If true, the _buf member is assumed to be large enough to hold the
706 // incoming cardinal data and is *not* reallocated. If false, new storage is
707 // allocated. If the internal buffer has not yet been allocated, then this
708 // parameter has no effect (i.e., storage is allocated). This parameter
709 // effects storage for cardinal data only.
710 //
711 // Returns: True is successful, false otherwise.
712 
713 bool Vector::deserialize(UnMarshaller &um, DDS * dds, bool reuse)
714 {
715  unsigned int num;
716  unsigned i = 0;
717 
718  switch (_var->type()) {
719  case dods_byte_c:
720  case dods_int16_c:
721  case dods_uint16_c:
722  case dods_int32_c:
723  case dods_uint32_c:
724  case dods_float32_c:
725  case dods_float64_c:
726  if (_buf && !reuse) {
728  }
729 
730  um.get_int((int &) num);
731 
732  DBG(cerr << "Vector::deserialize: num = " << num << endl);
733  DBG(cerr << "Vector::deserialize: length = " << length() << endl);
734 
735  if (length() == -1)
736  set_length(num);
737 
738  if (num != (unsigned int) length())
739  throw InternalErr(__FILE__, __LINE__, "The server sent declarations and data with mismatched sizes.");
740 
741  if (!_buf) {
742  // Make _buf be large enough for length() elements of _var->type()
744  DBG(cerr << "Vector::deserialize: allocating "
745  << width() << " bytes for an array of "
746  << length() << " " << _var->type_name() << endl);
747  }
748 
749  if (_var->type() == dods_byte_c)
750  um.get_vector((char **) &_buf, num, *this);
751  else
752  um.get_vector((char **) &_buf, num, _var->width(), *this);
753 
754  DBG(cerr << "Vector::deserialize: read " << num << " elements\n");
755 
756  break;
757 
758  case dods_str_c:
759  case dods_url_c:
760  um.get_int((int &) num);
761 
762  if (length() == -1)
763  set_length(num);
764 
765  if (num != (unsigned int) length())
766  throw InternalErr(__FILE__, __LINE__, "The client sent declarations and data with mismatched sizes.");
767 
768  d_str.resize((num > 0) ? num : 0); // Fill with NULLs
769  _capacity = num; // capacity is number of strings we can fit.
770 
771  for (i = 0; i < num; ++i) {
772  string str;
773  um.get_str(str);
774  d_str[i] = str;
775 
776  }
777 
778  break;
779 
780  case dods_array_c:
781  case dods_structure_c:
782  case dods_sequence_c:
783  case dods_grid_c:
784  um.get_int((int &) num);
785 
786  if (length() == -1)
787  set_length(num);
788 
789  if (num != (unsigned int) length())
790  throw InternalErr(__FILE__, __LINE__, "The client sent declarations and data with mismatched sizes.");
791 
792  vec_resize(num);
793 
794  for (i = 0; i < num; ++i) {
795  _vec[i] = _var->ptr_duplicate();
796  _vec[i]->deserialize(um, dds);
797  }
798 
799  break;
800 
801  default:
802  throw InternalErr(__FILE__, __LINE__, "Unknown type!");
803  break;
804  }
805 
806  return false;
807 }
808 
836 unsigned int Vector::val2buf(void *val, bool reuse)
837 {
838  // Jose Garcia
839 
840  // I *think* this method has been mainly designed to be use by read which
841  // is implemented in the surrogate library. Passing NULL as a pointer to
842  // this method will be an error of the creator of the surrogate library.
843  // Even though I recognize the fact that some methods inside libdap++ can
844  // call val2buf, I think by now no coding bugs such as misusing val2buf
845  // will be in libdap++, so it will be an internal error from the
846  // surrogate library.
847  if (!val)
848  throw InternalErr(__FILE__, __LINE__, "The incoming pointer does not contain any data.");
849 
850  switch (_var->type()) {
851  case dods_byte_c:
852  case dods_int16_c:
853  case dods_uint16_c:
854  case dods_int32_c:
855  case dods_uint32_c:
856  case dods_float32_c:
857  case dods_float64_c: {
858  // width(true) returns the size given the constraint
859  unsigned int array_wid = width(true);
860  if (_buf && !reuse) {
862  }
863 
864  if (!_buf) { // First time or no reuse (free'd above)
866  }
867 
868  memcpy(_buf, val, array_wid);
869  break;
870  }
871 
872  case dods_str_c:
873  case dods_url_c: {
874  // Assume val points to an array of C++ string objects. Copy
875  // them into the vector<string> field of this object.
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);
880 
881  break;
882  }
883 
884  default:
885  throw InternalErr(__FILE__, __LINE__, "Vector::val2buf: bad type");
886 
887  }
888 
889  return width(true);
890 }
891 
922 unsigned int Vector::buf2val(void **val)
923 {
924  // Jose Garcia
925  // The same comment in Vector::val2buf applies here!
926  if (!val)
927  throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
928 
929  unsigned int wid = static_cast<unsigned int> (width(true /* constrained */));
930  // This is the width computed using length(). The
931  // length() property is changed when a projection
932  // constraint is applied. Thus this is the number of
933  // bytes in the buffer given the current constraint.
934 
935  switch (_var->type()) {
936  case dods_byte_c:
937  case dods_int16_c:
938  case dods_uint16_c:
939  case dods_int32_c:
940  case dods_uint32_c:
941  case dods_float32_c:
942  case dods_float64_c:
943  if (!*val) {
944  *val = new char[wid];
945  }
946  // avoid bus error if _buf is null and this is called improperly.
947  if (!_buf) {
948  throw InternalErr(__FILE__, __LINE__, "Vector::buf2val: Logic error: called when _buf was null!");
949  }
950 
951  (void) memcpy(*val, _buf, wid);
952 
953  break;
954 
955  case dods_str_c:
956  case dods_url_c: {
957  if (!*val)
958  *val = new string[d_length];
959 
960  for (int i = 0; i < d_length; ++i)
961  *(static_cast<string *> (*val) + i) = d_str[i];
962 
963  break;
964  }
965 
966  default:
967  throw InternalErr(__FILE__, __LINE__, "Vector::buf2val: bad type");
968  return 0;
969  }
970 
971  return wid;
972 }
973 
994 void Vector::set_vec(unsigned int i, BaseType * val)
995 {
996  // Jose Garcia
997  // This is a public method which allows users to set the elements
998  // of *this* vector. Passing an invalid index, a NULL pointer or
999  // mismatching the vector type are internal errors.
1000  if (i >= static_cast<unsigned int> (d_length))
1001  throw InternalErr(__FILE__, __LINE__, "Invalid data: index too large.");
1002  if (!val)
1003  throw InternalErr(__FILE__, __LINE__, "Invalid data: null pointer to BaseType object.");
1004  if (val->type() != _var->type())
1005  throw InternalErr(__FILE__, __LINE__, "invalid data: type of incoming object does not match *this* vector type.");
1006 
1007  if (i >= _vec.capacity())
1008  vec_resize(i + 10);
1009 
1010  _vec[i] = val->ptr_duplicate();
1011 }
1012 
1023 {
1024  if (_buf) {
1025  delete[] _buf;
1026  _buf = 0;
1027  }
1028 
1029  for (unsigned int i = 0; i < _vec.size(); ++i) {
1030  delete _vec[i];
1031  _vec[i] = 0;
1032  }
1033 
1034  // Force memory to be reclaimed.
1035  _vec.resize(0);
1036  d_str.resize(0);
1037 
1038  _capacity = 0;
1039  set_read_p(false);
1040 }
1041 
1049 unsigned int Vector::get_value_capacity() const
1050 {
1051  return _capacity;
1052 }
1053 
1063 void Vector::reserve_value_capacity(unsigned int numElements)
1064 {
1065  if (!_var) {
1066  throw InternalErr(__FILE__, __LINE__, "reserve_value_capacity: Logic error: _var is null!");
1067  }
1068  switch (_var->type()) {
1069  case dods_byte_c:
1070  case dods_int16_c:
1071  case dods_uint16_c:
1072  case dods_int32_c:
1073  case dods_uint32_c:
1074  case dods_float32_c:
1075  case dods_float64_c: {
1076  // Make _buf be the right size and set _capacity
1078  }
1079  break;
1080 
1081  case dods_str_c:
1082  case dods_url_c: {
1083  // Make sure the d_str has enough room for all the strings.
1084  // Technically not needed, but it will speed things up for large arrays.
1085  d_str.reserve(numElements);
1086  _capacity = numElements;
1087  }
1088  break;
1089 
1090  case dods_array_c:
1091  case dods_structure_c:
1092  case dods_sequence_c:
1093  case dods_grid_c: {
1094  // not clear anyone will go this path, but best to be complete.
1095  _vec.reserve(numElements);
1096  _capacity = numElements;
1097  }
1098  break;
1099 
1100  default: {
1101  throw InternalErr(__FILE__, __LINE__, "reserve_value_capacity: Unknown type!");
1102  }
1103  break;
1104 
1105  } // switch
1106 
1107 }
1108 
1115 {
1116  // Use the current length of the vector as the reserve amount.
1118 }
1119 
1148 unsigned int Vector::set_value_slice_from_row_major_vector(const Vector& rowMajorDataC, unsigned int startElement)
1149 {
1150  static const string funcName = "set_value_slice_from_row_major_vector:";
1151 
1152  // semantically const from the caller's viewpoint, but some calls are not syntactic const.
1153  Vector& rowMajorData = const_cast<Vector&> (rowMajorDataC);
1154 
1155  bool typesMatch = rowMajorData.var() && _var && (rowMajorData.var()->type() == _var->type());
1156  if (!typesMatch) {
1157  throw InternalErr(__FILE__, __LINE__, funcName + "Logic error: types do not match so cannot be copied!");
1158  }
1159 
1160  // Make sure the data exists
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!");
1163  }
1164 
1165  // Check this otherwise the static_cast<unsigned int> below will do the wrong thing.
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!");
1168  }
1169 
1170  // The read-in capacity had better be at least the length (the amountt we will copy) or we'll memcpy into bad memory
1171  // I imagine we could copy just the capacity rather than throw, but I really think this implies a problem to be addressed.
1172  if (rowMajorData.get_value_capacity() < static_cast<unsigned int> (rowMajorData.length())) {
1173  throw InternalErr(__FILE__, __LINE__, funcName + "Logic error: the Vector to copy from has a data capacity less than its length, can't copy!");
1174  }
1175 
1176  // Make sure there's enough room in this Vector to store all the elements requested. Again,
1177  // better to throw than just copy what we can since it implies a logic error that needs to be solved.
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!");
1180  }
1181 
1182  // OK, at this point we're pretty sure we can copy the data, but we have to do it differently depending on type.
1183  switch (_var->type()) {
1184  case dods_byte_c:
1185  case dods_int16_c:
1186  case dods_uint16_c:
1187  case dods_int32_c:
1188  case dods_uint32_c:
1189  case dods_float32_c:
1190  case dods_float64_c: {
1191  if (!_buf) {
1192  throw InternalErr(__FILE__, __LINE__, funcName + "Logic error: this->_buf was unexpectedly null!");
1193  }
1194  if (!rowMajorData._buf) {
1195  throw InternalErr(__FILE__, __LINE__, funcName + "Logic error: rowMajorData._buf was unexpectedly null!");
1196  }
1197  // memcpy the data into this, taking care to do ptr arithmetic on bytes and not sizeof(element)
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);
1203  }
1204  break;
1205 
1206  case dods_str_c:
1207  case dods_url_c: {
1208  // Strings need to be copied directly
1209  for (unsigned int i = 0; i < static_cast<unsigned int> (rowMajorData.length()); ++i) {
1210  d_str[startElement + i] = rowMajorData.d_str[i];
1211  }
1212  }
1213  break;
1214 
1215  case dods_array_c:
1216  case dods_structure_c:
1217  case dods_sequence_c:
1218  case dods_grid_c: {
1219  // Not sure that this function will be used for these type of nested objects, so I will throw here.
1220  // TODO impl and test this path if it's ever needed.
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.");
1222  }
1223  break;
1224 
1225  default: {
1226  throw InternalErr(__FILE__, __LINE__, funcName + ": Unknown type!");
1227  }
1228  break;
1229 
1230  } // switch (_var->type())
1231 
1232  // This is how many elements we copied.
1233  return (unsigned int) rowMajorData.length();
1234 }
1235 
1237 
1238 bool Vector::set_value(dods_byte *val, int sz)
1239 {
1240  if (var()->type() == dods_byte_c && val) {
1241  set_cardinal_values_internal<dods_byte> (val, sz);
1242  return true;
1243  }
1244  else {
1245  return false;
1246  }
1247 }
1248 
1250 bool Vector::set_value(vector<dods_byte> &val, int sz)
1251 {
1252  return set_value(&val[0], sz);
1253 }
1254 
1256 bool Vector::set_value(dods_int16 *val, int sz)
1257 {
1258  if (var()->type() == dods_int16_c && val) {
1259  set_cardinal_values_internal<dods_int16> (val, sz);
1260  return true;
1261  }
1262  else {
1263  return false;
1264  }
1265 }
1266 
1268 bool Vector::set_value(vector<dods_int16> &val, int sz)
1269 {
1270  return set_value(&val[0], sz);
1271 }
1272 
1274 bool Vector::set_value(dods_int32 *val, int sz)
1275 {
1276  if (var()->type() == dods_int32_c && val) {
1277  set_cardinal_values_internal<dods_int32> (val, sz);
1278  return true;
1279  }
1280  else {
1281  return false;
1282  }
1283 }
1284 
1286 bool Vector::set_value(vector<dods_int32> &val, int sz)
1287 {
1288  return set_value(&val[0], sz);
1289 }
1290 
1292 bool Vector::set_value(dods_uint16 *val, int sz)
1293 {
1294  if (var()->type() == dods_uint16_c && val) {
1295  set_cardinal_values_internal<dods_uint16> (val, sz);
1296  return true;
1297  }
1298  else {
1299  return false;
1300  }
1301 }
1302 
1304 bool Vector::set_value(vector<dods_uint16> &val, int sz)
1305 {
1306  return set_value(&val[0], sz);
1307 }
1308 
1310 bool Vector::set_value(dods_uint32 *val, int sz)
1311 {
1312  if (var()->type() == dods_uint32_c && val) {
1313  set_cardinal_values_internal<dods_uint32> (val, sz);
1314  return true;
1315  }
1316  else {
1317  return false;
1318  }
1319 }
1320 
1322 bool Vector::set_value(vector<dods_uint32> &val, int sz)
1323 {
1324  return set_value(&val[0], sz);
1325 }
1326 
1329 {
1330  if (var()->type() == dods_float32_c && val) {
1331  set_cardinal_values_internal<dods_float32> (val, sz);
1332  return true;
1333  }
1334  else {
1335  return false;
1336  }
1337 }
1338 
1340 bool Vector::set_value(vector<dods_float32> &val, int sz)
1341 {
1342  return set_value(&val[0], sz);
1343 }
1344 
1347 {
1348  if (var()->type() == dods_float64_c && val) {
1349  set_cardinal_values_internal<dods_float64> (val, sz);
1350  return true;
1351  }
1352  else {
1353  return false;
1354  }
1355 }
1356 
1358 bool Vector::set_value(vector<dods_float64> &val, int sz)
1359 {
1360  return set_value(&val[0], sz);
1361 }
1362 
1364 bool Vector::set_value(string *val, int sz)
1365 {
1366  if ((var()->type() == dods_str_c || var()->type() == dods_url_c) && val) {
1367  d_str.resize(sz);
1368  _capacity = sz;
1369  for (register int t = 0; t < sz; t++) {
1370  d_str[t] = val[t];
1371  }
1372  set_length(sz);
1373  set_read_p(true);
1374  return true;
1375  }
1376  else {
1377  return false;
1378  }
1379 }
1380 
1382 bool Vector::set_value(vector<string> &val, int sz)
1383 {
1384  if (var()->type() == dods_str_c || var()->type() == dods_url_c) {
1385  d_str.resize(sz);
1386  _capacity = sz;
1387  for (register int t = 0; t < sz; t++) {
1388  d_str[t] = val[t];
1389  }
1390  set_length(sz);
1391  set_read_p(true);
1392  return true;
1393  }
1394  else {
1395  return false;
1396  }
1397 }
1399 
1401 
1410 void Vector::value(vector<unsigned int> *subsetIndex, dods_byte *b) const
1411 {
1412  unsigned long currentIndex;
1413 
1414  for(unsigned long i=0; i<subsetIndex->size() ;++i){
1415  currentIndex = (*subsetIndex)[i] ;
1416  if(currentIndex> (unsigned int)length()){
1417  stringstream s;
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());
1421  }
1422  b[i] = reinterpret_cast<dods_byte*>(_buf )[currentIndex]; // I like this version - and it works!
1423  }
1424 }
1425 
1426 
1428 void Vector::value(vector<unsigned int> *subsetIndex, dods_uint16 *b) const
1429 {
1430  unsigned long currentIndex;
1431 
1432  for(unsigned long i=0; i<subsetIndex->size() ;++i){
1433  currentIndex = (*subsetIndex)[i] ;
1434  if(currentIndex> (unsigned int)length()){
1435  stringstream s;
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());
1439  }
1440  b[i] = reinterpret_cast<dods_uint16*>(_buf )[currentIndex]; // I like this version - and it works!
1441  }
1442 }
1443 
1444 
1446 void Vector::value(vector<unsigned int> *subsetIndex, dods_int16 *b) const
1447 {
1448  unsigned long currentIndex;
1449 
1450  for(unsigned long i=0; i<subsetIndex->size() ;++i){
1451  currentIndex = (*subsetIndex)[i] ;
1452  if(currentIndex> (unsigned int)length()){
1453  stringstream s;
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());
1457  }
1458  b[i] = reinterpret_cast<dods_int16*>(_buf )[currentIndex]; // I like this version - and it works!
1459  }
1460 }
1461 
1463 void Vector::value(vector<unsigned int> *subsetIndex, dods_uint32 *b) const
1464 {
1465  unsigned long currentIndex;
1466 
1467  for(unsigned long i=0; i<subsetIndex->size() ;++i){
1468  currentIndex = (*subsetIndex)[i] ;
1469  if(currentIndex> (unsigned int)length()){
1470  stringstream s;
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());
1474  }
1475  b[i] = reinterpret_cast<dods_uint32*>(_buf )[currentIndex]; // I like this version - and it works!
1476  }
1477 }
1478 
1480 void Vector::value(vector<unsigned int> *subsetIndex, dods_int32 *b) const
1481 {
1482  unsigned long currentIndex;
1483 
1484  for(unsigned long i=0; i<subsetIndex->size() ;++i){
1485  currentIndex = (*subsetIndex)[i] ;
1486  if(currentIndex> (unsigned int)length()){
1487  stringstream s;
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());
1491  }
1492  b[i] = reinterpret_cast<dods_int32*>(_buf )[currentIndex]; // I like this version - and it works!
1493  }
1494 }
1495 
1497 void Vector::value(vector<unsigned int> *subsetIndex, dods_float32 *b) const
1498 {
1499  unsigned long currentIndex;
1500 
1501  for(unsigned long i=0; i<subsetIndex->size() ;++i){
1502  currentIndex = (*subsetIndex)[i] ;
1503  //cerr << "currentIndex: " << currentIndex << endl;
1504  if(currentIndex> (unsigned int)length()){
1505  stringstream s;
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());
1509  }
1510  // b[i] = *reinterpret_cast<dods_float32*>(_buf ) + currentIndex; // BROKEN
1511  // b[i] = *(reinterpret_cast<dods_float32*>(_buf ) + currentIndex); // Works but I like other forms
1512  // b[i] = ((dods_float32*)_buf )[currentIndex]; // Works but isn't as 'safe'
1513 
1514  b[i] = reinterpret_cast<dods_float32*>(_buf )[currentIndex]; // I like this version - and it works!
1515 
1516  //cerr << "b[" << i << "]=" << b[i] << endl;
1517  }
1518 }
1519 
1521 void Vector::value(vector<unsigned int> *subsetIndex, dods_float64 *b) const
1522 {
1523  unsigned long currentIndex;
1524 
1525  for(unsigned long i=0; i<subsetIndex->size() ;++i){
1526  currentIndex = (*subsetIndex)[i] ;
1527  if(currentIndex> (unsigned int)length()){
1528  stringstream s;
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());
1532  }
1533  b[i] = reinterpret_cast<dods_float64*>(_buf )[currentIndex]; // I like this version - and it works!
1534  }
1535 }
1536 
1537 
1539 void Vector::value(vector<unsigned int> *subsetIndex, vector<string> &b) const
1540 {
1541  unsigned long currentIndex;
1542 
1543  if (_var->type() == dods_str_c || _var->type() == dods_url_c){
1544  for(unsigned long i=0; i<subsetIndex->size() ;++i){
1545  currentIndex = (*subsetIndex)[i] ;
1546  if(currentIndex > (unsigned int)length()){
1547  stringstream s;
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());
1551  }
1552  b[i] = d_str[currentIndex];
1553  }
1554  }
1555 }
1556 
1557 
1558 
1559 
1560 
1561 
1562 
1570 void Vector::value(dods_byte *b) const
1571 {
1572  if (b && _var->type() == dods_byte_c) {
1573  memcpy(b, _buf, length() * sizeof(dods_byte));
1574  }
1575 }
1576 
1579 {
1580  if (b && _var->type() == dods_uint16_c) {
1581  memcpy(b, _buf, length() * sizeof(dods_uint16));
1582  }
1583 }
1584 
1587 {
1588  if (b && _var->type() == dods_int16_c) {
1589  memcpy(b, _buf, length() * sizeof(dods_int16));
1590  }
1591 }
1592 
1595 {
1596  if (b && _var->type() == dods_uint32_c) {
1597  memcpy(b, _buf, length() * sizeof(dods_uint32));
1598  }
1599 }
1600 
1603 {
1604  if (b && _var->type() == dods_int32_c) {
1605  memcpy(b, _buf, length() * sizeof(dods_int32));
1606  }
1607 }
1608 
1611 {
1612  if (b && _var->type() == dods_float32_c) {
1613  memcpy(b, _buf, length() * sizeof(dods_float32));
1614  }
1615 }
1616 
1619 {
1620  if (b && _var->type() == dods_float64_c) {
1621  memcpy(b, _buf, length() * sizeof(dods_float64));
1622  }
1623 }
1624 
1626 void Vector::value(vector<string> &b) const
1627 {
1628  if (_var->type() == dods_str_c || _var->type() == dods_url_c)
1629  b = d_str;
1630 }
1631 
1635 {
1636  void *buffer = new char[width(true)];
1637 
1638  memcpy(buffer, _buf, width(true));
1639 
1640  return buffer;
1641 }
1643 
1660 {
1661 #if 0
1662  if (v && v->is_dap4_only_type())
1663  throw InternalErr(__FILE__, __LINE__, "Attempt to add a DAP4 type to a DAP2 Vector.");
1664 #endif
1665  // Delete the current template variable
1666  if (_var) {
1667  delete _var;
1668  _var = 0;
1669  }
1670 
1671  // if 'v' is null, just set _var to null and exit.
1672  if (!v) {
1673  _var = 0;
1674  }
1675  else {
1676  // Jose Garcia
1677  // By getting a copy of this object to be assigned to _var
1678  // we let the owner of 'v' to deallocate it as necessary.
1679  _var = v->ptr_duplicate();
1680 
1681  // If 'v' has a name, use it as the name of the array. If it *is*
1682  // empty, then make sure to copy the array's name to the template
1683  // so that software which uses the template's name will still work.
1684  if (!v->name().empty())
1685  set_name(v->name());
1686  else
1687  _var->set_name(name());
1688 
1689  _var->set_parent(this); // Vector --> child
1690 
1691  DBG(cerr << "Vector::add_var: Added variable " << v << " ("
1692  << v->name() << " " << v->type_name() << ")" << endl);
1693  }
1694 }
1695 
1697 {
1698 #if 0
1699  if (v && v->is_dap4_only_type())
1700  throw InternalErr(__FILE__, __LINE__, "Attempt to add a DAP4 type to a DAP2 Vector.");
1701 #endif
1702  // Delete the current template variable
1703  if (_var) {
1704  delete _var;
1705  _var = 0;
1706  }
1707 
1708  // if 'v' is null, just set _var to null and exit.
1709  if (!v) {
1710  _var = 0;
1711  }
1712  else {
1713  _var = v;
1714 
1715  // If 'v' has a name, use it as the name of the array. If it *is*
1716  // empty, then make sure to copy the array's name to the template
1717  // so that software which uses the template's name will still work.
1718  if (!v->name().empty())
1719  set_name(v->name());
1720  else
1721  _var->set_name(name());
1722 
1723  _var->set_parent(this); // Vector --> child
1724 
1725  DBG(cerr << "Vector::add_var: Added variable " << v << " ("
1726  << v->name() << " " << v->type_name() << ")" << endl);
1727  }
1728 }
1729 
1730 #if 0
1731 // branch version
1733 {
1734  // Delete the current template variable
1735  if (_var) {
1736  delete _var;
1737  _var = 0;
1738  }
1739 
1740  // if 'v' is null, just set _var to null and exit.
1741  if (!v) {
1742  _var = 0;
1743  }
1744  else {
1745  _var = v;
1746 
1747  // If 'v' has a name, use it as the name of the array. If it *is*
1748  // empty, then make sure to copy the array's name to the template
1749  // so that software which uses the template's name will still work.
1750  if (!v->name().empty())
1751  set_name(v->name());
1752  else
1753  _var->set_name(name());
1754 
1755  _var->set_parent(this); // Vector --> child
1756 
1757  DBG(cerr << "Vector::add_var: Added variable " << v << " ("
1758  << v->name() << " " << v->type_name() << ")" << endl);
1759  }
1760 }
1761 #endif
1762 
1763 bool Vector::check_semantics(string & msg, bool)
1764 {
1765  return BaseType::check_semantics(msg);
1766 }
1767 
1776 void Vector::dump(ostream &strm) const
1777 {
1778  strm << DapIndent::LMarg << "Vector::dump - (" << (void *) this << ")" << endl;
1780  BaseType::dump(strm);
1781  strm << DapIndent::LMarg << "# elements in vector: " << d_length << endl;
1782  if (_var) {
1783  strm << DapIndent::LMarg << "base type:" << endl;
1785  _var->dump(strm);
1787  }
1788  else {
1789  strm << DapIndent::LMarg << "base type: not set" << endl;
1790  }
1791  strm << DapIndent::LMarg << "vector contents:" << endl;
1793  for (unsigned i = 0; i < _vec.size(); ++i) {
1794  if (_vec[i])
1795  _vec[i]->dump(strm);
1796  else
1797  strm << DapIndent::LMarg << "vec[" << i << "] is null" << endl;
1798  }
1800  strm << DapIndent::LMarg << "strings:" << endl;
1802  for (unsigned i = 0; i < d_str.size(); i++) {
1803  strm << DapIndent::LMarg << d_str[i] << endl;
1804  }
1806  if (_buf) {
1807  switch (_var->type()) {
1808  case dods_byte_c: {
1809  strm << DapIndent::LMarg << "_buf: ";
1810  strm.write(_buf, d_length);
1811  strm << endl;
1812  }
1813  break;
1814  default: {
1815  strm << DapIndent::LMarg << "_buf: " << (void *) _buf << endl;
1816  }
1817  break;
1818  }
1819  }
1820  else {
1821  strm << DapIndent::LMarg << "_buf: EMPTY" << endl;
1822  }
1824 }
1825 
1826 } // namespace libdap
1827 
virtual bool read()
Read data into a local buffer.
Definition: BaseType.cc:923
virtual bool read_p()
Has this variable been read?
Definition: BaseType.cc:579
virtual void put_int(int val)=0
static void UnIndent()
Definition: DapIndent.cc:51
abstract base class used to unmarshall/deserialize dap data objects
Definition: UnMarshaller.h:54
virtual void add_var_nocopy(BaseType *v, Part p=nil)
Definition: Vector.cc:1696
virtual unsigned int get_value_capacity() const
Definition: Vector.cc:1049
uint8_t dods_byte
void set_vec(unsigned int i, BaseType *val)
Sets element i to value val.
Definition: Vector.cc:994
Part
Names the parts of multi-section constructor data types.
Definition: BaseType.h:95
virtual void set_name(const string &n)
Sets the name of the class instance.
Definition: BaseType.cc:261
virtual void put_str(const string &val)=0
void _duplicate(const Vector &v)
Definition: Vector.cc:61
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:78
virtual bool is_dap2_only_type()
Definition: Vector.cc:308
virtual void dump(ostream &strm) const
dumps information about this object
Definition: Vector.cc:1776
virtual unsigned int width(bool constrained=false)
Returns the width of the data, in bytes.
Definition: Vector.cc:503
void clear_local_data()
Definition: Vector.cc:1022
virtual int length() const
Definition: Vector.cc:519
virtual void set_read_p(bool state)
Indicates that the data is ready to send.
Definition: Vector.cc:355
virtual void add_var(BaseType *v, Part p=nil)
Add the BaseType pointer to this constructor type instance.
Definition: Vector.cc:1659
virtual int element_count(bool leaves)
Count the members of constructor types.
Definition: Vector.cc:323
virtual void * value()
Definition: Vector.cc:1634
void timeout_off()
Definition: DDS.cc:862
virtual unsigned int set_value_slice_from_row_major_vector(const Vector &rowMajorData, unsigned int startElement)
Definition: Vector.cc:1148
Type
Identifies the data type.
Definition: BaseType.h:137
Type type() const
Returns the type of the class instance.
Definition: BaseType.cc:282
uint16_t dods_uint16
#define DBG2(x)
Definition: debug.h:73
stack< BaseType * > btp_stack
Definition: BaseType.h:233
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Serialize a Vector.
Definition: Vector.cc:628
virtual void set_parent(BaseType *parent)
Definition: BaseType.cc:770
A class for software fault reporting.
Definition: InternalErr.h:64
virtual bool is_constructor_type()
Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable...
Definition: BaseType.cc:449
string dataset() const
Returns the name of the dataset used to create this instance.
Definition: BaseType.cc:275
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)
Definition: Vector.cc:380
virtual void get_str(string &val)=0
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
Definition: Vector.cc:713
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
Returns a pointer to a member of a constructor class.
Definition: BaseType.cc:795
#define DBG(x)
Definition: debug.h:58
string type_name() const
Returns the type of the class instance as a string.
Definition: BaseType.cc:296
virtual int element_count(bool leaves=false)
Count the members of constructor types.
Definition: BaseType.cc:542
virtual void set_send_p(bool state)
Definition: BaseType.cc:652
double dods_float64
static void Indent()
Definition: DapIndent.cc:45
virtual void dump(ostream &strm) const
dumps information about this object
Definition: BaseType.cc:230
bool m_is_cardinal_type() const
Definition: Vector.cc:110
uint32_t dods_uint32
virtual void reserve_value_capacity()
Definition: Vector.cc:1114
Vector & operator=(const Vector &rhs)
Definition: Vector.cc:292
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Definition: BaseType.cc:618
void set_cardinal_values_internal(const CardType *fromArray, int numElts)
Definition: Vector.cc:198
virtual ~Vector()
Definition: Vector.cc:279
virtual unsigned int val2buf(void *val, bool reuse=false)
Reads data into the Vector buffer. Thrown if called for Structure, Sequence or Grid.
Definition: Vector.cc:836
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
Definition: Vector.cc:1763
void m_delete_cardinal_data_buffer()
Definition: Vector.cc:185
virtual unsigned int val2buf(void *val, bool reuse=false)=0
Loads class data.
string name() const
Returns the name of the class instance.
Definition: BaseType.cc:254
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)
Definition: escaping.cc:220
void timeout_on()
Definition: DDS.cc:854
Vector(const string &n, BaseType *v, const Type &t)
The Vector constructor.
Definition: Vector.cc:228
Evaluate a constraint expression.
static ostream & LMarg(ostream &strm)
Definition: DapIndent.cc:80
virtual void set_send_p(bool state)
Indicates that the data is ready to send.
Definition: Vector.cc:343
int16_t dods_int16
unsigned int m_create_cardinal_data_buffer_for_type(unsigned int numEltsOfType)
Definition: Vector.cc:157
The basic data type for the DODS DAP types.
Definition: BaseType.h:199
abstract base class used to marshal/serialize dap data objects
Definition: Marshaller.h:53
virtual void set_name(const std::string &name)
Definition: Vector.cc:313
virtual unsigned int buf2val(void **val)
Definition: Vector.cc:922
virtual void get_int(int &val)=0
virtual unsigned int width(bool constrained=false)
Definition: BaseType.cc:1218
virtual void set_length(int l)
Definition: Vector.cc:530
virtual bool set_value(dods_byte *val, int sz)
set the value of a byte array
Definition: Vector.cc:1238
A class for error processing.
Definition: Error.h:90
virtual void intern_data(ConstraintEvaluator &eval, DDS &dds)
read data into a variable for later use
Definition: Vector.cc:564
void vec_resize(int l)
Definition: Vector.cc:543
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.
Definition: BaseType.cc:1153
int32_t dods_int32