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 */