libdap++  Updated for version 3.14.0
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 
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 private:
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 
201 protected:
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 #if 0
220  // See note in Sequence.cc
221  virtual void load_prototypes_with_values(int d_row_number);
222 #endif
223 
224 public:
225 
226  Sequence(const string &n);
227  Sequence(const string &n, const string &d);
228 
229  Sequence(const Sequence &rhs);
230 
231  virtual ~Sequence();
232 
233  Sequence &operator=(const Sequence &rhs);
234 
235  virtual BaseType *ptr_duplicate();
236 
237  virtual BaseType *transform_to_dap4(D4Group *root, Constructor *container);
238 
239  virtual bool is_dap2_only_type();
240 
241  virtual string toString();
242 
243  virtual bool is_linear();
244 
245  virtual int length() const;
246 
247  virtual int number_of_rows() const;
248 
249  virtual bool read_row(int row, DDS &dds, ConstraintEvaluator &eval, bool ce_eval = true);
250 
251  virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
252  virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
253  virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
254 
256  void reset_row_number();
257 
259 
260  virtual int get_row_stride();
261 
262  virtual int get_ending_row_number();
263 
264  virtual void set_row_number_constraint(int start, int stop, int stride = 1);
265 
268  {
269  return d_unsent_data;
270  }
271 
273  void set_unsent_data(bool usd)
274  {
275  d_unsent_data = usd;
276  }
277 
278  virtual void set_value(SequenceValues &values);
279  virtual SequenceValues value();
280  virtual SequenceValues &value_ref();
281 
282  virtual BaseType *var_value(size_t row, const string &name);
283 
284  virtual BaseType *var_value(size_t row, size_t i);
285 
286  virtual BaseTypeRow *row_value(size_t row);
287  virtual void print_one_row(ostream &out, int row, string space, bool print_row_num = false);
288  virtual void print_val_by_rows(ostream &out, string space = "", bool print_decl_p = true, bool print_row_numbers =
289  true);
290  virtual void print_val(ostream &out, string space = "", bool print_decl_p = true);
291 
292  virtual void print_one_row(FILE *out, int row, string space, bool print_row_num = false);
293  virtual void print_val_by_rows(FILE *out, string space = "", bool print_decl_p = true,
294  bool print_row_numbers = true);
295  virtual void print_val(FILE *out, string space = "", bool print_decl_p = true);
296 
297  virtual void set_leaf_p(bool state);
298 
299  virtual bool is_leaf_sequence();
300 
301  virtual void set_leaf_sequence(int lvl = 1);
302 
303  virtual void dump(ostream &strm) const;
304 };
305 
306 } // namespace libdap
307 
308 #endif //_sequence_h
virtual void intern_data(ConstraintEvaluator &eval, DDS &dds)
Definition: Sequence.cc:851
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:1327
void set_unsent_data(bool usd)
Set the unsent data property.
Definition: Sequence.h:273
virtual bool read_row(int row, DDS &dds, ConstraintEvaluator &eval, bool ce_eval=true)
Definition: Sequence.cc:539
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Deserialize (read from the network) the entire Sequence.
Definition: Sequence.cc:1053
virtual bool is_dap2_only_type()
Definition: Sequence.cc:254
vector< BaseTypeRow * > SequenceValues
Definition: Sequence.h:64
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Definition: Sequence.cc:663
virtual bool serialize_leaf(DDS &dds, ConstraintEvaluator &eval, Marshaller &m, bool ce_eval)
Definition: Sequence.cc:770
virtual BaseTypeRow * row_value(size_t row)
Get a whole row from the sequence.
Definition: Sequence.cc:307
virtual ~Sequence()
Definition: Sequence.cc:234
virtual void set_row_number_constraint(int start, int stop, int stride=1)
Definition: Sequence.cc:1154
virtual void print_val_by_rows(ostream &out, string space="", bool print_decl_p=true, bool print_row_numbers=true)
Definition: Sequence.cc:1218
virtual void intern_data_private(ConstraintEvaluator &eval, DDS &dds, sequence_values_stack_t &sequence_values_stack)
Definition: Sequence.cc:867
virtual bool is_linear()
Check to see whether this variable can be printed simply.
Definition: Sequence.cc:274
virtual void intern_data_for_leaf(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
Definition: Sequence.cc:981
virtual int length() const
Definition: Sequence.cc:395
bool get_unsent_data()
Get the unsent data property.
Definition: Sequence.h:267
Sequence(const string &n)
The Sequence constructor.
Definition: Sequence.cc:158
virtual void set_leaf_sequence(int lvl=1)
Mark the Sequence which holds the leaf elements.
Definition: Sequence.cc:1284
Sequence & operator=(const Sequence &rhs)
Definition: Sequence.cc:240
Holds a sequence.
Definition: Sequence.h:162
vector< BaseType * > BaseTypeRow
Definition: Sequence.h:57
virtual void serialize_parent_part_two(DDS &dds, ConstraintEvaluator &eval, Marshaller &m)
Definition: Sequence.cc:741
virtual bool is_leaf_sequence()
Definition: Sequence.cc:1255
string name() const
Returns the name of the class instance.
Definition: BaseType.cc:261
virtual string toString()
Definition: Sequence.cc:259
int get_starting_row_number()
Get the starting row number.
Definition: Sequence.cc:1110
virtual int number_of_rows() const
Definition: Sequence.cc:401
Evaluate a constraint expression.
virtual SequenceValues & value_ref()
Definition: Sequence.cc:334
virtual SequenceValues value()
Definition: Sequence.cc:326
friend class SequenceTest
Definition: Sequence.h:199
void reset_row_number()
Rest the row number counter.
Definition: Sequence.cc:409
virtual void intern_data_parent_part_two(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
Definition: Sequence.cc:933
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:53
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:345
virtual void print_one_row(ostream &out, int row, string space, bool print_row_num=false)
Definition: Sequence.cc:1170
virtual void intern_data_parent_part_one(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
Definition: Sequence.cc:877
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition: Sequence.cc:1245
virtual bool serialize_parent_part_one(DDS &dds, ConstraintEvaluator &eval, Marshaller &m)
Definition: Sequence.cc:678
virtual void set_leaf_p(bool state)
Definition: Sequence.cc:1250
stack< SequenceValues * > sequence_values_stack_t
Definition: Sequence.h:203
void m_duplicate(const Sequence &s)
Definition: Sequence.cc:86
virtual BaseType * transform_to_dap4(D4Group *root, Constructor *container)
Definition: Sequence.cc:208
virtual int get_ending_row_number()
Get the ending row number.
Definition: Sequence.cc:1141
virtual BaseType * ptr_duplicate()
Definition: Sequence.cc:188
virtual int get_row_stride()
Get the row stride.
Definition: Sequence.cc:1125
virtual void set_value(SequenceValues &values)
Definition: Sequence.cc:319