D4Sequence.h
// -*- mode: c++; c-basic-offset:4 -*-
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.
// Copyright (c) 2013 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
#ifndef _d4sequence_h
#define _d4sequence_h 1
#include "Constructor.h"
// DAP2 Sequence supported subsetting using the array notation. This might
// be introduced into DAP4 later on.
#define INDEX_SUBSETTING 0
class Crc32;
namespace libdap {
class BaseType;
class D4FilterClauseList;
typedef vector<BaseType *> D4SeqRow;
typedef vector<D4SeqRow *> D4SeqValues;
typedef vector<BaseType *> BaseTypeRow;
typedef vector<BaseTypeRow *> SequenceValues;
class D4Sequence : public Constructor {
private:
// This may be zero (nullptr) but the accessor (clauses()) allocates an
// instance if that is the case.
D4FilterClauseList *d_clauses;
// Use this to control if ptr_duplicate(), ..., copy the filter clauses.
// Because the values of a child sequence are held in copies of the Seq
// object they clauses will be bound to the 'master' instance will be copied
// but the copies will never be used. This field can be used to control
// that. ...purely an optimization.
bool d_copy_clauses;
protected:
// This holds the values of the sequence. Values are stored in
// instances of BaseTypeRow objects which hold instances of BaseType.
//
// Allow these values to be accessed by subclasses
D4SeqValues d_values;
int64_t d_length; // How many elements are in the sequence; -1 if not currently known
#if INDEX_SUBSETTING
int d_starting_row_number;
int d_row_stride;
int d_ending_row_number;
#endif
void m_duplicate(const D4Sequence &s);
// Specialize this if you have a data source that requires read()
// recursively call itself for child sequences.
void read_sequence_values(bool filter);
friend class D4SequenceTest;
public:
D4Sequence(const string &n);
D4Sequence(const string &n, const string &d);
D4Sequence(const D4Sequence &rhs);
virtual ~D4Sequence();
D4Sequence &operator=(const D4Sequence &rhs);
BaseType *ptr_duplicate() override;
void clear_local_data() override;
int length() const override { return (int)d_length; }
void set_length(int64_t count) override { d_length = count; }
// FIXME length() and set_length()
virtual bool read_next_instance(bool filter);
void intern_data(ConstraintEvaluator &, DDS &) override {
throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
}
bool serialize(ConstraintEvaluator &, DDS &, Marshaller &, bool) override {
throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
}
bool deserialize(UnMarshaller &, DDS *, bool) override {
throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
}
// DAP4
void intern_data() override;
void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter = false) override;
void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override;
D4FilterClauseList &clauses();
#if INDEX_SUBSETTING
virtual int get_starting_row_number() const { return d_starting_row_number; }
virtual int get_row_stride() const { return d_row_stride; }
virtual int get_ending_row_number() const { return d_ending_row_number; }
virtual void set_row_number_constraint(int start, int stop, int stride = 1);
#endif
virtual void set_value(D4SeqValues &values) {
d_values = values;
d_length = d_values.size();
}
virtual D4SeqValues value() const { return d_values; }
virtual D4SeqValues &value_ref() { return d_values; }
virtual D4SeqRow *row_value(size_t row);
virtual BaseType *var_value(size_t row, const string &name);
virtual BaseType *var_value(size_t row, size_t i);
virtual void print_one_row(ostream &out, int row, string space, bool print_row_num = false);
virtual void print_val_by_rows(ostream &out, string space = "", bool print_decl_p = true,
bool print_row_numbers = true);
void print_val(ostream &out, string space = "", bool print_decl_p = true) override;
void dump(ostream &strm) const override;
};
} // namespace libdap
#endif //_sequence_h
Crc32
Definition crc.h:45
libdap::BaseType
The basic data type for the DODS DAP types.
Definition BaseType.h:118
libdap::BaseType::name
virtual string name() const
Returns the name of the class instance.
Definition BaseType.cc:296
libdap::ConstraintEvaluator
Evaluate a constraint expression.
Definition ConstraintEvaluator.h:41
libdap::Constructor
Definition Constructor.h:42
libdap::D4FilterClauseList
List of DAP4 Filter Clauses.
Definition D4FilterClause.h:44
libdap::D4Sequence
Holds a sequence.
Definition D4Sequence.h:131
libdap::D4Sequence::row_value
virtual D4SeqRow * row_value(size_t row)
Get a whole row from the sequence.
Definition D4Sequence.cc:357
libdap::D4Sequence::read_next_instance
virtual bool read_next_instance(bool filter)
Read the next instance of the sequence While the rest of the variables' read() methods are assumed to...
Definition D4Sequence.cc:169
libdap::D4Sequence::ptr_duplicate
BaseType * ptr_duplicate() override
Definition D4Sequence.cc:114
libdap::D4Sequence::set_value
virtual void set_value(D4SeqValues &values)
Set the internal value. The 'values' of a D4Sequence is a vector of vectors of BaseType* objects....
Definition D4Sequence.h:268
libdap::D4Sequence::length
int length() const override
The number of elements in a Sequence object.
Definition D4Sequence.h:189
libdap::D4Sequence::clauses
D4FilterClauseList & clauses()
Access the filter clauses for this D4Sequence.
Definition D4Sequence.cc:328
libdap::D4Sequence::intern_data
void intern_data(ConstraintEvaluator &, DDS &) override
Definition D4Sequence.h:200
libdap::D4Sequence::value
virtual D4SeqValues value() const
Get the values for this D4Sequence This method returns a reference to the values held by the instance...
Definition D4Sequence.h:281
libdap::D4Sequence::value_ref
virtual D4SeqValues & value_ref()
Get the sequence values by reference This method returns a reference to the D4Sequence's values,...
Definition D4Sequence.h:291
libdap::D4Sequence::set_length
void set_length(int64_t count) override
Definition D4Sequence.h:195
libdap::D4Sequence::serialize
bool serialize(ConstraintEvaluator &, DDS &, Marshaller &, bool) override
Move data to the net, then remove them from the object.
Definition D4Sequence.h:203
libdap::D4Sequence::deserialize
bool deserialize(UnMarshaller &, DDS *, bool) override
Receive data from the net.
Definition D4Sequence.h:206
libdap::D4Sequence::dump
void dump(ostream &strm) const override
dumps information about this object
Definition D4Sequence.cc:473
libdap::D4Sequence::print_val
void print_val(ostream &out, string space="", bool print_decl_p=true) override
Prints the value of the variable.
Definition D4Sequence.cc:459
libdap::D4Sequence::intern_data
void intern_data() override
Read data into this variable.
Definition D4Sequence.cc:197
libdap::D4Sequence::read_sequence_values
void read_sequence_values(bool filter)
Read a Sequence's value into memory.
Definition D4Sequence.cc:220
libdap::D4Sequence::var_value
virtual BaseType * var_value(size_t row, const string &name)
Get the BaseType pointer to the named variable of a given row.
Definition D4Sequence.cc:368
libdap::D4Sequence::clear_local_data
void clear_local_data() override
Definition D4Sequence.cc:129
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:176
libdap::DMR
Definition DMR.h:56
libdap::InternalErr
A class for software fault reporting.
Definition InternalErr.h:61
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:53
libdap
top level DAP object to house generic methods
Definition AlarmHandler.h:35
libdap::BaseTypeRow
vector< BaseType * > BaseTypeRow
Definition D4Sequence.h:49
libdap::D4SeqRow
vector< BaseType * > D4SeqRow
Definition D4Sequence.h:42
libdap::SequenceValues
vector< BaseTypeRow * > SequenceValues
Definition D4Sequence.h:52
libdap::D4SeqValues
vector< D4SeqRow * > D4SeqValues
Definition D4Sequence.h:45