libdap Updated for version 3.20.11
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4Sequence.h
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
37{
38class BaseType;
39class D4FilterClauseList;
40
43typedef vector<BaseType *> D4SeqRow;
44
46typedef vector<D4SeqRow *> D4SeqValues;
47
50typedef vector<BaseType *> BaseTypeRow;
51
53typedef vector<BaseTypeRow *> SequenceValues;
54
55
134{
135private:
136 // This may be zero (nullptr) but the accessor (clauses()) allocates an
137 // instance if that is the case.
138 D4FilterClauseList *d_clauses;
139
140 // Use this to control if ptr_duplicate(), ..., copy the filter clauses.
141 // Because the values of a child sequence are held in copies of the Seq
142 // object they clauses will bound to the 'master' instance will be copied
143 // but the copies will never be used. This field can be used to control
144 // that. ...purely an optimization.
145 bool d_copy_clauses;
146
147protected:
148 // This holds the values of the sequence. Values are stored in
149 // instances of BaseTypeRow objects which hold instances of BaseType.
150 //
151 // Allow these values to be accessed by subclasses
152 D4SeqValues d_values;
153
154 int64_t d_length; // How many elements are in the sequence; -1 if not currently known
155
156#if INDEX_SUBSETTING
157 int d_starting_row_number;
158 int d_row_stride;
159 int d_ending_row_number;
160#endif
161
162 void m_duplicate(const D4Sequence &s);
163
164 // Specialize this if you have a data source that requires read()
165 // recursively call itself for child sequences.
166 void read_sequence_values(bool filter);
167
168 friend class D4SequenceTest;
169
170public:
171
172 D4Sequence(const string &n);
173 D4Sequence(const string &n, const string &d);
174
175 D4Sequence(const D4Sequence &rhs);
176
177 virtual ~D4Sequence();
178
179 D4Sequence &operator=(const D4Sequence &rhs);
180
181 virtual BaseType *ptr_duplicate();
182
183 virtual void clear_local_data();
184
193 virtual int length() const { return (int)d_length; }
194
199 virtual void set_length(int count) { d_length = (int64_t)count; }
200
201 virtual bool read_next_instance(bool filter);
202
204 throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
205 }
206 virtual bool serialize(ConstraintEvaluator &, DDS &, Marshaller &, bool ) {
207 throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
208 }
209 virtual bool deserialize(UnMarshaller &, DDS *, bool ) {
210 throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
211 }
212
213 // DAP4
214 virtual void intern_data(/*Crc32 &checksum, DMR &dmr, ConstraintEvaluator &eval*/);
215 virtual void serialize(D4StreamMarshaller &m, DMR &dmr, /*ConstraintEvaluator &eval,*/ bool filter = false);
216 virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);
217
219
220#if INDEX_SUBSETTING
232 virtual int get_starting_row_number() const { return d_starting_row_number; }
233
244 virtual int get_row_stride() const { return d_row_stride; }
245
257 virtual int get_ending_row_number() const { return d_ending_row_number; }
258
259 virtual void set_row_number_constraint(int start, int stop, int stride = 1);
260#endif
261
271 virtual void set_value(D4SeqValues &values) { d_values = values; d_length = d_values.size(); }
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,
298 bool print_row_num = false);
299 virtual void print_val_by_rows(ostream &out, string space = "",
300 bool print_decl_p = true,
301 bool print_row_numbers = true);
302 virtual void print_val(ostream &out, string space = "",
303 bool print_decl_p = true);
304
305 virtual void dump(ostream &strm) const ;
306};
307
308} // namespace libdap
309
310#endif //_sequence_h
Definition: crc.h:77
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:316
Evaluate a constraint expression.
List of DAP4 Filter Clauses.
Holds a sequence.
Definition: D4Sequence.h:134
virtual D4SeqRow * row_value(size_t row)
Get a whole row from the sequence.
Definition: D4Sequence.cc:386
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:188
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition: D4Sequence.cc:490
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:271
D4Sequence(const string &n)
The Sequence constructor.
Definition: D4Sequence.cc:96
virtual bool serialize(ConstraintEvaluator &, DDS &, Marshaller &, bool)
Move data to the net, then remove them from the object.
Definition: D4Sequence.h:206
D4FilterClauseList & clauses()
Access the filter clauses for this D4Sequence.
Definition: D4Sequence.cc:354
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
virtual void intern_data()
Read data into this variable.
Definition: D4Sequence.cc:217
virtual BaseType * ptr_duplicate()
Definition: D4Sequence.cc:123
virtual bool deserialize(UnMarshaller &, DDS *, bool)
Receive data from the net.
Definition: D4Sequence.h:209
void read_sequence_values(bool filter)
Read a Sequence's value into memory.
Definition: D4Sequence.cc:243
virtual void set_length(int count)
Definition: D4Sequence.h:199
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:398
virtual void dump(ostream &strm) const
dumps information about this object
Definition: D4Sequence.cc:505
virtual void intern_data(ConstraintEvaluator &, DDS &)
Definition: D4Sequence.h:203
virtual void clear_local_data()
Definition: D4Sequence.cc:146
virtual int length() const
The number of elements in a Sequence object.
Definition: D4Sequence.h:193
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:65
abstract base class used to marshal/serialize dap data objects
Definition: Marshaller.h:50
abstract base class used to unmarshall/deserialize dap data objects
Definition: UnMarshaller.h:55
top level DAP object to house generic methods
Definition: AlarmHandler.h:36
vector< BaseType * > BaseTypeRow
Definition: D4Sequence.h:50
vector< BaseType * > D4SeqRow
Definition: D4Sequence.h:43
vector< BaseTypeRow * > SequenceValues
Definition: D4Sequence.h:53
vector< D4SeqRow * > D4SeqValues
Definition: D4Sequence.h:46