libdap  Updated for version 3.17.2
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 #if 0
221  // See note in Sequence.cc
222  virtual void load_prototypes_with_values(int d_row_number);
223 #endif
224 
225 public:
226 
227  Sequence(const string &n);
228  Sequence(const string &n, const string &d);
229 
230  Sequence(const Sequence &rhs);
231 
232  virtual ~Sequence();
233 
234  Sequence &operator=(const Sequence &rhs);
235 
236  virtual BaseType *ptr_duplicate();
237 
238  virtual void clear_local_data();
239 
240  virtual BaseType *transform_to_dap4(D4Group *root, Constructor *container);
241 
242  virtual bool is_dap2_only_type();
243 
244  virtual string toString();
245 
246  virtual bool is_linear();
247 
248  virtual int length() const;
249 
250  virtual int number_of_rows() const;
251 
252  virtual bool read_row(int row, DDS &dds, ConstraintEvaluator &eval, bool ce_eval = true);
253 
254  virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
255  virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
256 #if 0
257  virtual bool serialize_no_release(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
258 #endif
259  virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
260 
262  void reset_row_number();
263 
265 
266  virtual int get_row_stride();
267 
268  virtual int get_ending_row_number();
269 
270  virtual void set_row_number_constraint(int start, int stop, int stride = 1);
271 
274  {
275  return d_unsent_data;
276  }
277 
279  void set_unsent_data(bool usd)
280  {
281  d_unsent_data = usd;
282  }
283 
284  virtual void set_value(SequenceValues &values);
285  virtual SequenceValues value();
286  virtual SequenceValues &value_ref();
287 
288  virtual BaseType *var_value(size_t row, const string &name);
289 
290  virtual BaseType *var_value(size_t row, size_t i);
291 
292  virtual BaseTypeRow *row_value(size_t row);
293  virtual void print_one_row(ostream &out, int row, string space, bool print_row_num = false);
294  virtual void print_val_by_rows(ostream &out, string space = "", bool print_decl_p = true, bool print_row_numbers =
295  true);
296  virtual void print_val(ostream &out, string space = "", bool print_decl_p = true);
297 
298  virtual void print_one_row(FILE *out, int row, string space, bool print_row_num = false);
299  virtual void print_val_by_rows(FILE *out, string space = "", bool print_decl_p = true,
300  bool print_row_numbers = true);
301  virtual void print_val(FILE *out, string space = "", bool print_decl_p = true);
302 
303  virtual void set_leaf_p(bool state);
304 
305  virtual bool is_leaf_sequence();
306 
307  virtual void set_leaf_sequence(int lvl = 1);
308 
309  virtual void dump(ostream &strm) const;
310 };
311 
312 } // namespace libdap
313 
314 #endif //_sequence_h
virtual void clear_local_data()
Definition: Sequence.cc:242
abstract base class used to unmarshall/deserialize dap data objects
Definition: UnMarshaller.h:54
virtual void dump(ostream &strm) const
dumps information about this object
Definition: Sequence.cc:1347
void set_unsent_data(bool usd)
Set the unsent data property.
Definition: Sequence.h:279
virtual bool read_row(int row, DDS &dds, ConstraintEvaluator &eval, bool ce_eval=true)
Definition: Sequence.cc:552
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Deserialize (read from the network) the entire Sequence.
Definition: Sequence.cc:1074
virtual bool is_dap2_only_type()
Definition: Sequence.cc:267
vector< BaseTypeRow * > SequenceValues
Definition: Sequence.h:64
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Definition: Sequence.cc:676
virtual BaseTypeRow * row_value(size_t row)
Get a whole row from the sequence.
Definition: Sequence.cc:320
virtual void set_row_number_constraint(int start, int stop, int stride=1)
Definition: Sequence.cc:1175
virtual bool is_linear()
Check to see whether this variable can be printed simply.
Definition: Sequence.cc:287
virtual int length() const
Definition: Sequence.cc:408
bool get_unsent_data()
Get the unsent data property.
Definition: Sequence.h:273
Sequence(const string &n)
The Sequence constructor.
Definition: Sequence.cc:160
virtual void set_leaf_sequence(int lvl=1)
Mark the Sequence which holds the leaf elements.
Definition: Sequence.cc:1305
Holds a sequence.
Definition: Sequence.h:162
vector< BaseType * > BaseTypeRow
Definition: Sequence.h:57
virtual string name() const
Returns the name of the class instance.
Definition: BaseType.cc:265
virtual string toString()
Definition: Sequence.cc:272
int get_starting_row_number()
Get the starting row number.
Definition: Sequence.cc:1131
Evaluate a constraint expression.
virtual SequenceValues & value_ref()
Definition: Sequence.cc:347
virtual SequenceValues value()
Definition: Sequence.cc:339
void reset_row_number()
Rest the row number counter.
Definition: Sequence.cc:422
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:358
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition: Sequence.cc:1266
virtual void intern_data()
Read data into this variable.
Definition: Constructor.cc:531
virtual BaseType * transform_to_dap4(D4Group *root, Constructor *container)
Definition: Sequence.cc:211
virtual int get_ending_row_number()
Get the ending row number.
Definition: Sequence.cc:1162
virtual BaseType * ptr_duplicate()
Definition: Sequence.cc:191
virtual int get_row_stride()
Get the row stride.
Definition: Sequence.cc:1146
virtual void set_value(SequenceValues &values)
Definition: Sequence.cc:332