libdap++  Updated for version 3.11.7
Vector.h
Go to the documentation of this file.
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
5 // Access Protocol.
6 
7 // Copyright (c) 2002,2003 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 // (c) COPYRIGHT URI/MIT 1995-1999
27 // Please read the full copyright statement in the file COPYRIGHT_URI.
28 //
29 // Authors:
30 // jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
31 
32 // This is the interface definition file for the abstract class
33 // Vector. Vector is the parent class for List and Array.
34 
35 #ifndef _vector_h
36 #define _vector_h 1
37 
38 #ifndef _basetype_h
39 #include "BaseType.h"
40 #endif
41 
42 #ifndef _dds_h
43 #include "DDS.h"
44 #endif
45 
46 #ifndef constraint_evaluator_h
47 #include "ConstraintEvaluator.h"
48 #endif
49 
50 namespace libdap
51 {
52 
78 class Vector: public BaseType
79 {
80 private:
81  int _length; // number of elements in the vector
82  BaseType *_var; // base type of the Vector
83 
84  // _buf was a pointer to void; delete[] complained. 6/4/2001 jhrg
85  char *_buf; // array which holds cardinal data
86  vector<string> d_str; // special storage for strings. jhrg 2/11/05
87  vector<BaseType *> _vec; // array for other data
88 
89  // the number of elements we have allocated memory to store.
90  // This should be either the sizeof(buf)/width() for cardinal data
91  // or the capacity of d_str for strings or capacity of _vec.
92  unsigned int _capacity;
93 
94 protected:
95  // This function copies the private members of Vector.
96  void _duplicate(const Vector &v);
97 
98  bool is_cardinal_type() const;
99  unsigned int create_cardinal_data_buffer_for_type(unsigned int numEltsOfType);
101 
102  template <class CardType> void set_cardinal_values_internal(const CardType* fromArray, int numElts);
103 
104 public:
105  Vector(const string &n, BaseType *v, const Type &t);
106  Vector(const string &n, const string &d, BaseType *v, const Type &t);
107  Vector(const Vector &rhs);
108 
109  virtual ~Vector();
110 
111  Vector &operator=(const Vector &rhs);
112  virtual BaseType *ptr_duplicate() = 0;
113 
114  virtual void set_name(const std::string& name);
115 
116  virtual int element_count(bool leaves);
117 
118  virtual void set_send_p(bool state);
119 
120  virtual void set_read_p(bool state);
121 
122  virtual unsigned int width();
123 
124  virtual int length() const;
125 
126  virtual void set_length(int l);
127 
128  virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
129  virtual bool serialize(ConstraintEvaluator &eval, DDS &dds,
130  Marshaller &m, bool ce_eval = true);
131  virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
132 
133  virtual unsigned int val2buf(void *val, bool reuse = false);
134  virtual unsigned int buf2val(void **val);
135 
136  void set_vec(unsigned int i, BaseType *val);
137 
138  void vec_resize(int l);
139 
140  void clear_local_data();
141 
142  virtual unsigned int get_value_capacity() const;
143  virtual void reserve_value_capacity(unsigned int numElements);
144  virtual void reserve_value_capacity();
145 
146  virtual unsigned int set_value_slice_from_row_major_vector
147  (const Vector& rowMajorData, unsigned int startElement);
148 
149  virtual bool set_value(dods_byte *val, int sz);
150  virtual bool set_value(vector<dods_byte> &val, int sz);
151  virtual bool set_value(dods_int16 *val, int sz);
152  virtual bool set_value(vector<dods_int16> &val, int sz);
153  virtual bool set_value(dods_uint16 *val, int sz);
154  virtual bool set_value(vector<dods_uint16> &val, int sz);
155  virtual bool set_value(dods_int32 *val, int sz);
156  virtual bool set_value(vector<dods_int32> &val, int sz);
157  virtual bool set_value(dods_uint32 *val, int sz);
158  virtual bool set_value(vector<dods_uint32> &val, int sz);
159  virtual bool set_value(dods_float32 *val, int sz);
160  virtual bool set_value(vector<dods_float32> &val, int sz);
161  virtual bool set_value(dods_float64 *val, int sz);
162  virtual bool set_value(vector<dods_float64> &val, int sz);
163  virtual bool set_value(string *val, int sz);
164  virtual bool set_value(vector<string> &val, int sz);
165 
166  virtual void value(dods_byte *b) const;
167  virtual void value(dods_int16 *b) const;
168  virtual void value(dods_uint16 *b) const;
169  virtual void value(dods_int32 *b) const;
170  virtual void value(dods_uint32 *b) const;
171  virtual void value(dods_float32 *b) const;
172  virtual void value(dods_float64 *b) const;
173  virtual void value(vector<string> &b) const;
174 
175  virtual void *value();
176 
177  virtual BaseType *var(const string &name = "", bool exact_match = true,
178  btp_stack *s = 0);
179  virtual BaseType *var(const string &name, btp_stack &s);
180  virtual BaseType *var(unsigned int i);
181 
182  virtual void add_var(BaseType *v, Part p = nil);
183  virtual void add_var_nocopy(BaseType *v, Part p = nil);
184  virtual bool check_semantics(string &msg, bool all = false);
185 
186  virtual void dump(ostream &strm) const ;
187 };
188 
189 } // namespace libdap
190 
191 #endif /* _vector_h */
bool is_cardinal_type() const
Definition: Vector.cc:105
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:1510
virtual unsigned int get_value_capacity() const
Definition: Vector.cc:1032
uint8_t dods_byte
void set_vec(unsigned int i, BaseType *val)
Sets element i to value val.
Definition: Vector.cc:977
Part
Names the parts of multi-section constructor data types.
Definition: BaseType.h:102
void _duplicate(const Vector &v)
Definition: Vector.cc:56
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:78
virtual void dump(ostream &strm) const
dumps information about this object
Definition: Vector.cc:1553
void clear_local_data()
Definition: Vector.cc:1005
virtual int length() const
Definition: Vector.cc:502
virtual void set_read_p(bool state)
Indicates that the data is ready to send.
Definition: Vector.cc:341
virtual void add_var(BaseType *v, Part p=nil)
Add the BaseType pointer to this constructor type instance.
Definition: Vector.cc:1477
void delete_cardinal_data_buffer()
Definition: Vector.cc:180
virtual int element_count(bool leaves)
Count the members of constructor types.
Definition: Vector.cc:309
virtual void * value()
Definition: Vector.cc:1455
virtual unsigned int set_value_slice_from_row_major_vector(const Vector &rowMajorData, unsigned int startElement)
Definition: Vector.cc:1131
Type
Identifies the data type.
Definition: BaseType.h:135
uint16_t dods_uint16
stack< BaseType * > btp_stack
Definition: BaseType.h:218
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Serialize a Vector.
Definition: Vector.cc:611
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
Definition: Vector.cc:366
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
Definition: Vector.cc:696
double dods_float64
uint32_t dods_uint32
virtual void reserve_value_capacity()
Definition: Vector.cc:1097
Vector & operator=(const Vector &rhs)
Definition: Vector.cc:287
unsigned int create_cardinal_data_buffer_for_type(unsigned int numEltsOfType)
Definition: Vector.cc:152
void set_cardinal_values_internal(const CardType *fromArray, int numElts)
Definition: Vector.cc:193
virtual ~Vector()
Definition: Vector.cc:274
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:819
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
Definition: Vector.cc:1540
string name() const
Returns the name of the class instance.
Definition: BaseType.cc:210
Vector(const string &n, BaseType *v, const Type &t)
The Vector constructor.
Definition: Vector.cc:223
Evaluate a constraint expression.
virtual BaseType * ptr_duplicate()=0
virtual void set_send_p(bool state)
Indicates that the data is ready to send.
Definition: Vector.cc:329
int16_t dods_int16
The basic data type for the DODS DAP types.
Definition: BaseType.h:194
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:299
virtual unsigned int buf2val(void **val)
Definition: Vector.cc:905
virtual void set_length(int l)
Definition: Vector.cc:513
virtual unsigned int width()
Returns the width of the data, in bytes.
Definition: Vector.cc:486
virtual bool set_value(dods_byte *val, int sz)
set the value of a byte array
Definition: Vector.cc:1221
virtual void intern_data(ConstraintEvaluator &eval, DDS &dds)
read data into a variable for later use
Definition: Vector.cc:547
void vec_resize(int l)
Definition: Vector.cc:526
int32_t dods_int32