Vector.h
// -*- mode: c++; c-basic-offset:4 -*-
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.
// Copyright (c) 2002,2003 OPeNDAP, Inc.
// Author: James Gallagher <jgallagher@opendap.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
// (c) COPYRIGHT URI/MIT 1995-1999
// Please read the full copyright statement in the file COPYRIGHT_URI.
//
// Authors:
// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
// This is the interface definition file for the abstract class
// Vector. Vector is the parent class for List and Array.
#ifndef _vector_h
#define _vector_h 1
#ifndef _basetype_h
#include "BaseType.h"
#endif
#ifndef _dds_h
#include "DDS.h"
#endif
#ifndef constraint_evaluator_h
#include "ConstraintEvaluator.h"
#endif
class Crc32;
namespace libdap
{
class Vector: public BaseType
{
private:
int d_length; // number of elements in the vector
BaseType *d_proto; // element prototype for the Vector
// _buf was a pointer to void; delete[] complained. 6/4/2001 jhrg
char *d_buf; // storage for cardinal data
vector<string> d_str; // special storage for strings. jhrg 2/11/05
vector<BaseType *> d_compound_buf; // storage for data in compound types (e.g., Structure)
// the number of elements we have allocated memory to store.
// This should be either the sizeof(buf)/width(bool constrained = false) for cardinal data
// or the capacity of d_str for strings or capacity of _vec.
unsigned int d_capacity;
friend class MarshallerTest;
/*
* Made these template methods private because they can't be
* overridden anyways (because c++...) - ndp 08/14/2015
*
*/
template <typename T> void value_worker(T *v) const;
template <typename T> void value_worker(vector<unsigned int> *indices, T *b) const;
template <typename T> bool set_value_worker(T *v, int sz);
template <typename T> bool set_value_worker(vector<T> &v, int sz);
protected:
// This function copies the private members of Vector.
void m_duplicate(const Vector &v);
bool m_is_cardinal_type() const;
unsigned int m_create_cardinal_data_buffer_for_type(unsigned int numEltsOfType);
void m_delete_cardinal_data_buffer();
template <class CardType> void m_set_cardinal_values_internal(const CardType* fromArray, int numElts);
public:
Vector(const string &n, BaseType *v, const Type &t, bool is_dap4 = false);
Vector(const string &n, const string &d, BaseType *v, const Type &t, bool is_dap4 = false);
Vector(const Vector &rhs);
virtual ~Vector();
Vector &operator=(const Vector &rhs);
virtual BaseType *ptr_duplicate() = 0;
char *get_buf() {
return d_buf;
}
vector<string> &get_str() {
return d_str;
}
vector<BaseType*> &get_compound_buf() {
return d_compound_buf;
}
#if 0
virtual bool is_dap2_only_type();
#endif
virtual BaseType *prototype() const { return d_proto; }
virtual void set_name(const std::string& name);
virtual int element_count(bool leaves);
virtual void set_send_p(bool state);
virtual void set_read_p(bool state);
virtual unsigned int width(bool constrained = false) const;
virtual int length() const;
virtual void set_length(int l);
// DAP2
virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
#if 0
virtual bool serialize_no_release(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
#endif
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
// DAP4
virtual void compute_checksum(Crc32 &checksum);
virtual void intern_data(/*Crc32 &checksum*/);
virtual void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter = false);
#if 0
virtual void serialize_no_release(D4StreamMarshaller &m, DMR &dmr, bool filter = false);
#endif
virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);
virtual unsigned int val2buf(void *val, bool reuse = false);
virtual unsigned int buf2val(void **val);
void set_vec(unsigned int i, BaseType *val);
void set_vec_nocopy(unsigned int i, BaseType * val);
void vec_resize(int l);
virtual void clear_local_data();
virtual unsigned int get_value_capacity() const;
virtual void reserve_value_capacity(unsigned int numElements);
virtual void reserve_value_capacity();
virtual unsigned int set_value_slice_from_row_major_vector(const Vector& rowMajorData, unsigned int startElement);
virtual bool set_value(dods_byte *val, int sz);
virtual bool set_value(dods_int8 *val, int sz);
virtual bool set_value(dods_int16 *val, int sz);
virtual bool set_value(dods_uint16 *val, int sz);
virtual bool set_value(dods_int32 *val, int sz);
virtual bool set_value(dods_uint32 *val, int sz);
virtual bool set_value(dods_int64 *val, int sz);
virtual bool set_value(dods_uint64 *val, int sz);
virtual bool set_value(dods_float32 *val, int sz);
virtual bool set_value(dods_float64 *val, int sz);
virtual bool set_value(string *val, int sz);
virtual bool set_value(vector<dods_byte> &val, int sz);
virtual bool set_value(vector<dods_int8> &val, int sz);
virtual bool set_value(vector<dods_int16> &val, int sz);
virtual bool set_value(vector<dods_uint16> &val, int sz);
virtual bool set_value(vector<dods_int32> &val, int sz);
virtual bool set_value(vector<dods_uint32> &val, int sz);
virtual bool set_value(vector<dods_int64> &val, int sz);
virtual bool set_value(vector<dods_uint64> &val, int sz);
virtual bool set_value(vector<dods_float32> &val, int sz);
virtual bool set_value(vector<dods_float64> &val, int sz);
virtual bool set_value(vector<string> &val, int sz);
virtual void value(dods_byte *b) const;
virtual void value(dods_int8 *b) const;
virtual void value(dods_int16 *b) const;
virtual void value(dods_uint16 *b) const;
virtual void value(dods_int32 *b) const;
virtual void value(dods_uint32 *b) const;
virtual void value(dods_int64 *b) const;
virtual void value(dods_uint64 *b) const;
virtual void value(dods_float32 *b) const;
virtual void value(dods_float64 *b) const;
virtual void value(vector<string> &b) const;
virtual void value(vector<unsigned int> *indices, dods_byte *b) const;
virtual void value(vector<unsigned int> *indices, dods_int8 *b) const;
virtual void value(vector<unsigned int> *indices, dods_int16 *b) const;
virtual void value(vector<unsigned int> *indices, dods_uint16 *b) const;
virtual void value(vector<unsigned int> *indices, dods_int32 *b) const;
virtual void value(vector<unsigned int> *indices, dods_uint32 *b) const;
virtual void value(vector<unsigned int> *indices, dods_int64 *b) const;
virtual void value(vector<unsigned int> *indices, dods_uint64 *b) const;
virtual void value(vector<unsigned int> *indices, dods_float32 *b) const;
virtual void value(vector<unsigned int> *indices, dods_float64 *b) const;
virtual void value(vector<unsigned int> *index, vector<string> &b) const;
virtual void *value();
virtual BaseType *var(const string &name = "", bool exact_match = true, btp_stack *s = 0);
virtual BaseType *var(const string &name, btp_stack &s);
virtual BaseType *var(unsigned int i);
virtual void add_var(BaseType *v, Part p = nil);
virtual void add_var_nocopy(BaseType *v, Part p = nil);
virtual bool check_semantics(string &msg, bool all = false);
virtual void dump(ostream &strm) const ;
};
} // namespace libdap
#endif /* _vector_h */
libdap::BaseType::name
virtual string name() const
Returns the name of the class instance.
Definition: BaseType.cc:311
libdap::UnMarshaller
abstract base class used to unmarshall/deserialize dap data objects
Definition: UnMarshaller.h:54
libdap::Vector::set_vec
void set_vec(unsigned int i, BaseType *val)
Sets element i to value val.
Definition: Vector.cc:1341
libdap::Part
Part
Names the parts of multi-section constructor data types.
Definition: Type.h:48
libdap::Vector
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:80
libdap::Vector::width
virtual unsigned int width(bool constrained=false) const
Returns the width of the data, in bytes.
Definition: Vector.cc:543
libdap::Vector::intern_data
virtual void intern_data()
Read data into this variable.
Definition: Vector.cc:918
libdap::Vector::clear_local_data
virtual void clear_local_data()
Definition: Vector.cc:1394
libdap::D4StreamUnMarshaller
Read data from the stream made by D4StreamMarshaller.
Definition: D4StreamUnMarshaller.h:65
libdap::Vector::compute_checksum
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:875
libdap::Vector::set_read_p
virtual void set_read_p(bool state)
Indicates that the data is ready to send.
Definition: Vector.cc:392
Crc32
Definition: crc.h:76
libdap::Vector::add_var
virtual void add_var(BaseType *v, Part p=nil)
Add the BaseType pointer to this constructor type instance.
Definition: Vector.cc:1975
libdap::Vector::element_count
virtual int element_count(bool leaves)
Count the members of constructor types.
Definition: Vector.cc:334
libdap::Vector::value
virtual void * value()
Definition: Vector.cc:1950
libdap::Vector::m_set_cardinal_values_internal
void m_set_cardinal_values_internal(const CardType *fromArray, int numElts)
Definition: Vector.cc:220
libdap::Vector::set_value_slice_from_row_major_vector
virtual unsigned int set_value_slice_from_row_major_vector(const Vector &rowMajorData, unsigned int startElement)
Definition: Vector.cc:1529
libdap::Type
Type
Identifies the data type.
Definition: Type.h:94
libdap::Vector::serialize
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Serialize a Vector.
Definition: Vector.cc:670
libdap
Definition: AlarmHandler.h:35
libdap::Vector::var
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
Definition: Vector.cc:434
libdap::Vector::deserialize
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
Definition: Vector.cc:770
libdap::Vector::get_str
vector< string > & get_str()
Definition: Vector.h:148
libdap::Vector::get_compound_buf
vector< BaseType * > & get_compound_buf()
Definition: Vector.h:159
libdap::DMR
Definition: DMR.h:55
libdap::D4StreamMarshaller
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4&#39;s receiv...
Definition: D4StreamMarshaller.h:71
libdap::DDS
Definition: DDS.h:180
libdap::Vector::set_vec_nocopy
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:1357
libdap::Vector::m_is_cardinal_type
bool m_is_cardinal_type() const
Definition: Vector.cc:124
libdap::Vector::reserve_value_capacity
virtual void reserve_value_capacity()
Definition: Vector.cc:1494
libdap::Vector::Vector
Vector(const string &n, BaseType *v, const Type &t, bool is_dap4=false)
The Vector constructor.
Definition: Vector.cc:249
libdap::Vector::val2buf
virtual unsigned int val2buf(void *val, bool reuse=false)
Reads data into the Vector buffer.
Definition: Vector.cc:1165
libdap::Vector::get_buf
char * get_buf()
Definition: Vector.h:138
libdap::Vector::check_semantics
virtual bool check_semantics(string &msg, bool all=false)
Compare an object&#39;s current state with the semantics of its type.
Definition: Vector.cc:2045
libdap::Vector::m_delete_cardinal_data_buffer
void m_delete_cardinal_data_buffer()
Definition: Vector.cc:209
libdap::Vector::get_value_capacity
virtual unsigned int get_value_capacity() const
Definition: Vector.cc:1421
libdap::ConstraintEvaluator
Evaluate a constraint expression.
Definition: ConstraintEvaluator.h:42
libdap::Vector::ptr_duplicate
virtual BaseType * ptr_duplicate()=0
libdap::Vector::set_send_p
virtual void set_send_p(bool state)
Indicates that the data is ready to send.
Definition: Vector.cc:355
libdap::Vector::m_create_cardinal_data_buffer_for_type
unsigned int m_create_cardinal_data_buffer_for_type(unsigned int numEltsOfType)
Definition: Vector.cc:181
libdap::BaseType
The basic data type for the DODS DAP types.
Definition: BaseType.h:117
libdap::Marshaller
abstract base class used to marshal/serialize dap data objects
Definition: Marshaller.h:50
libdap::Vector::set_name
virtual void set_name(const std::string &name)
Sets the name of the class instance.
Definition: Vector.cc:324
libdap::Vector::length
virtual int length() const
Definition: Vector.cc:555
libdap::Vector::buf2val
virtual unsigned int buf2val(void **val)
Definition: Vector.cc:1261
libdap::Vector::set_length
virtual void set_length(int l)
Definition: Vector.cc:562
libdap::Vector::vec_resize
void vec_resize(int l)
Definition: Vector.cc:575
libdap::Vector::dump
virtual void dump(ostream &strm) const
dumps information about this object
Definition: Vector.cc:2058