libdap  Updated for version 3.20.6
libdap4 is an implementation of OPeNDAP's DAP protocol.
Sequence.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) 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 
53 namespace libdap {
54 
55 class BaseType;
56 class ConstraintEvaluator;
57 class D4Group;
58 
61 typedef vector<BaseType *> BaseTypeRow;
62 
64 typedef vector<BaseTypeRow *> SequenceValues;
65 
162 class Sequence: public Constructor
163 {
164 private:
165  // This holds the values read off the wire. Values are stored in
166  // instances of BaseTypeRow objects which hold instances of BaseType.
167  SequenceValues d_values;
168 
169  // The number of the row that has just been deserialized. Before
170  // deserialized has been called, this field is -1.
171  int d_row_number;
172 
173  // If a client asks for certain rows of a sequence using the bracket
174  // notation (<tt>[<start>:<stride>:<stop>]</tt>) primarily intended for
175  // arrays
176  // and grids, record that information in the next three fields. This
177  // information can be used by the translation software. s.a. the accessor
178  // and mutator methods for these members. Values of -1 indicate that
179  // these have not yet been set.
180  int d_starting_row_number;
181  int d_row_stride;
182  int d_ending_row_number;
183 
184  // Used to track if data has not already been sent.
185  bool d_unsent_data;
186 
187  // Track if the Start Of Instance marker has been written. Needed to
188  // properly send EOS for only the outer Sequence when a selection
189  // returns an empty Sequence.
190  bool d_wrote_soi;
191 
192  // This signals whether the sequence is a leaf or parent.
193  bool d_leaf_sequence;
194 
195  // In a hierarchy of sequences, is this the top most?
196  bool d_top_most;
197 
198  bool is_end_of_rows(int i);
199 
200  friend class SequenceTest;
201 
202 protected:
203  void m_duplicate(const Sequence &s);
204  typedef stack<SequenceValues*> sequence_values_stack_t;
205 
206  virtual bool serialize_parent_part_one(DDS &dds, ConstraintEvaluator &eval, Marshaller &m);
207  virtual void serialize_parent_part_two(DDS &dds, ConstraintEvaluator &eval, Marshaller &m);
208  virtual bool serialize_leaf(DDS &dds, ConstraintEvaluator &eval, Marshaller &m, bool ce_eval);
209 
210  virtual void intern_data_private(ConstraintEvaluator &eval, DDS &dds,
211  sequence_values_stack_t &sequence_values_stack);
212  virtual void intern_data_for_leaf(DDS &dds, ConstraintEvaluator &eval,
213  sequence_values_stack_t &sequence_values_stack);
214 
215  virtual void intern_data_parent_part_one(DDS &dds, ConstraintEvaluator &eval,
216  sequence_values_stack_t &sequence_values_stack);
217 
218  virtual void intern_data_parent_part_two(DDS &dds, ConstraintEvaluator &eval,
219  sequence_values_stack_t &sequence_values_stack);
220 
221 public:
222 
223  Sequence(const string &n);
224  Sequence(const string &n, const string &d);
225 
226  Sequence(const Sequence &rhs);
227 
228  virtual ~Sequence();
229 
230  Sequence &operator=(const Sequence &rhs);
231 
232  virtual BaseType *ptr_duplicate();
233 
234  virtual void clear_local_data();
235 
236  virtual void transform_to_dap4(D4Group *root, Constructor *container);
237 
238  virtual bool is_dap2_only_type();
239 
240  virtual string toString();
241 
242  virtual bool is_linear();
243 
244  virtual int length() const;
245 
246  virtual int number_of_rows() const;
247 
248  virtual bool read_row(int row, DDS &dds, ConstraintEvaluator &eval, bool ce_eval = true);
249 
250  virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
251  virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
252  virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
253 
255  void reset_row_number();
256  // I added a second method instead of a param with a default value because I think
257  // this will result only in an addition to the ABI/API, not a change. 5/16/15 jhrg
258  void reset_row_number(bool recur);
259  void increment_row_number(unsigned int i) { d_row_number += i; }
260  int get_row_number() const { return d_row_number; }
261 
263 
264  virtual int get_row_stride();
265 
266  virtual int get_ending_row_number();
267 
268  virtual void set_row_number_constraint(int start, int stop, int stride = 1);
269 
271  bool get_unsent_data() const
272  {
273  return d_unsent_data;
274  }
275 
277  void set_unsent_data(bool usd)
278  {
279  d_unsent_data = usd;
280  }
281 
282  virtual void set_value(SequenceValues &values);
283  virtual SequenceValues value();
284  virtual SequenceValues &value_ref();
285 
286  virtual BaseType *var_value(size_t row, const string &name);
287 
288  virtual BaseType *var_value(size_t row, size_t i);
289 
290  virtual BaseTypeRow *row_value(size_t row);
291  virtual void print_one_row(ostream &out, int row, string space, bool print_row_num = false);
292  virtual void print_val_by_rows(ostream &out, string space = "", bool print_decl_p = true, bool print_row_numbers =
293  true);
294  virtual void print_val(ostream &out, string space = "", bool print_decl_p = true);
295 
296  virtual void print_one_row(FILE *out, int row, string space, bool print_row_num = false);
297  virtual void print_val_by_rows(FILE *out, string space = "", bool print_decl_p = true,
298  bool print_row_numbers = true);
299  virtual void print_val(FILE *out, string space = "", bool print_decl_p = true);
300 
301  virtual void set_leaf_p(bool state);
302 
303  virtual bool is_leaf_sequence();
304 
305  virtual void set_leaf_sequence(int lvl = 1);
306 
307  virtual void dump(ostream &strm) const;
308 };
309 
310 } // namespace libdap
311 
312 #endif //_sequence_h
virtual void clear_local_data()
Definition: Sequence.cc:247
virtual string name() const
Returns the name of the class instance.
Definition: BaseType.cc:320
abstract base class used to unmarshall/deserialize dap data objects
Definition: UnMarshaller.h:54
bool get_unsent_data() const
Get the unsent data property.
Definition: Sequence.h:271
void set_unsent_data(bool usd)
Set the unsent data property.
Definition: Sequence.h:277
virtual bool read_row(int row, DDS &dds, ConstraintEvaluator &eval, bool ce_eval=true)
Definition: Sequence.cc:499
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Deserialize (read from the network) the entire Sequence.
Definition: Sequence.cc:1003
virtual bool is_dap2_only_type()
Definition: Sequence.cc:272
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Definition: Sequence.cc:607
virtual BaseTypeRow * row_value(size_t row)
Get a whole row from the sequence.
Definition: Sequence.cc:325
vector< BaseTypeRow * > SequenceValues
Definition: D4Sequence.h:53
virtual void set_row_number_constraint(int start, int stop, int stride=1)
Definition: Sequence.cc:1106
top level DAP object to house generic methods
Definition: AISConnect.cc:30
virtual bool is_linear()
Check to see whether this variable can be printed simply.
Definition: Sequence.cc:292
Sequence(const string &n)
The Sequence constructor.
Definition: Sequence.cc:161
virtual void set_leaf_sequence(int lvl=1)
Mark the Sequence which holds the leaf elements.
Definition: Sequence.cc:1236
Holds a sequence.
Definition: Sequence.h:162
virtual string toString()
Definition: Sequence.cc:277
int get_starting_row_number()
Get the starting row number.
Definition: Sequence.cc:1062
Evaluate a constraint expression.
virtual SequenceValues & value_ref()
Definition: Sequence.cc:352
virtual SequenceValues value()
Definition: Sequence.cc:344
void reset_row_number()
Rest the row number counter.
Definition: Sequence.cc:427
virtual int length() const
Definition: Sequence.cc:413
The basic data type for the DODS DAP types.
Definition: BaseType.h:117
abstract base class used to marshal/serialize dap data objects
Definition: Marshaller.h:50
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:363
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition: Sequence.cc:1197
virtual void intern_data()
Read data into this variable.
Definition: Constructor.cc:556
virtual void dump(ostream &strm) const
dumps information about this object
Definition: Sequence.cc:1278
virtual void transform_to_dap4(D4Group *root, Constructor *container)
Definition: Sequence.cc:212
virtual int get_ending_row_number()
Get the ending row number.
Definition: Sequence.cc:1093
virtual BaseType * ptr_duplicate()
Definition: Sequence.cc:192
virtual int get_row_stride()
Get the row stride.
Definition: Sequence.cc:1077
virtual void set_value(SequenceValues &values)
Definition: Sequence.cc:337
vector< BaseType * > BaseTypeRow
Definition: D4Sequence.h:50