libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
Sequence.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) 2002,2003 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24
25// (c) COPYRIGHT URI/MIT 1994-1999
26// Please read the full copyright statement in the file COPYRIGHT_URI.
27//
28// Authors:
29// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
30
31// Interface for the class Sequence. A sequence contains a single set
32// of variables, all at the same lexical level just like a structure
33// (and like a structure, it may contain other ctor types...). Unlike
34// a structure, a sequence defines a pattern that is repeated N times
35// for a sequence of N elements. Thus, Sequence { String name; Int32
36// age; } person; means a sequence of N persons where each contain a
37// name and age. The sequence can be arbitrarily long (i.e., you don't
38// know N by looking at the sequence declaration.
39//
40// jhrg 9/14/94
41
42#ifndef _sequence_h
43#define _sequence_h 1
44
45#include <stack>
46
47#include "Constructor.h"
48
49#ifndef S_XDRUtils_h
50#include "XDRUtils.h"
51#endif
52
53namespace libdap {
54
55class BaseType;
57class D4Group;
58
61typedef vector<BaseType *> BaseTypeRow;
62
64typedef vector<BaseTypeRow *> SequenceValues;
65
161
162class Sequence : public Constructor {
163private:
164 // This holds the values read off the wire. Values are stored in
165 // instances of BaseTypeRow objects which hold instances of BaseType.
166 SequenceValues d_values;
167
168 // The number of the row that has just been deserialized. Before
169 // deserialized has been called, this field is -1.
170 int d_row_number;
171
172 // If a client asks for certain rows of a sequence using the bracket
173 // notation (<tt>[<start>:<stride>:<stop>]</tt>) primarily intended for
174 // arrays
175 // and grids, record that information in the next three fields. This
176 // information can be used by the translation software. s.a. the accessor
177 // and mutator methods for these members. Values of -1 indicate that
178 // these have not yet been set.
179 int d_starting_row_number;
180 int d_row_stride;
181 int d_ending_row_number;
182
183 // Used to track if data has not already been sent.
184 bool d_unsent_data;
185
186 // Track if the Start Of Instance marker has been written. Needed to
187 // properly send EOS for only the outer Sequence when a selection
188 // returns an empty Sequence.
189 bool d_wrote_soi;
190
191 // This signals whether the sequence is a leaf or parent.
192 bool d_leaf_sequence;
193
194 // In a hierarchy of sequences, is this the top most?
195 bool d_top_most;
196
197 bool is_end_of_rows(int i);
198
199 friend class SequenceTest;
200
201protected:
202 void m_duplicate(const Sequence &s);
203 typedef stack<SequenceValues *> sequence_values_stack_t;
204
205 virtual bool serialize_parent_part_one(DDS &dds, ConstraintEvaluator &eval, Marshaller &m);
206 virtual void serialize_parent_part_two(DDS &dds, ConstraintEvaluator &eval, Marshaller &m);
207 virtual bool serialize_leaf(DDS &dds, ConstraintEvaluator &eval, Marshaller &m, bool ce_eval);
208
209 virtual void intern_data_private(ConstraintEvaluator &eval, DDS &dds,
210 sequence_values_stack_t &sequence_values_stack);
211 virtual void intern_data_for_leaf(DDS &dds, ConstraintEvaluator &eval,
212 sequence_values_stack_t &sequence_values_stack);
213
214 virtual void intern_data_parent_part_one(DDS &dds, ConstraintEvaluator &eval,
215 sequence_values_stack_t &sequence_values_stack);
216
217 virtual void intern_data_parent_part_two(DDS &dds, ConstraintEvaluator &eval,
218 sequence_values_stack_t &sequence_values_stack);
219
220public:
221 Sequence(const string &n);
222 Sequence(const string &n, const string &d);
223
224 Sequence(const Sequence &rhs);
225
226 virtual ~Sequence();
227
228 Sequence &operator=(const Sequence &rhs);
229
230 virtual BaseType *ptr_duplicate();
231
232 virtual void clear_local_data();
233
234 virtual void transform_to_dap4(D4Group *root, Constructor *container);
235
236 virtual bool is_dap2_only_type();
237
238 virtual string toString();
239
240 virtual bool is_linear();
241
242 virtual int length() const;
243
244 virtual int number_of_rows() const;
245
246 virtual bool read_row(int row, DDS &dds, ConstraintEvaluator &eval, bool ce_eval = true);
247
248 virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
249 virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
250 virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
251
253 void reset_row_number();
254 // I added a second method instead of a param with a default value because I think
255 // this will result only in an addition to the ABI/API, not a change. 5/16/15 jhrg
256 void reset_row_number(bool recur);
257 void increment_row_number(unsigned int i) { d_row_number += i; }
258 int get_row_number() const { return d_row_number; }
259
261
262 virtual int get_row_stride();
263
264 virtual int get_ending_row_number();
265
266 virtual void set_row_number_constraint(int start, int stop, int stride = 1);
267
269 bool get_unsent_data() const { return d_unsent_data; }
270
272 void set_unsent_data(bool usd) { d_unsent_data = usd; }
273
274 virtual void set_value(SequenceValues &values);
275 virtual SequenceValues value();
276 virtual SequenceValues &value_ref();
277
278 virtual BaseType *var_value(size_t row, const string &name);
279
280 virtual BaseType *var_value(size_t row, size_t i);
281
282 virtual BaseTypeRow *row_value(size_t row);
283 virtual void print_one_row(ostream &out, int row, string space, bool print_row_num = false);
284 virtual void print_val_by_rows(ostream &out, string space = "", bool print_decl_p = true,
285 bool print_row_numbers = true);
286 virtual void print_val(ostream &out, string space = "", bool print_decl_p = true);
287
288 virtual void print_one_row(FILE *out, int row, string space, bool print_row_num = false);
289 virtual void print_val_by_rows(FILE *out, string space = "", bool print_decl_p = true,
290 bool print_row_numbers = true);
291 virtual void print_val(FILE *out, string space = "", bool print_decl_p = true);
292
293 virtual void set_leaf_p(bool state);
294
295 virtual bool is_leaf_sequence();
296
297 virtual void set_leaf_sequence(int lvl = 1);
298
299 virtual void dump(ostream &strm) const;
300};
301
302} // namespace libdap
303
304#endif //_sequence_h
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.
void intern_data() override
Read data into this variable.
Constructor(const string &name, const Type &type, bool is_dap4=false)
Definition Constructor.h:52
abstract base class used to marshal/serialize dap data objects
Definition Marshaller.h:50
void m_duplicate(const Sequence &s)
Definition Sequence.cc:88
void increment_row_number(unsigned int i)
Definition Sequence.h:257
virtual void transform_to_dap4(D4Group *root, Constructor *container)
Definition Sequence.cc:183
virtual bool serialize_leaf(DDS &dds, ConstraintEvaluator &eval, Marshaller &m, bool ce_eval)
Definition Sequence.cc:652
virtual SequenceValues value()
Definition Sequence.cc:299
virtual string toString()
Definition Sequence.cc:240
virtual void intern_data_for_leaf(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
Definition Sequence.cc:863
virtual bool serialize_parent_part_one(DDS &dds, ConstraintEvaluator &eval, Marshaller &m)
Definition Sequence.cc:561
virtual bool is_leaf_sequence()
Definition Sequence.cc:1122
int get_row_number() const
Definition Sequence.h:258
virtual void dump(ostream &strm) const
dumps information about this object
Definition Sequence.cc:1190
virtual bool read_row(int row, DDS &dds, ConstraintEvaluator &eval, bool ce_eval=true)
Definition Sequence.cc:436
virtual void set_leaf_sequence(int lvl=1)
Mark the Sequence which holds the leaf elements.
Definition Sequence.cc:1148
virtual void intern_data_parent_part_one(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
Definition Sequence.cc:761
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition Sequence.cc:1116
virtual void print_one_row(ostream &out, int row, string space, bool print_row_num=false)
Definition Sequence.cc:1043
stack< SequenceValues * > sequence_values_stack_t
Definition Sequence.h:203
virtual void serialize_parent_part_two(DDS &dds, ConstraintEvaluator &eval, Marshaller &m)
Definition Sequence.cc:624
friend class SequenceTest
Definition Sequence.h:199
virtual ~Sequence()
Definition Sequence.cc:210
Sequence & operator=(const Sequence &rhs)
Definition Sequence.cc:227
Sequence(const string &n)
The Sequence constructor.
Definition Sequence.cc:146
virtual SequenceValues & value_ref()
Definition Sequence.cc:303
virtual void set_value(SequenceValues &values)
Definition Sequence.cc:295
virtual BaseType * ptr_duplicate()
Definition Sequence.cc:167
virtual bool is_linear()
Check to see whether this variable can be printed simply.
Definition Sequence.cc:254
virtual BaseType * var_value(size_t row, const string &name)
Get the BaseType pointer to the named variable of a given row.
Definition Sequence.cc:310
virtual void set_leaf_p(bool state)
Definition Sequence.cc:1120
virtual void clear_local_data()
Definition Sequence.cc:218
virtual bool is_dap2_only_type()
Definition Sequence.cc:238
virtual void print_val_by_rows(ostream &out, string space="", bool print_decl_p=true, bool print_row_numbers=true)
Definition Sequence.cc:1090
virtual void intern_data_parent_part_two(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
Definition Sequence.cc:818
virtual void intern_data_private(ConstraintEvaluator &eval, DDS &dds, sequence_values_stack_t &sequence_values_stack)
Definition Sequence.cc:751
bool get_unsent_data() const
Get the unsent data property.
Definition Sequence.h:269
int get_starting_row_number()
Get the starting row number.
Definition Sequence.cc:993
void reset_row_number()
Rest the row number counter.
Definition Sequence.cc:368
void set_unsent_data(bool usd)
Set the unsent data property.
Definition Sequence.h:272
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Definition Sequence.cc:545
virtual int length() const
Definition Sequence.cc:360
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Deserialize (read from the network) the entire Sequence.
Definition Sequence.cc:937
virtual int get_row_stride()
Get the row stride.
Definition Sequence.cc:1005
virtual int get_ending_row_number()
Get the ending row number.
Definition Sequence.cc:1018
virtual BaseTypeRow * row_value(size_t row)
Get a whole row from the sequence.
Definition Sequence.cc:283
virtual void set_row_number_constraint(int start, int stop, int stride=1)
Definition Sequence.cc:1028
virtual int number_of_rows() const
Definition Sequence.cc:363
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< BaseTypeRow * > SequenceValues
Definition D4Sequence.h:52