libdap++  Updated for version 3.14.0
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 class Crc32;
51 
52 namespace libdap
53 {
54 
80 class Vector: public BaseType
81 {
82 private:
83  int d_length; // number of elements in the vector
84  BaseType *d_proto; // element prototype for the Vector
85 
86  // _buf was a pointer to void; delete[] complained. 6/4/2001 jhrg
87  char *d_buf; // storage for cardinal data
88  vector<string> d_str; // special storage for strings. jhrg 2/11/05
89  vector<BaseType *> d_compound_buf; // storage for data in compound types (e.g., Structure)
90 
91  // the number of elements we have allocated memory to store.
92  // This should be either the sizeof(buf)/width(bool constrained = false) for cardinal data
93  // or the capacity of d_str for strings or capacity of _vec.
94  unsigned int d_capacity;
95 
96 protected:
97  // This function copies the private members of Vector.
98  void m_duplicate(const Vector &v);
99 
100  bool m_is_cardinal_type() const;
101  unsigned int m_create_cardinal_data_buffer_for_type(unsigned int numEltsOfType);
103 
104  template <class CardType> void m_set_cardinal_values_internal(const CardType* fromArray, int numElts);
105 
106 public:
107  Vector(const string &n, BaseType *v, const Type &t, bool is_dap4 = false);
108  Vector(const string &n, const string &d, BaseType *v, const Type &t, bool is_dap4 = false);
109  Vector(const Vector &rhs);
110 
111  virtual ~Vector();
112 
113  Vector &operator=(const Vector &rhs);
114  virtual BaseType *ptr_duplicate() = 0;
115 
116 #if 0
117  virtual bool is_dap2_only_type();
118 #endif
119 
120  virtual BaseType *prototype() const { return d_proto; }
121 
122  virtual void set_name(const std::string& name);
123 
124  virtual int element_count(bool leaves);
125 
126  virtual void set_send_p(bool state);
127 
128  virtual void set_read_p(bool state);
129 
130  virtual unsigned int width(bool constrained = false) const;
131 
132  virtual int length() const;
133 
134  virtual void set_length(int l);
135 
136  // DAP2
137  virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
138  virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
139  virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
140 
141  // DAP4
142  virtual void compute_checksum(Crc32 &checksum);
143  virtual void intern_data(Crc32 &checksum/*, DMR &dmr, ConstraintEvaluator &eval*/);
144  virtual void serialize(D4StreamMarshaller &m, DMR &dmr, /*ConstraintEvaluator &eval,*/ bool filter = false);
145  virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);
146 
147  virtual unsigned int val2buf(void *val, bool reuse = false);
148  virtual unsigned int buf2val(void **val);
149 
150  void set_vec(unsigned int i, BaseType *val);
151  void set_vec_nocopy(unsigned int i, BaseType * val);
152 
153  void vec_resize(int l);
154 
155  void clear_local_data();
156 
157  virtual unsigned int get_value_capacity() const;
158  virtual void reserve_value_capacity(unsigned int numElements);
159  virtual void reserve_value_capacity();
160 
161  virtual unsigned int set_value_slice_from_row_major_vector(const Vector& rowMajorData, unsigned int startElement);
162 
163  template <typename T> bool set_value(T *v, int sz);
164  template <typename T> bool set_value(vector<T> &v, int sz);
165 #if 0
166  virtual bool set_value(dods_byte *val, int sz);
167  virtual bool set_value(vector<dods_byte> &val, int sz);
168 
169  virtual bool set_value(dods_int8 *val, int sz);
170  virtual bool set_value(vector<dods_int8> &val, int sz);
171 
172  virtual bool set_value(dods_int16 *val, int sz);
173  virtual bool set_value(vector<dods_int16> &val, int sz);
174 
175  virtual bool set_value(dods_uint16 *val, int sz);
176  virtual bool set_value(vector<dods_uint16> &val, int sz);
177 
178  virtual bool set_value(dods_int32 *val, int sz);
179  virtual bool set_value(vector<dods_int32> &val, int sz);
180 
181  virtual bool set_value(dods_uint32 *val, int sz);
182  virtual bool set_value(vector<dods_uint32> &val, int sz);
183 
184  virtual bool set_value(dods_int64 *val, int sz);
185  virtual bool set_value(vector<dods_int64> &val, int sz);
186 
187  virtual bool set_value(dods_uint64 *val, int sz);
188  virtual bool set_value(vector<dods_uint64> &val, int sz);
189 
190  virtual bool set_value(dods_float32 *val, int sz);
191  virtual bool set_value(vector<dods_float32> &val, int sz);
192 
193  virtual bool set_value(dods_float64 *val, int sz);
194  virtual bool set_value(vector<dods_float64> &val, int sz);
195 #endif
196  virtual bool set_value(string *val, int sz);
197  virtual bool set_value(vector<string> &val, int sz);
198 
199  template <typename T> void value(T *v) const;
200 #if 0
201  virtual void value(dods_byte *b) const;
202  virtual void value(dods_int8 *b) const;
203  virtual void value(dods_int16 *b) const;
204  virtual void value(dods_uint16 *b) const;
205  virtual void value(dods_int32 *b) const;
206  virtual void value(dods_uint32 *b) const;
207  virtual void value(dods_int64 *b) const;
208  virtual void value(dods_uint64 *b) const;
209  virtual void value(dods_float32 *b) const;
210  virtual void value(dods_float64 *b) const;
211 #endif
212  virtual void value(vector<string> &b) const;
213 
214  template <typename T> void value(vector<unsigned int> *indices, T *b) const;
215 #if 0
216  void value(vector<unsigned int> *index, dods_byte *b) const;
217  void value(vector<unsigned int> *index, dods_int8 *b) const;
218  void value(vector<unsigned int> *index, dods_int16 *b) const;
219  void value(vector<unsigned int> *index, dods_uint16 *b) const;
220  void value(vector<unsigned int> *index, dods_int32 *b) const;
221  void value(vector<unsigned int> *index, dods_uint32 *b) const;
222  void value(vector<unsigned int> *index, dods_float32 *b) const;
223  void value(vector<unsigned int> *index, dods_float64 *b) const;
224 #endif
225  void value(vector<unsigned int> *index, vector<string> &b) const;
226 
227  virtual void *value();
228 
229  virtual BaseType *var(const string &name = "", bool exact_match = true, btp_stack *s = 0);
230  virtual BaseType *var(const string &name, btp_stack &s);
231  virtual BaseType *var(unsigned int i);
232 
233  virtual void add_var(BaseType *v, Part p = nil);
234  virtual void add_var_nocopy(BaseType *v, Part p = nil);
235 
236  virtual bool check_semantics(string &msg, bool all = false);
237 
238  virtual void dump(ostream &strm) const ;
239 };
240 
241 } // namespace libdap
242 
243 #endif /* _vector_h */
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:2267
virtual unsigned int get_value_capacity() const
Definition: Vector.cc:1309
uint8_t dods_byte
void set_vec(unsigned int i, BaseType *val)
Sets element i to value val.
Definition: Vector.cc:1243
int64_t dods_int64
Part
Names the parts of multi-section constructor data types.
Definition: Type.h:48
virtual BaseType * prototype() const
Definition: Vector.h:120
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:80
virtual void dump(ostream &strm) const
dumps information about this object
Definition: Vector.cc:2310
bool is_dap4() const
Definition: BaseType.h:166
void clear_local_data()
Definition: Vector.cc:1282
Read data from the stream made by D4StreamMarshaller.
virtual int length() const
Definition: Vector.cc:513
virtual void compute_checksum(Crc32 &checksum)
include the data for this variable in the checksum DAP4 includes a checksum with every data response...
Definition: Vector.cc:801
virtual void set_read_p(bool state)
Indicates that the data is ready to send.
Definition: Vector.cc:362
Definition: crc.h:76
virtual void add_var(BaseType *v, Part p=nil)
Add the BaseType pointer to this constructor type instance.
Definition: Vector.cc:2227
virtual int element_count(bool leaves)
Count the members of constructor types.
Definition: Vector.cc:329
virtual void * value()
Definition: Vector.cc:2202
void m_set_cardinal_values_internal(const CardType *fromArray, int numElts)
Definition: Vector.cc:215
virtual unsigned int set_value_slice_from_row_major_vector(const Vector &rowMajorData, unsigned int startElement)
Definition: Vector.cc:1417
Type
Identifies the data type.
Definition: Type.h:94
uint16_t dods_uint16
stack< BaseType * > btp_stack
Definition: BaseType.h:149
uint64_t dods_uint64
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Serialize a Vector.
Definition: Vector.cc:622
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
Definition: Vector.cc:387
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
Definition: Vector.cc:708
bool set_value(T *v, int sz)
set the value of a byte array
Definition: Vector.cc:1573
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
double dods_float64
void set_vec_nocopy(unsigned int i, BaseType *val)
Sets element i to value val.
Definition: Vector.cc:1254
bool m_is_cardinal_type() const
Definition: Vector.cc:122
uint32_t dods_uint32
virtual void reserve_value_capacity()
Definition: Vector.cc:1382
Vector & operator=(const Vector &rhs)
Definition: Vector.cc:307
Vector(const string &n, BaseType *v, const Type &t, bool is_dap4=false)
The Vector constructor.
Definition: Vector.cc:244
virtual ~Vector()
Definition: Vector.cc:294
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:1071
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
Definition: Vector.cc:2297
void m_delete_cardinal_data_buffer()
Definition: Vector.cc:204
string name() const
Returns the name of the class instance.
Definition: BaseType.cc:261
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:350
int16_t dods_int16
unsigned int m_create_cardinal_data_buffer_for_type(unsigned int numEltsOfType)
Definition: Vector.cc:180
The basic data type for the DODS DAP types.
Definition: BaseType.h:117
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:319
void m_duplicate(const Vector &v)
Definition: Vector.cc:73
virtual unsigned int buf2val(void **val)
Definition: Vector.cc:1163
virtual void set_length(int l)
Definition: Vector.cc:520
virtual void intern_data(ConstraintEvaluator &eval, DDS &dds)
read data into a variable for later use
Definition: Vector.cc:559
void vec_resize(int l)
Definition: Vector.cc:533
virtual unsigned int width(bool constrained=false) const
Returns the width of the data, in bytes.
Definition: Vector.cc:498
int32_t dods_int32