libdap Updated for version 3.20.11
libdap4 is an implementation of OPeNDAP's DAP protocol.
Vector.h
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
50class Crc32;
51
52namespace libdap
53{
54
80class Vector: public BaseType
81{
82private:
83 int d_length = -1; // number of elements in the vector
84 BaseType *d_proto = nullptr; // element prototype for the Vector
85
86 // _buf was a pointer to void; delete[] complained. 6/4/2001 jhrg
87 char *d_buf = nullptr; // 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 = 0;
95
96 friend class MarshallerTest;
97
98 /*
99 * Made these template methods private because they can't be
100 * overridden anyways (because c++...) - ndp 08/14/2015
101 *
102 */
103
104 template <typename T> void value_worker(T *v) const;
105 template <typename T> void value_worker(vector<unsigned int> *indices, T *b) const;
106
107 template <typename T> bool set_value_worker(T *v, int sz);
108 template <typename T> bool set_value_worker(vector<T> &v, int sz);
109
110protected:
111 // This function copies the private members of Vector.
112 void m_duplicate(const Vector &v);
113
114 bool m_is_cardinal_type() const;
115 unsigned int m_create_cardinal_data_buffer_for_type(unsigned int numEltsOfType);
117
118 template <class CardType> void m_set_cardinal_values_internal(const CardType* fromArray, int numElts);
119
120public:
121 Vector(const string &n, BaseType *v, const Type &t, bool is_dap4 = false);
122 Vector(const string &n, const string &d, BaseType *v, const Type &t, bool is_dap4 = false);
123 Vector(const Vector &rhs);
124
125 virtual ~Vector();
126
127 Vector &operator=(const Vector &rhs);
128 virtual BaseType *ptr_duplicate() = 0;
129
138 char *get_buf() {
139 return d_buf;
140 }
141
148 vector<string> &get_str() {
149 return d_str;
150 }
151
159 vector<BaseType*> &get_compound_buf() {
160 return d_compound_buf;
161 }
162
163#if 0
164 virtual bool is_dap2_only_type();
165#endif
166
167 virtual BaseType *prototype() const { return d_proto; }
168
169 virtual void set_name(const std::string& name);
170
171 virtual int element_count(bool leaves);
172
173 virtual void set_send_p(bool state);
174
175 virtual void set_read_p(bool state);
176
177 virtual unsigned int width(bool constrained = false) const;
178
179 virtual int length() const;
180
181 virtual void set_length(int l);
182
183 // DAP2
184 virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
185 virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
186#if 0
187 virtual bool serialize_no_release(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
188#endif
189 virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
190
191 // DAP4
192 virtual void compute_checksum(Crc32 &checksum);
193 virtual void intern_data(/*Crc32 &checksum*/);
194 virtual void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter = false);
195#if 0
196 virtual void serialize_no_release(D4StreamMarshaller &m, DMR &dmr, bool filter = false);
197#endif
198 virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);
199
200 virtual unsigned int val2buf(void *val, bool reuse = false);
201 virtual unsigned int buf2val(void **val);
202
203 void set_vec(unsigned int i, BaseType *val);
204 void set_vec_nocopy(unsigned int i, BaseType * val);
205
206 void vec_resize(int l);
207
208 virtual void clear_local_data();
209
210 virtual unsigned int get_value_capacity() const;
211 virtual void reserve_value_capacity(unsigned int numElements);
212 virtual void reserve_value_capacity();
213
214 virtual unsigned int set_value_slice_from_row_major_vector(const Vector& rowMajorData, unsigned int startElement);
215
216
217 virtual bool set_value(dods_byte *val, int sz);
218 virtual bool set_value(dods_int8 *val, int sz);
219 virtual bool set_value(dods_int16 *val, int sz);
220 virtual bool set_value(dods_uint16 *val, int sz);
221 virtual bool set_value(dods_int32 *val, int sz);
222 virtual bool set_value(dods_uint32 *val, int sz);
223 virtual bool set_value(dods_int64 *val, int sz);
224 virtual bool set_value(dods_uint64 *val, int sz);
225 virtual bool set_value(dods_float32 *val, int sz);
226 virtual bool set_value(dods_float64 *val, int sz);
227 virtual bool set_value(string *val, int sz);
228
229
230 virtual bool set_value(vector<dods_byte> &val, int sz);
231 virtual bool set_value(vector<dods_int8> &val, int sz);
232 virtual bool set_value(vector<dods_int16> &val, int sz);
233 virtual bool set_value(vector<dods_uint16> &val, int sz);
234 virtual bool set_value(vector<dods_int32> &val, int sz);
235 virtual bool set_value(vector<dods_uint32> &val, int sz);
236 virtual bool set_value(vector<dods_int64> &val, int sz);
237 virtual bool set_value(vector<dods_uint64> &val, int sz);
238 virtual bool set_value(vector<dods_float32> &val, int sz);
239 virtual bool set_value(vector<dods_float64> &val, int sz);
240 virtual bool set_value(vector<string> &val, int sz);
241
242 virtual void value(dods_byte *b) const;
243 virtual void value(dods_int8 *b) const;
244 virtual void value(dods_int16 *b) const;
245 virtual void value(dods_uint16 *b) const;
246 virtual void value(dods_int32 *b) const;
247 virtual void value(dods_uint32 *b) const;
248 virtual void value(dods_int64 *b) const;
249 virtual void value(dods_uint64 *b) const;
250 virtual void value(dods_float32 *b) const;
251 virtual void value(dods_float64 *b) const;
252 virtual void value(vector<string> &b) const;
253
254 virtual void value(vector<unsigned int> *indices, dods_byte *b) const;
255 virtual void value(vector<unsigned int> *indices, dods_int8 *b) const;
256 virtual void value(vector<unsigned int> *indices, dods_int16 *b) const;
257 virtual void value(vector<unsigned int> *indices, dods_uint16 *b) const;
258 virtual void value(vector<unsigned int> *indices, dods_int32 *b) const;
259 virtual void value(vector<unsigned int> *indices, dods_uint32 *b) const;
260 virtual void value(vector<unsigned int> *indices, dods_int64 *b) const;
261 virtual void value(vector<unsigned int> *indices, dods_uint64 *b) const;
262 virtual void value(vector<unsigned int> *indices, dods_float32 *b) const;
263 virtual void value(vector<unsigned int> *indices, dods_float64 *b) const;
264 virtual void value(vector<unsigned int> *index, vector<string> &b) const;
265
266 virtual void *value();
267
268 virtual BaseType *var(const string &name = "", bool exact_match = true, btp_stack *s = 0);
269 virtual BaseType *var(const string &name, btp_stack &s);
270 virtual BaseType *var(unsigned int i);
271
272 virtual void add_var(BaseType *v, Part p = nil);
273 virtual void add_var_nocopy(BaseType *v, Part p = nil);
274
275 virtual bool check_semantics(string &msg, bool all = false);
276
277 virtual void dump(ostream &strm) const ;
278};
279
280} // namespace libdap
281
282#endif /* _vector_h */
Definition: crc.h:77
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:316
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
Definition: BaseType.cc:126
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:81
virtual void add_var(BaseType *v, Part p=nil)
Add the BaseType pointer to this constructor type instance.
Definition: Vector.cc:1961
virtual void set_length(int l)
Definition: Vector.cc:555
vector< BaseType * > & get_compound_buf()
Definition: Vector.h:159
virtual unsigned int get_value_capacity() const
Definition: Vector.cc:1407
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:1343
void m_set_cardinal_values_internal(const CardType *fromArray, int numElts)
Definition: Vector.cc:221
virtual int length() const
Definition: Vector.cc:548
virtual BaseType * ptr_duplicate()=0
virtual unsigned int set_value_slice_from_row_major_vector(const Vector &rowMajorData, unsigned int startElement)
Definition: Vector.cc:1512
virtual void set_read_p(bool state)
Indicates that the data is ready to send.
Definition: Vector.cc:391
virtual void set_send_p(bool state)
Indicates that the data is ready to send.
Definition: Vector.cc:354
void set_vec(unsigned int i, BaseType *val)
Sets element i to value val.
Definition: Vector.cc:1327
virtual unsigned int width(bool constrained=false) const
Returns the width of the data, in bytes.
Definition: Vector.cc:536
virtual unsigned int val2buf(void *val, bool reuse=false)
Reads data into the Vector buffer.
Definition: Vector.cc:1144
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Serialize a Vector.
Definition: Vector.cc:661
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:858
virtual void dump(ostream &strm) const
dumps information about this object
Definition: Vector.cc:2044
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
Definition: Vector.cc:433
virtual void set_name(const std::string &name)
Sets the name of the class instance.
Definition: Vector.cc:323
char * get_buf()
Definition: Vector.h:138
virtual int element_count(bool leaves)
Count the members of constructor types.
Definition: Vector.cc:333
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
Definition: Vector.cc:755
virtual void intern_data()
Read data into this variable.
Definition: Vector.cc:900
bool m_is_cardinal_type() const
Definition: Vector.cc:127
virtual void clear_local_data()
Definition: Vector.cc:1380
virtual void * value()
Definition: Vector.cc:1936
vector< string > & get_str()
Definition: Vector.h:148
void vec_resize(int l)
Definition: Vector.cc:568
void m_delete_cardinal_data_buffer()
Definition: Vector.cc:210
virtual void reserve_value_capacity()
Definition: Vector.cc:1477
unsigned int m_create_cardinal_data_buffer_for_type(unsigned int numEltsOfType)
Definition: Vector.cc:182
virtual unsigned int buf2val(void **val)
Copies data from the Vector buffer.
Definition: Vector.cc:1249
Vector(const string &n, BaseType *v, const Type &t, bool is_dap4=false)
The Vector constructor.
Definition: Vector.cc:251
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
Definition: Vector.cc:2031
top level DAP object to house generic methods
Definition: AlarmHandler.h:36
Type
Identifies the data type.
Definition: Type.h:94
Part
Names the parts of multi-section constructor data types.
Definition: Type.h:48