libdap++  Updated for version 3.12.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 namespace libdap
51 {
52 
78 class Vector: public BaseType
79 {
80 private:
81  int d_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(bool constrained = false) 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 m_is_cardinal_type() const;
99  unsigned int m_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 bool is_dap2_only_type();
115 
116  virtual void set_name(const std::string& name);
117 
118  virtual int element_count(bool leaves);
119 
120  virtual void set_send_p(bool state);
121 
122  virtual void set_read_p(bool state);
123 
124  virtual unsigned int width(bool constrained = false);
125 
126  virtual int length() const;
127 
128  virtual void set_length(int l);
129 
130  virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
131  virtual bool serialize(ConstraintEvaluator &eval, DDS &dds,
132  Marshaller &m, bool ce_eval = true);
133  virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
134 
135  virtual unsigned int val2buf(void *val, bool reuse = false);
136  virtual unsigned int buf2val(void **val);
137 
138  void set_vec(unsigned int i, BaseType *val);
139 
140  void vec_resize(int l);
141 
142  void clear_local_data();
143 
144  virtual unsigned int get_value_capacity() const;
145  virtual void reserve_value_capacity(unsigned int numElements);
146  virtual void reserve_value_capacity();
147 
148  virtual unsigned int set_value_slice_from_row_major_vector
149  (const Vector& rowMajorData, unsigned int startElement);
150 
151  virtual bool set_value(dods_byte *val, int sz);
152  virtual bool set_value(vector<dods_byte> &val, int sz);
153  virtual bool set_value(dods_int16 *val, int sz);
154  virtual bool set_value(vector<dods_int16> &val, int sz);
155  virtual bool set_value(dods_uint16 *val, int sz);
156  virtual bool set_value(vector<dods_uint16> &val, int sz);
157  virtual bool set_value(dods_int32 *val, int sz);
158  virtual bool set_value(vector<dods_int32> &val, int sz);
159  virtual bool set_value(dods_uint32 *val, int sz);
160  virtual bool set_value(vector<dods_uint32> &val, int sz);
161  virtual bool set_value(dods_float32 *val, int sz);
162  virtual bool set_value(vector<dods_float32> &val, int sz);
163  virtual bool set_value(dods_float64 *val, int sz);
164  virtual bool set_value(vector<dods_float64> &val, int sz);
165  virtual bool set_value(string *val, int sz);
166  virtual bool set_value(vector<string> &val, int sz);
167 
168  virtual void value(dods_byte *b) const;
169  virtual void value(dods_int16 *b) const;
170  virtual void value(dods_uint16 *b) const;
171  virtual void value(dods_int32 *b) const;
172  virtual void value(dods_uint32 *b) const;
173  virtual void value(dods_float32 *b) const;
174  virtual void value(dods_float64 *b) const;
175  virtual void value(vector<string> &b) const;
176 
177  void value(vector<unsigned int> *index, dods_byte *b) const;
178  void value(vector<unsigned int> *index, dods_int16 *b) const;
179  void value(vector<unsigned int> *index, dods_uint16 *b) const;
180  void value(vector<unsigned int> *index, dods_int32 *b) const;
181  void value(vector<unsigned int> *index, dods_uint32 *b) const;
182  void value(vector<unsigned int> *index, dods_float32 *b) const;
183  void value(vector<unsigned int> *index, dods_float64 *b) const;
184  void value(vector<unsigned int> *index, vector<string> &b) const;
185 
186  virtual void *value();
187 
188  virtual BaseType *var(const string &name = "", bool exact_match = true,
189  btp_stack *s = 0);
190  virtual BaseType *var(const string &name, btp_stack &s);
191  virtual BaseType *var(unsigned int i);
192 
193  virtual void add_var(BaseType *v, Part p = nil);
194  virtual void add_var_nocopy(BaseType *v, Part p = nil);
195 
196  virtual bool check_semantics(string &msg, bool all = false);
197 
198  virtual void dump(ostream &strm) const ;
199 };
200 
201 } // namespace libdap
202 
203 #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: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
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
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
uint16_t dods_uint16
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 BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
Definition: Vector.cc:380
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
Definition: Vector.cc:713
double dods_float64
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
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
string name() const
Returns the name of the class instance.
Definition: BaseType.cc:254
Vector(const string &n, BaseType *v, const Type &t)
The Vector constructor.
Definition: Vector.cc:228
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: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 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
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
int32_t dods_int32