libdap
Updated for version 3.17.0
|
00001 00002 // -*- mode: c++; c-basic-offset:4 -*- 00003 00004 // This file is part of libdap, A C++ implementation of the OPeNDAP Data 00005 // Access Protocol. 00006 00007 // Copyright (c) 2002,2003 OPeNDAP, Inc. 00008 // Author: James Gallagher <jgallagher@opendap.org> 00009 // 00010 // This library is free software; you can redistribute it and/or 00011 // modify it under the terms of the GNU Lesser General Public 00012 // License as published by the Free Software Foundation; either 00013 // version 2.1 of the License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00023 // 00024 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112. 00025 00026 // (c) COPYRIGHT URI/MIT 1995-1999 00027 // Please read the full copyright statement in the file COPYRIGHT_URI. 00028 // 00029 // Authors: 00030 // jhrg,jimg James Gallagher <jgallagher@gso.uri.edu> 00031 00032 // This is the interface definition file for the abstract class 00033 // Vector. Vector is the parent class for List and Array. 00034 00035 #ifndef _vector_h 00036 #define _vector_h 1 00037 00038 #ifndef _basetype_h 00039 #include "BaseType.h" 00040 #endif 00041 00042 #ifndef _dds_h 00043 #include "DDS.h" 00044 #endif 00045 00046 #ifndef constraint_evaluator_h 00047 #include "ConstraintEvaluator.h" 00048 #endif 00049 00050 class Crc32; 00051 00052 namespace libdap 00053 { 00054 00080 class Vector: public BaseType 00081 { 00082 private: 00083 int d_length; // number of elements in the vector 00084 BaseType *d_proto; // element prototype for the Vector 00085 00086 // _buf was a pointer to void; delete[] complained. 6/4/2001 jhrg 00087 char *d_buf; // storage for cardinal data 00088 vector<string> d_str; // special storage for strings. jhrg 2/11/05 00089 vector<BaseType *> d_compound_buf; // storage for data in compound types (e.g., Structure) 00090 00091 // the number of elements we have allocated memory to store. 00092 // This should be either the sizeof(buf)/width(bool constrained = false) for cardinal data 00093 // or the capacity of d_str for strings or capacity of _vec. 00094 unsigned int d_capacity; 00095 00096 friend class MarshallerTest; 00097 00098 /* 00099 * Made these template methods private because they can't be 00100 * overridden anyways (because c++...) - ndp 08/14/2015 00101 * 00102 */ 00103 00104 template <typename T> void value_worker(T *v) const; 00105 template <typename T> void value_worker(vector<unsigned int> *indices, T *b) const; 00106 00107 template <typename T> bool set_value_worker(T *v, int sz); 00108 template <typename T> bool set_value_worker(vector<T> &v, int sz); 00109 00110 protected: 00111 // This function copies the private members of Vector. 00112 void m_duplicate(const Vector &v); 00113 00114 bool m_is_cardinal_type() const; 00115 unsigned int m_create_cardinal_data_buffer_for_type(unsigned int numEltsOfType); 00116 void m_delete_cardinal_data_buffer(); 00117 00118 template <class CardType> void m_set_cardinal_values_internal(const CardType* fromArray, int numElts); 00119 00120 public: 00121 Vector(const string &n, BaseType *v, const Type &t, bool is_dap4 = false); 00122 Vector(const string &n, const string &d, BaseType *v, const Type &t, bool is_dap4 = false); 00123 Vector(const Vector &rhs); 00124 00125 virtual ~Vector(); 00126 00127 Vector &operator=(const Vector &rhs); 00128 virtual BaseType *ptr_duplicate() = 0; 00129 00138 char *get_buf() { 00139 return d_buf; 00140 } 00141 00148 vector<string> &get_str() { 00149 return d_str; 00150 } 00151 00159 vector<BaseType*> &get_compound_buf() { 00160 return d_compound_buf; 00161 } 00162 00163 #if 0 00164 virtual bool is_dap2_only_type(); 00165 #endif 00166 00167 virtual BaseType *prototype() const { return d_proto; } 00168 00169 virtual void set_name(const std::string& name); 00170 00171 virtual int element_count(bool leaves); 00172 00173 virtual void set_send_p(bool state); 00174 00175 virtual void set_read_p(bool state); 00176 00177 virtual unsigned int width(bool constrained = false) const; 00178 00179 virtual int length() const; 00180 00181 virtual void set_length(int l); 00182 00183 // DAP2 00184 virtual void intern_data(ConstraintEvaluator &eval, DDS &dds); 00185 virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true); 00186 #if 0 00187 virtual bool serialize_no_release(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true); 00188 #endif 00189 virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false); 00190 00191 // DAP4 00192 virtual void compute_checksum(Crc32 &checksum); 00193 virtual void intern_data(/*Crc32 &checksum*/); 00194 virtual void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter = false); 00195 #if 0 00196 virtual void serialize_no_release(D4StreamMarshaller &m, DMR &dmr, bool filter = false); 00197 #endif 00198 virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr); 00199 00200 virtual unsigned int val2buf(void *val, bool reuse = false); 00201 virtual unsigned int buf2val(void **val); 00202 00203 void set_vec(unsigned int i, BaseType *val); 00204 void set_vec_nocopy(unsigned int i, BaseType * val); 00205 00206 void vec_resize(int l); 00207 00208 virtual void clear_local_data(); 00209 00210 virtual unsigned int get_value_capacity() const; 00211 virtual void reserve_value_capacity(unsigned int numElements); 00212 virtual void reserve_value_capacity(); 00213 00214 virtual unsigned int set_value_slice_from_row_major_vector(const Vector& rowMajorData, unsigned int startElement); 00215 00216 00217 virtual bool set_value(dods_byte *val, int sz); 00218 virtual bool set_value(dods_int8 *val, int sz); 00219 virtual bool set_value(dods_int16 *val, int sz); 00220 virtual bool set_value(dods_uint16 *val, int sz); 00221 virtual bool set_value(dods_int32 *val, int sz); 00222 virtual bool set_value(dods_uint32 *val, int sz); 00223 virtual bool set_value(dods_int64 *val, int sz); 00224 virtual bool set_value(dods_uint64 *val, int sz); 00225 virtual bool set_value(dods_float32 *val, int sz); 00226 virtual bool set_value(dods_float64 *val, int sz); 00227 virtual bool set_value(string *val, int sz); 00228 00229 00230 virtual bool set_value(vector<dods_byte> &val, int sz); 00231 virtual bool set_value(vector<dods_int8> &val, int sz); 00232 virtual bool set_value(vector<dods_int16> &val, int sz); 00233 virtual bool set_value(vector<dods_uint16> &val, int sz); 00234 virtual bool set_value(vector<dods_int32> &val, int sz); 00235 virtual bool set_value(vector<dods_uint32> &val, int sz); 00236 virtual bool set_value(vector<dods_int64> &val, int sz); 00237 virtual bool set_value(vector<dods_uint64> &val, int sz); 00238 virtual bool set_value(vector<dods_float32> &val, int sz); 00239 virtual bool set_value(vector<dods_float64> &val, int sz); 00240 virtual bool set_value(vector<string> &val, int sz); 00241 00242 virtual void value(dods_byte *b) const; 00243 virtual void value(dods_int8 *b) const; 00244 virtual void value(dods_int16 *b) const; 00245 virtual void value(dods_uint16 *b) const; 00246 virtual void value(dods_int32 *b) const; 00247 virtual void value(dods_uint32 *b) const; 00248 virtual void value(dods_int64 *b) const; 00249 virtual void value(dods_uint64 *b) const; 00250 virtual void value(dods_float32 *b) const; 00251 virtual void value(dods_float64 *b) const; 00252 virtual void value(vector<string> &b) const; 00253 00254 virtual void value(vector<unsigned int> *indices, dods_byte *b) const; 00255 virtual void value(vector<unsigned int> *indices, dods_int8 *b) const; 00256 virtual void value(vector<unsigned int> *indices, dods_int16 *b) const; 00257 virtual void value(vector<unsigned int> *indices, dods_uint16 *b) const; 00258 virtual void value(vector<unsigned int> *indices, dods_int32 *b) const; 00259 virtual void value(vector<unsigned int> *indices, dods_uint32 *b) const; 00260 virtual void value(vector<unsigned int> *indices, dods_int64 *b) const; 00261 virtual void value(vector<unsigned int> *indices, dods_uint64 *b) const; 00262 virtual void value(vector<unsigned int> *indices, dods_float32 *b) const; 00263 virtual void value(vector<unsigned int> *indices, dods_float64 *b) const; 00264 virtual void value(vector<unsigned int> *index, vector<string> &b) const; 00265 00266 virtual void *value(); 00267 00268 virtual BaseType *var(const string &name = "", bool exact_match = true, btp_stack *s = 0); 00269 virtual BaseType *var(const string &name, btp_stack &s); 00270 virtual BaseType *var(unsigned int i); 00271 00272 virtual void add_var(BaseType *v, Part p = nil); 00273 virtual void add_var_nocopy(BaseType *v, Part p = nil); 00274 00275 virtual bool check_semantics(string &msg, bool all = false); 00276 00277 virtual void dump(ostream &strm) const ; 00278 }; 00279 00280 } // namespace libdap 00281 00282 #endif /* _vector_h */