libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4Sequence.h
Go to the documentation of this file.
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of libdap, A C++ implementation of the OPeNDAP Data
4// Access Protocol.
5
6// Copyright (c) 2013 OPeNDAP, Inc.
7// Author: James Gallagher <jgallagher@opendap.org>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22//
23// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24
25#ifndef _d4sequence_h
26#define _d4sequence_h 1
27
28#include "Constructor.h"
29
30// DAP2 Sequence supported subsetting using the array notation. This might
31// be introduced into DAP4 later on.
32#define INDEX_SUBSETTING 0
33
34class Crc32;
35
36namespace libdap {
37class BaseType;
38class D4FilterClauseList;
39
42typedef vector<BaseType *> D4SeqRow;
43
45typedef vector<D4SeqRow *> D4SeqValues;
46
49typedef vector<BaseType *> BaseTypeRow;
50
52typedef vector<BaseTypeRow *> SequenceValues;
53
130
131class D4Sequence : public Constructor {
132private:
133 // This may be zero (nullptr) but the accessor (clauses()) allocates an
134 // instance if that is the case.
135 D4FilterClauseList *d_clauses;
136
137 // Use this to control if ptr_duplicate(), ..., copy the filter clauses.
138 // Because the values of a child sequence are held in copies of the Seq
139 // object they clauses will be bound to the 'master' instance will be copied
140 // but the copies will never be used. This field can be used to control
141 // that. ...purely an optimization.
142 bool d_copy_clauses;
143
144protected:
145 // This holds the values of the sequence. Values are stored in
146 // instances of BaseTypeRow objects which hold instances of BaseType.
147 //
148 // Allow these values to be accessed by subclasses
150
151 int64_t d_length; // How many elements are in the sequence; -1 if not currently known
152
153#if INDEX_SUBSETTING
154 int d_starting_row_number;
155 int d_row_stride;
156 int d_ending_row_number;
157#endif
158
159 void m_duplicate(const D4Sequence &s);
160
161 // Specialize this if you have a data source that requires read()
162 // recursively call itself for child sequences.
163 void read_sequence_values(bool filter);
164
165 friend class D4SequenceTest;
166
167public:
168 D4Sequence(const string &n);
169 D4Sequence(const string &n, const string &d);
170
171 D4Sequence(const D4Sequence &rhs);
172
173 virtual ~D4Sequence();
174
175 D4Sequence &operator=(const D4Sequence &rhs);
176
177 BaseType *ptr_duplicate() override;
178
179 void clear_local_data() override;
180
189 int length() const override { return (int)d_length; }
190
195 void set_length(int64_t count) override { d_length = count; }
196 // FIXME length() and set_length()
197
198 virtual bool read_next_instance(bool filter);
199
200 void intern_data(ConstraintEvaluator &, DDS &) override {
201 throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
202 }
203 bool serialize(ConstraintEvaluator &, DDS &, Marshaller &, bool) override {
204 throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
205 }
206 bool deserialize(UnMarshaller &, DDS *, bool) override {
207 throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
208 }
209
210 // DAP4
211 void intern_data() override;
212 void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter = false) override;
213 void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override;
214
216
217#if INDEX_SUBSETTING
229 virtual int get_starting_row_number() const { return d_starting_row_number; }
230
241 virtual int get_row_stride() const { return d_row_stride; }
242
254 virtual int get_ending_row_number() const { return d_ending_row_number; }
255
256 virtual void set_row_number_constraint(int start, int stop, int stride = 1);
257#endif
258
268 virtual void set_value(D4SeqValues &values) {
269 d_values = values;
270 d_length = d_values.size();
271 }
272
281 virtual D4SeqValues value() const { return d_values; }
282
291 virtual D4SeqValues &value_ref() { return d_values; }
292
293 virtual D4SeqRow *row_value(size_t row);
294 virtual BaseType *var_value(size_t row, const string &name);
295 virtual BaseType *var_value(size_t row, size_t i);
296
297 virtual void print_one_row(ostream &out, int row, string space, bool print_row_num = false);
298 virtual void print_val_by_rows(ostream &out, string space = "", bool print_decl_p = true,
299 bool print_row_numbers = true);
300 void print_val(ostream &out, string space = "", bool print_decl_p = true) override;
301
302 void dump(ostream &strm) const override;
303};
304
305} // namespace libdap
306
307#endif //_sequence_h
Definition crc.h:43
The basic data type for the DODS DAP types.
Definition BaseType.h:118
virtual string name() const
Returns the name of the class instance.
Definition BaseType.cc:296
Evaluate a constraint expression.
Constructor(const string &name, const Type &type, bool is_dap4=false)
Definition Constructor.h:52
List of DAP4 Filter Clauses.
virtual D4SeqRow * row_value(size_t row)
Get a whole row from the sequence.
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...
BaseType * ptr_duplicate() override
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
D4Sequence(const string &n)
The Sequence constructor.
Definition D4Sequence.cc:94
int length() const override
The number of elements in a Sequence object.
Definition D4Sequence.h:189
virtual void print_one_row(ostream &out, int row, string space, bool print_row_num=false)
D4FilterClauseList & clauses()
Access the filter clauses for this D4Sequence.
virtual void print_val_by_rows(ostream &out, string space="", bool print_decl_p=true, bool print_row_numbers=true)
void intern_data(ConstraintEvaluator &, DDS &) override
Definition D4Sequence.h:200
D4SeqValues d_values
Definition D4Sequence.h:149
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
virtual D4SeqValues & value_ref()
Get the sequence values by reference This method returns a reference to the D4Sequence's values,...
Definition D4Sequence.h:291
void set_length(int64_t count) override
Definition D4Sequence.h:195
bool serialize(ConstraintEvaluator &, DDS &, Marshaller &, bool) override
Move data to the net, then remove them from the object.
Definition D4Sequence.h:203
void m_duplicate(const D4Sequence &s)
Definition D4Sequence.cc:60
bool deserialize(UnMarshaller &, DDS *, bool) override
Receive data from the net.
Definition D4Sequence.h:206
void dump(ostream &strm) const override
dumps information about this object
void print_val(ostream &out, string space="", bool print_decl_p=true) override
Prints the value of the variable.
void intern_data() override
Read data into this variable.
friend class D4SequenceTest
Definition D4Sequence.h:165
void read_sequence_values(bool filter)
Read a Sequence's value into memory.
virtual BaseType * var_value(size_t row, const string &name)
Get the BaseType pointer to the named variable of a given row.
D4Sequence & operator=(const D4Sequence &rhs)
void clear_local_data() override
virtual ~D4Sequence()
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
Read data from the stream made by D4StreamMarshaller.
A class for software fault reporting.
Definition InternalErr.h:61
abstract base class used to marshal/serialize dap data objects
Definition Marshaller.h:50
abstract base class used to unmarshall/deserialize dap data objects
top level DAP object to house generic methods
Definition AISConnect.cc:30
vector< BaseType * > BaseTypeRow
Definition D4Sequence.h:49
vector< BaseType * > D4SeqRow
Definition D4Sequence.h:42
vector< BaseTypeRow * > SequenceValues
Definition D4Sequence.h:52
vector< D4SeqRow * > D4SeqValues
Definition D4Sequence.h:45