libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
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#include <cassert>
39
40#ifndef _basetype_h
41#include "BaseType.h"
42#endif
43
44#ifndef _dds_h
45#include "DDS.h"
46#endif
47
48#ifndef constraint_evaluator_h
49#include "ConstraintEvaluator.h"
50#endif
51
52class Crc32;
53
54namespace libdap {
55
81class Vector : public BaseType {
82private:
83 // Add d_length_ll. This uses -1 as a sentinel value. jhrg 7/25/22
84 // If we decide to add a bool for 'no values yet' do that as a
85 // separate refactor. jhrg 7/25/22
86 int64_t d_length_ll = -1; // number of elements in the vector
87
88 int d_length = -1; // number of elements in the vector
89 BaseType *d_proto = nullptr; // element prototype for the Vector
90
91 // _buf was a pointer to void; delete[] complained. 6/4/2001 jhrg
92 char *d_buf = nullptr; // storage for cardinal data
93 vector<string> d_str; // special storage for strings. jhrg 2/11/05
94 vector<BaseType *> d_compound_buf; // storage for data in compound types (e.g., Structure)
95
96 // the number of elements we have allocated memory to store.
97 // This should be either the sizeof(buf)/width(bool constrained = false) for cardinal data
98 // or the capacity of d_str for strings or capacity of _vec.
99 unsigned int d_capacity = 0;
100 uint64_t d_capacity_ll = 0;
101
102 bool d_too_big_for_dap2 = false;
103
104 friend class MarshallerTest;
105
106 // Made these template methods private because they can't be
107 // overridden anyways (because c++...) - ndp 08/14/2015
108 template <typename T> void value_worker(T *v) const;
109 template <typename T> void value_ll_worker(T *v) const;
110 template <typename T> void value_worker(vector<unsigned int> *indices, T *b) const;
111 template <typename T> void value_ll_worker(vector<uint64_t> *indices, T *b) const;
112
113 template <typename T> bool set_value_worker(T *v, int sz);
114 template <typename T> bool set_value_ll_worker(T *v, int64_t sz);
115 template <typename T> bool set_value_worker(vector<T> &v, int sz);
116 template <typename T> bool set_value_ll_worker(vector<T> &v, int64_t sz);
117
118 bool m_is_cardinal_type() const;
119 int64_t m_create_cardinal_data_buffer_for_type(int64_t num_elements);
120 void m_delete_cardinal_data_buffer();
121 template <class CardType> void m_set_cardinal_values_internal(const CardType *fromArray, int64_t num_elements);
122
123 // This function copies the private members of Vector.
124 void m_duplicate(const Vector &v);
125
126public:
127 Vector(const string &n, BaseType *v, const Type &t, bool is_dap4 = false);
128 Vector(const string &n, const string &d, BaseType *v, const Type &t, bool is_dap4 = false);
129 Vector(const Vector &rhs);
130
131 virtual ~Vector();
132
133 Vector &operator=(const Vector &rhs);
134 // FIXME BaseType *ptr_duplicate() = 0 override;
135
144 char *get_buf() { return d_buf; }
145
152 vector<string> &get_str() { return d_str; }
153
161 vector<BaseType *> &get_compound_buf() { return d_compound_buf; }
162
163 virtual BaseType *prototype() const { return d_proto; }
164
171 BaseType *orig = d_proto;
172 d_proto = btp;
173 return orig;
174 }
175
176 void set_name(const std::string &name) override;
177
178 int element_count(bool leaves) override;
179
180 void set_send_p(bool state) override;
181
182 void set_read_p(bool state) override;
183
191 unsigned int width(bool constrained = false) const override {
192 // Jose Garcia
193 assert(d_proto);
194
195 return length() * d_proto->width(constrained);
196 }
197
203 int64_t width_ll(bool constrained = false) const override { return length_ll() * d_proto->width_ll(constrained); }
204
210 int length() const override { return d_length; }
211
218 int64_t length_ll() const override { return d_length_ll; }
219
220 void set_length(int64_t l) override;
221
222 void set_length_ll(int64_t l) override;
223
224 // DAP2
225 void intern_data(ConstraintEvaluator &eval, DDS &dds) override;
226 bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true) override;
227 bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false) override;
228
229 // DAP4
230 void compute_checksum(Crc32 &checksum) override;
231 void intern_data(/*Crc32 &checksum*/) override;
232 void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter = false) override;
233 void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override;
234
235 unsigned int val2buf(void *val, bool reuse = false) override;
236 unsigned int buf2val(void **val) override;
237
238 int64_t val2buf_ll(void *val, bool reuse = false);
239 int64_t buf2val_ll(void **val);
240
241 void set_vec(unsigned int i, BaseType *val);
242 void set_vec_nocopy(unsigned int i, BaseType *val);
243
244 void set_vec_ll(uint64_t i, BaseType *val);
245 void set_vec_nocopy_ll(uint64_t i, BaseType *val);
246
247 void vec_resize(int l);
248 void vec_resize_ll(int64_t l);
249
250 void clear_local_data() override;
251
252 virtual unsigned int get_value_capacity() const;
253 virtual uint64_t get_value_capacity_ll() const;
254
255 void set_value_capacity(uint64_t l);
256 virtual void reserve_value_capacity(unsigned int numElements);
257 virtual void reserve_value_capacity();
258 virtual void reserve_value_capacity_ll(uint64_t numElements);
259 virtual void reserve_value_capacity_ll();
260
261 virtual void reserve_value_capacity_ll_byte(uint64_t numBytes);
262
263 virtual uint64_t set_value_slice_from_row_major_vector(const Vector &rowMajorData, uint64_t startElement);
264
265 virtual bool set_value(dods_byte *val, int sz);
266 virtual bool set_value(dods_int8 *val, int sz);
267 virtual bool set_value(dods_int16 *val, int sz);
268 virtual bool set_value(dods_uint16 *val, int sz);
269 virtual bool set_value(dods_int32 *val, int sz);
270 virtual bool set_value(dods_uint32 *val, int sz);
271 virtual bool set_value(dods_int64 *val, int sz);
272 virtual bool set_value(dods_uint64 *val, int sz);
273 virtual bool set_value(dods_float32 *val, int sz);
274 virtual bool set_value(dods_float64 *val, int sz);
275 virtual bool set_value(string *val, int sz);
276
277 virtual bool set_value_ll(dods_byte *val, int64_t sz);
278 virtual bool set_value_ll(dods_int8 *val, int64_t sz);
279 virtual bool set_value_ll(dods_int16 *val, int64_t sz);
280 virtual bool set_value_ll(dods_uint16 *val, int64_t sz);
281 virtual bool set_value_ll(dods_int32 *val, int64_t sz);
282 virtual bool set_value_ll(dods_uint32 *val, int64_t sz);
283 virtual bool set_value_ll(dods_int64 *val, int64_t sz);
284 virtual bool set_value_ll(dods_uint64 *val, int64_t sz);
285 virtual bool set_value_ll(dods_float32 *val, int64_t sz);
286 virtual bool set_value_ll(dods_float64 *val, int64_t sz);
287 virtual bool set_value_ll(string *val, int64_t sz);
288
289 virtual bool set_value(vector<dods_byte> &val, int sz);
290 virtual bool set_value(vector<dods_int8> &val, int sz);
291 virtual bool set_value(vector<dods_int16> &val, int sz);
292 virtual bool set_value(vector<dods_uint16> &val, int sz);
293 virtual bool set_value(vector<dods_int32> &val, int sz);
294 virtual bool set_value(vector<dods_uint32> &val, int sz);
295 virtual bool set_value(vector<dods_int64> &val, int sz);
296 virtual bool set_value(vector<dods_uint64> &val, int sz);
297 virtual bool set_value(vector<dods_float32> &val, int sz);
298 virtual bool set_value(vector<dods_float64> &val, int sz);
299 virtual bool set_value(vector<string> &val, int sz);
300
301 virtual bool set_value_ll(vector<dods_byte> &val, int64_t sz);
302 virtual bool set_value_ll(vector<dods_int8> &val, int64_t sz);
303 virtual bool set_value_ll(vector<dods_int16> &val, int64_t sz);
304 virtual bool set_value_ll(vector<dods_uint16> &val, int64_t sz);
305 virtual bool set_value_ll(vector<dods_int32> &val, int64_t sz);
306 virtual bool set_value_ll(vector<dods_uint32> &val, int64_t sz);
307 virtual bool set_value_ll(vector<dods_int64> &val, int64_t sz);
308 virtual bool set_value_ll(vector<dods_uint64> &val, int64_t sz);
309 virtual bool set_value_ll(vector<dods_float32> &val, int64_t sz);
310 virtual bool set_value_ll(vector<dods_float64> &val, int64_t sz);
311 virtual bool set_value_ll(vector<string> &val, int64_t sz);
312
313 virtual void value(dods_byte *b) const;
314 virtual void value(dods_int8 *b) const;
315 virtual void value(dods_int16 *b) const;
316 virtual void value(dods_uint16 *b) const;
317 virtual void value(dods_int32 *b) const;
318 virtual void value(dods_uint32 *b) const;
319 virtual void value(dods_int64 *b) const;
320 virtual void value(dods_uint64 *b) const;
321 virtual void value(dods_float32 *b) const;
322 virtual void value(dods_float64 *b) const;
323 virtual void value(vector<string> &b) const;
324
325 virtual void value(vector<unsigned int> *indices, dods_byte *b) const;
326 virtual void value(vector<unsigned int> *indices, dods_int8 *b) const;
327 virtual void value(vector<unsigned int> *indices, dods_int16 *b) const;
328 virtual void value(vector<unsigned int> *indices, dods_uint16 *b) const;
329 virtual void value(vector<unsigned int> *indices, dods_int32 *b) const;
330 virtual void value(vector<unsigned int> *indices, dods_uint32 *b) const;
331 virtual void value(vector<unsigned int> *indices, dods_int64 *b) const;
332 virtual void value(vector<unsigned int> *indices, dods_uint64 *b) const;
333 virtual void value(vector<unsigned int> *indices, dods_float32 *b) const;
334 virtual void value(vector<unsigned int> *indices, dods_float64 *b) const;
335 virtual void value(vector<unsigned int> *index, vector<string> &b) const;
336
337 virtual void value_ll(vector<uint64_t> *indices, dods_byte *b) const;
338 virtual void value_ll(vector<uint64_t> *indices, dods_int8 *b) const;
339 virtual void value_ll(vector<uint64_t> *indices, dods_int16 *b) const;
340 virtual void value_ll(vector<uint64_t> *indices, dods_uint16 *b) const;
341 virtual void value_ll(vector<uint64_t> *indices, dods_int32 *b) const;
342 virtual void value_ll(vector<uint64_t> *indices, dods_uint32 *b) const;
343 virtual void value_ll(vector<uint64_t> *indices, dods_int64 *b) const;
344 virtual void value_ll(vector<uint64_t> *indices, dods_uint64 *b) const;
345 virtual void value_ll(vector<uint64_t> *indices, dods_float32 *b) const;
346 virtual void value_ll(vector<uint64_t> *indices, dods_float64 *b) const;
347 virtual void value_ll(vector<uint64_t> *index, vector<string> &b) const;
348
349 virtual void *value();
350
351 BaseType *var(const string &name = "", bool exact_match = true, btp_stack *s = nullptr) override;
352 BaseType *var(const string &name, btp_stack &s) override;
353
354 virtual BaseType *var(unsigned int i);
355 virtual BaseType *var_ll(uint64_t i);
356
357 void add_var(BaseType *v, Part p = nil) override;
358 void add_var_nocopy(BaseType *v, Part p = nil) override;
359
360 bool check_semantics(string &msg, bool all = false) override;
361
362 bool is_dap4_projected(std::vector<std::string> &projected_dap4_inventory) override;
363
364 void dump(ostream &strm) const override;
365};
366
367} // namespace libdap
368
369#endif /* _vector_h */
Definition crc.h:43
The basic data type for the DODS DAP types.
Definition BaseType.h:118
virtual string name() const
Returns the name of the class instance.
Definition BaseType.cc:296
virtual bool is_dap4() const
Definition BaseType.h:181
stack< BaseType * > btp_stack
Definition BaseType.h:149
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
Definition BaseType.cc:124
Evaluate a constraint expression.
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
Read data from the stream made by D4StreamMarshaller.
abstract base class used to marshal/serialize dap data objects
Definition Marshaller.h:50
abstract base class used to unmarshall/deserialize dap data objects
Holds a one-dimensional collection of DAP2 data types.
Definition Vector.h:81
unsigned int width(bool constrained=false) const override
Returns the width of the data, in bytes.
Definition Vector.h:191
virtual void reserve_value_capacity_ll_byte(uint64_t numBytes)
Definition Vector.cc:1818
bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false) override
Receive data from the net.
Definition Vector.cc:831
void set_send_p(bool state) override
Indicates that the data is ready to send.
Definition Vector.cc:352
int64_t width_ll(bool constrained=false) const override
Return the number of bytes needed to hold the array data.
Definition Vector.h:203
void dump(ostream &strm) const override
dumps information about this object
Definition Vector.cc:2452
virtual uint64_t get_value_capacity_ll() const
Definition Vector.cc:1665
virtual BaseType * set_prototype(BaseType *btp)
Change the Vector/Array element type.
Definition Vector.h:170
void compute_checksum(Crc32 &checksum) override
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
Definition Vector.cc:939
vector< BaseType * > & get_compound_buf()
Definition Vector.h:161
virtual unsigned int get_value_capacity() const
Definition Vector.cc:1663
void set_vec_nocopy(unsigned int i, BaseType *val)
Sets element i to value val. Set the ith element to val. Extend the vector if needed.
Definition Vector.cc:1571
friend class MarshallerTest
Conditionally set to true in set_length_ll()
Definition Vector.h:104
Vector & operator=(const Vector &rhs)
Definition Vector.cc:315
void add_var_nocopy(BaseType *v, Part p=nil) override
Definition Vector.cc:2391
void add_var(BaseType *v, Part p=nil) override
Add the BaseType pointer to this constructor type instance.
Definition Vector.cc:2351
int length() const override
Returns the number of elements in the vector. Note that some child classes of Vector use the length o...
Definition Vector.h:210
int64_t val2buf_ll(void *val, bool reuse=false)
Definition Vector.cc:1309
virtual void value_ll(vector< uint64_t > *indices, dods_byte *b) const
Definition Vector.cc:2226
int64_t length_ll() const override
Get the number of elements in this Vector/Array This version of the function deprecates length() whic...
Definition Vector.h:218
void set_read_p(bool state) override
Indicates that the data is ready to send.
Definition Vector.cc:389
int element_count(bool leaves) override
Count the members of constructor types.
Definition Vector.cc:332
void set_length_ll(int64_t l) override
Set the number of elements in this Vector/Array This version of the function deprecates set_length() ...
Definition Vector.cc:432
void set_vec(unsigned int i, BaseType *val)
Sets element i to value val.
Definition Vector.cc:1556
bool is_dap4_projected(std::vector< std::string > &projected_dap4_inventory) override
Definition Vector.cc:2424
virtual ~Vector()
Definition Vector.cc:303
void set_value_capacity(uint64_t l)
Definition Vector.cc:442
void set_name(const std::string &name) override
Sets the name of the class instance.
Definition Vector.cc:323
bool check_semantics(string &msg, bool all=false) override
Compare an object's current state with the semantics of its type.
Definition Vector.cc:2415
void vec_resize_ll(int64_t l)
Definition Vector.cc:628
void intern_data() override
Read data into this variable.
Definition Vector.cc:980
virtual void reserve_value_capacity_ll()
Definition Vector.cc:1808
unsigned int val2buf(void *val, bool reuse=false) override
Reads data into the Vector buffer.
Definition Vector.cc:1303
int64_t buf2val_ll(void **val)
Definition Vector.cc:1479
char * get_buf()
Definition Vector.h:144
virtual bool set_value_ll(dods_byte *val, int64_t sz)
Definition Vector.cc:2029
BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=nullptr) override
Definition Vector.cc:469
virtual uint64_t set_value_slice_from_row_major_vector(const Vector &rowMajorData, uint64_t startElement)
Definition Vector.cc:1847
virtual bool set_value(dods_byte *val, int sz)
Definition Vector.cc:2017
virtual void * value()
Definition Vector.cc:2327
bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true) override
Serialize a Vector.
Definition Vector.cc:726
vector< string > & get_str()
Definition Vector.h:152
void set_vec_nocopy_ll(uint64_t i, BaseType *val)
Definition Vector.cc:1599
void set_vec_ll(uint64_t i, BaseType *val)
Definition Vector.cc:1558
void vec_resize(int l)
Definition Vector.cc:613
virtual void reserve_value_capacity()
Definition Vector.cc:1735
virtual BaseType * prototype() const
Definition Vector.h:163
unsigned int buf2val(void **val) override
Copies data from the Vector buffer.
Definition Vector.cc:1422
void clear_local_data() override
Definition Vector.cc:1636
Vector(const string &n, BaseType *v, const Type &t, bool is_dap4=false)
The Vector constructor.
Definition Vector.cc:254
virtual BaseType * var_ll(uint64_t i)
Definition Vector.cc:567
void set_length(int64_t l) override
Sets the length of the vector. This function does not allocate any new space.
Definition Vector.cc:423
top level DAP object to house generic methods
Definition AISConnect.cc:30
Type
Identifies the data type.
Definition Type.h:94
uint64_t dods_uint64
uint32_t dods_uint32
Part
Names the parts of multi-section constructor data types.
Definition Type.h:48
@ nil
Definition Type.h:49
uint16_t dods_uint16