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
#include <cassert>
#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:
// Add d_length_ll. This uses -1 as a sentinel value. jhrg 7/25/22
// If we decide to add a bool for 'no values yet' do that as a
// separate refactor. jhrg 7/25/22
int64_t d_length_ll = -1; // number of elements in the vector
int d_length = -1; // number of elements in the vector
BaseType *d_proto = nullptr; // element prototype for the Vector
// _buf was a pointer to void; delete[] complained. 6/4/2001 jhrg
char *d_buf = nullptr; // 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 = 0;
uint64_t d_capacity_ll = 0;
bool d_too_big_for_dap2 = false;
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_ll_worker(T *v) const;
template <typename T> void value_worker(vector<unsigned int> *indices, T *b) const;
template <typename T> void value_ll_worker(vector<uint64_t> *indices, T *b) const;
template <typename T> bool set_value_worker(T *v, int sz);
template <typename T> bool set_value_ll_worker(T *v, int64_t sz);
template <typename T> bool set_value_worker(vector<T> &v, int sz);
template <typename T> bool set_value_ll_worker(vector<T> &v, int64_t sz);
bool m_is_cardinal_type() const;
int64_t m_create_cardinal_data_buffer_for_type(int64_t num_elements);
void m_delete_cardinal_data_buffer();
template <class CardType> void m_set_cardinal_values_internal(const CardType* fromArray, int64_t num_elements);
// This function copies the private members of Vector.
void m_duplicate(const Vector &v);
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);
// FIXME BaseType *ptr_duplicate() = 0 override;
char *get_buf() {
return d_buf;
}
vector<string> &get_str() {
return d_str;
}
vector<BaseType*> &get_compound_buf() {
return d_compound_buf;
}
virtual BaseType *prototype() const { return d_proto; }
virtual BaseType *set_prototype(BaseType *btp) { BaseType *orig = d_proto; d_proto = btp; return orig; }
void set_name(const std::string& name) override;
int element_count(bool leaves) override;
void set_send_p(bool state) override;
void set_read_p(bool state) override;
unsigned int width(bool constrained = false) const override
{
// Jose Garcia
assert(d_proto);
return length() * d_proto->width(constrained);
}
int64_t width_ll(bool constrained = false) const override
{
return length_ll() * d_proto->width_ll(constrained);
}
int length() const override { return d_length; }
int64_t length_ll() const override { return d_length_ll; }
void set_length(int64_t l) override;
void set_length_ll(int64_t l) override;
// DAP2
void intern_data(ConstraintEvaluator &eval, DDS &dds) override;
bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true) override;
bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false) override;
// DAP4
void compute_checksum(Crc32 &checksum) override;
void intern_data(/*Crc32 &checksum*/) override;
void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter = false) override;
void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override;
unsigned int val2buf(void *val, bool reuse = false) override;
unsigned int buf2val(void **val) override;
uint64_t val2buf_ll(void *val, bool reuse = false);
uint64_t buf2val_ll(void **val);
void set_vec(unsigned int i, BaseType *val);
void set_vec_nocopy(unsigned int i, BaseType * val);
void set_vec_ll(uint64_t i, BaseType *val);
void set_vec_nocopy_ll(uint64_t i, BaseType * val);
void vec_resize(int l);
void vec_resize_ll(int64_t l);
void clear_local_data() override;
virtual unsigned int get_value_capacity() const;
virtual uint64_t get_value_capacity_ll() const;
void set_value_capacity(uint64_t l);
virtual void reserve_value_capacity(unsigned int numElements);
virtual void reserve_value_capacity();
virtual void reserve_value_capacity_ll(uint64_t numElements);
virtual void reserve_value_capacity_ll();
virtual void reserve_value_capacity_ll_byte(uint64_t numBytes);
virtual uint64_t set_value_slice_from_row_major_vector(const Vector& rowMajorData, uint64_t 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_ll(dods_byte *val, int64_t sz);
virtual bool set_value_ll(dods_int8 *val, int64_t sz);
virtual bool set_value_ll(dods_int16 *val, int64_t sz);
virtual bool set_value_ll(dods_uint16 *val, int64_t sz);
virtual bool set_value_ll(dods_int32 *val, int64_t sz);
virtual bool set_value_ll(dods_uint32 *val, int64_t sz);
virtual bool set_value_ll(dods_int64 *val, int64_t sz);
virtual bool set_value_ll(dods_uint64 *val, int64_t sz);
virtual bool set_value_ll(dods_float32 *val, int64_t sz);
virtual bool set_value_ll(dods_float64 *val, int64_t sz);
virtual bool set_value_ll(string *val, int64_t 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 bool set_value_ll(vector<dods_byte> &val, int64_t sz);
virtual bool set_value_ll(vector<dods_int8> &val, int64_t sz);
virtual bool set_value_ll(vector<dods_int16> &val, int64_t sz);
virtual bool set_value_ll(vector<dods_uint16> &val, int64_t sz);
virtual bool set_value_ll(vector<dods_int32> &val, int64_t sz);
virtual bool set_value_ll(vector<dods_uint32> &val, int64_t sz);
virtual bool set_value_ll(vector<dods_int64> &val, int64_t sz);
virtual bool set_value_ll(vector<dods_uint64> &val, int64_t sz);
virtual bool set_value_ll(vector<dods_float32> &val, int64_t sz);
virtual bool set_value_ll(vector<dods_float64> &val, int64_t sz);
virtual bool set_value_ll(vector<string> &val, int64_t 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_ll(vector<uint64_t> *indices, dods_byte *b) const;
virtual void value_ll(vector<uint64_t> *indices, dods_int8 *b) const;
virtual void value_ll(vector<uint64_t> *indices, dods_int16 *b) const;
virtual void value_ll(vector<uint64_t> *indices, dods_uint16 *b) const;
virtual void value_ll(vector<uint64_t> *indices, dods_int32 *b) const;
virtual void value_ll(vector<uint64_t> *indices, dods_uint32 *b) const;
virtual void value_ll(vector<uint64_t> *indices, dods_int64 *b) const;
virtual void value_ll(vector<uint64_t> *indices, dods_uint64 *b) const;
virtual void value_ll(vector<uint64_t> *indices, dods_float32 *b) const;
virtual void value_ll(vector<uint64_t> *indices, dods_float64 *b) const;
virtual void value_ll(vector<uint64_t> *index, vector<string> &b) const;
virtual void *value();
BaseType *var(const string &name = "", bool exact_match = true, btp_stack *s = nullptr) override;
BaseType *var(const string &name, btp_stack &s) override;
virtual BaseType *var(unsigned int i);
virtual BaseType *var_ll(uint64_t i);
void add_var(BaseType *v, Part p = nil) override;
void add_var_nocopy(BaseType *v, Part p = nil) override;
bool check_semantics(string &msg, bool all = false) override;
bool is_dap4_projected(std::vector<std::string> &projected_dap4_inventory) override;
void dump(ostream &strm) const override;
};
} // namespace libdap
#endif /* _vector_h */
Crc32
Definition crc.h:79
libdap::BaseType
The basic data type for the DODS DAP types.
Definition BaseType.h:120
libdap::BaseType::name
virtual string name() const
Returns the name of the class instance.
Definition BaseType.cc:317
libdap::BaseType::width
virtual unsigned int width(bool constrained=false) const
How many bytes does this variable use Return the number of bytes of storage this variable uses....
Definition BaseType.cc:1305
libdap::ConstraintEvaluator
Evaluate a constraint expression.
Definition ConstraintEvaluator.h:43
libdap::D4StreamMarshaller
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
Definition D4StreamMarshaller.h:71
libdap::D4StreamUnMarshaller
Read data from the stream made by D4StreamMarshaller.
Definition D4StreamUnMarshaller.h:65
libdap::DDS
Definition DDS.h:178
libdap::DMR
Definition DMR.h:58
libdap::Marshaller
abstract base class used to marshal/serialize dap data objects
Definition Marshaller.h:50
libdap::UnMarshaller
abstract base class used to unmarshall/deserialize dap data objects
Definition UnMarshaller.h:55
libdap::Vector
Holds a one-dimensional collection of DAP2 data types.
Definition Vector.h:83
libdap::Vector::width
unsigned int width(bool constrained=false) const override
Returns the width of the data, in bytes.
Definition Vector.h:195
libdap::Vector::reserve_value_capacity_ll_byte
virtual void reserve_value_capacity_ll_byte(uint64_t numBytes)
Definition Vector.cc:1867
libdap::Vector::deserialize
bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false) override
Receive data from the net.
Definition Vector.cc:855
libdap::Vector::set_send_p
void set_send_p(bool state) override
Indicates that the data is ready to send.
Definition Vector.cc:363
libdap::Vector::width_ll
int64_t width_ll(bool constrained=false) const override
Return the number of bytes needed to hold the array data.
Definition Vector.h:208
libdap::Vector::dump
void dump(ostream &strm) const override
dumps information about this object
Definition Vector.cc:2665
libdap::Vector::set_prototype
virtual BaseType * set_prototype(BaseType *btp)
Change the Vector/Array element type.
Definition Vector.h:178
libdap::Vector::compute_checksum
void compute_checksum(Crc32 &checksum) override
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
Definition Vector.cc:959
libdap::Vector::get_compound_buf
vector< BaseType * > & get_compound_buf()
Definition Vector.h:167
libdap::Vector::get_value_capacity
virtual unsigned int get_value_capacity() const
Definition Vector.cc:1700
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:1606
libdap::Vector::MarshallerTest
friend class MarshallerTest
Conditionally set to true in set_length_ll()
Definition Vector.h:106
libdap::Vector::add_var
void add_var(BaseType *v, Part p=nil) override
Add the BaseType pointer to this constructor type instance.
Definition Vector.cc:2552
libdap::Vector::length
int length() const override
Returns the number of elements in the vector. Note that some child classes of Vector use the length o...
Definition Vector.h:218
libdap::Vector::length_ll
int64_t length_ll() const override
Get the number of elements in this Vector/Array This version of the function deprecates length() whic...
Definition Vector.h:226
libdap::Vector::set_read_p
void set_read_p(bool state) override
Indicates that the data is ready to send.
Definition Vector.cc:400
libdap::Vector::element_count
int element_count(bool leaves) override
Count the members of constructor types.
Definition Vector.cc:342
libdap::Vector::set_length_ll
void set_length_ll(int64_t l) override
Set the number of elements in this Vector/Array This version of the function deprecates set_length() ...
Definition Vector.cc:446
libdap::Vector::set_vec
void set_vec(unsigned int i, BaseType *val)
Sets element i to value val.
Definition Vector.cc:1585
libdap::Vector::is_dap4_projected
bool is_dap4_projected(std::vector< std::string > &projected_dap4_inventory) override
Definition Vector.cc:2631
libdap::Vector::set_name
void set_name(const std::string &name) override
Sets the name of the class instance.
Definition Vector.cc:332
libdap::Vector::check_semantics
bool check_semantics(string &msg, bool all=false) override
Compare an object's current state with the semantics of its type.
Definition Vector.cc:2619
libdap::Vector::intern_data
void intern_data() override
Read data into this variable.
Definition Vector.cc:1001
libdap::Vector::reserve_value_capacity_ll
virtual void reserve_value_capacity_ll()
Definition Vector.cc:1856
libdap::Vector::val2buf
unsigned int val2buf(void *val, bool reuse=false) override
Reads data into the Vector buffer.
Definition Vector.cc:1329
libdap::Vector::get_buf
char * get_buf()
Definition Vector.h:146
libdap::Vector::var
BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=nullptr) override
Definition Vector.cc:486
libdap::Vector::set_value_slice_from_row_major_vector
virtual uint64_t set_value_slice_from_row_major_vector(const Vector &rowMajorData, uint64_t startElement)
Definition Vector.cc:1901
libdap::Vector::value
virtual void * value()
Definition Vector.cc:2527
libdap::Vector::serialize
bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true) override
Serialize a Vector.
Definition Vector.cc:752
libdap::Vector::get_str
vector< string > & get_str()
Definition Vector.h:156
libdap::Vector::vec_resize
void vec_resize(int l)
Definition Vector.cc:637
libdap::Vector::reserve_value_capacity
virtual void reserve_value_capacity()
Definition Vector.cc:1780
libdap::Vector::buf2val
unsigned int buf2val(void **val) override
Copies data from the Vector buffer.
Definition Vector.cc:1452
libdap::Vector::clear_local_data
void clear_local_data() override
Definition Vector.cc:1672
libdap::Vector::set_length
void set_length(int64_t l) override
Sets the length of the vector. This function does not allocate any new space.
Definition Vector.cc:434
libdap
top level DAP object to house generic methods
Definition AlarmHandler.h:36
libdap::Type
Type
Identifies the data type.
Definition Type.h:94
libdap::Part
Part
Names the parts of multi-section constructor data types.
Definition Type.h:48