libdap++  Updated for version 3.13.1
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 
46 #include <stack>
47 
48 #ifndef _basetype_h
49 #include "BaseType.h"
50 #endif
51 
52 #ifndef _constructor_h
53 #include "Constructor.h"
54 #endif
55 
56 #ifndef constraint_evaluator_h
57 #include "ConstraintEvaluator.h"
58 #endif
59 
60 #ifndef S_XDRUtils_h
61 #include "XDRUtils.h"
62 #endif
63 
64 namespace libdap
65 {
66 
69 typedef vector<BaseType *> BaseTypeRow;
70 
72 typedef vector<BaseTypeRow *> SequenceValues;
73 
172 class Sequence: public Constructor
173 {
174 private:
175  // This holds the values read off the wire. Values are stored in
176  // instances of BaseTypeRow objects which hold instances of BaseType.
177  SequenceValues d_values;
178 
179  // The number of the row that has just been deserialized. Before
180  // deserialized has been called, this field is -1.
181  int d_row_number;
182 
183  // If a client asks for certain rows of a sequence using the bracket
184  // notation (<tt>[<start>:<stride>:<stop>]</tt>) primarily intended for
185  // arrays
186  // and grids, record that information in the next three fields. This
187  // information can be used by the translation software. s.a. the accessor
188  // and mutator methods for these members. Values of -1 indicate that
189  // these have not yet been set.
190  int d_starting_row_number;
191  int d_row_stride;
192  int d_ending_row_number;
193 
194  // Used to track if data has not already been sent.
195  bool d_unsent_data;
196 
197  // Track if the Start Of Instance marker has been written. Needed to
198  // properly send EOS for only the outer Sequence when a selection
199  // returns an empty Sequence.
200  bool d_wrote_soi;
201 
202  // This signals whether the sequence is a leaf or parent.
203  bool d_leaf_sequence;
204 
205  // In a hierarchy of sequences, is this the top most?
206  bool d_top_most;
207 #if 0
208  BaseType *m_leaf_match(const string &name, btp_stack *s = 0);
209  BaseType *m_exact_match(const string &name, btp_stack *s = 0);
210 #endif
211  bool is_end_of_rows(int i);
212 
213  friend class SequenceTest;
214 
215 protected:
216  void m_duplicate(const Sequence &s);
217  typedef stack<SequenceValues*> sequence_values_stack_t;
218 
219  virtual bool serialize_parent_part_one(DDS &dds,
220  ConstraintEvaluator &eval,
221  Marshaller &m);
222  virtual void serialize_parent_part_two(DDS &dds,
223  ConstraintEvaluator &eval,
224  Marshaller &m);
225  virtual bool serialize_leaf(DDS &dds,
226  ConstraintEvaluator &eval,
227  Marshaller &m, bool ce_eval);
228 
229  virtual void intern_data_private( ConstraintEvaluator &eval,
230  DDS &dds,
231  sequence_values_stack_t &sequence_values_stack);
232  virtual void intern_data_for_leaf(DDS &dds,
233  ConstraintEvaluator &eval,
234  sequence_values_stack_t &sequence_values_stack);
235 
236  virtual void intern_data_parent_part_one(DDS &dds,
237  ConstraintEvaluator &eval,
238  sequence_values_stack_t &sequence_values_stack);
239 
240  virtual void intern_data_parent_part_two(DDS &dds,
241  ConstraintEvaluator &eval,
242  sequence_values_stack_t &sequence_values_stack);
243 
244 public:
245 
246  Sequence(const string &n);
247  Sequence(const string &n, const string &d);
248 
249  Sequence(const Sequence &rhs);
250 
251  virtual ~Sequence();
252 
253  Sequence &operator=(const Sequence &rhs);
254 
255  virtual BaseType *ptr_duplicate();
256 
257  virtual bool is_dap2_only_type();
258 
259  virtual string toString();
260 #if 0
261  virtual int element_count(bool leaves = false);
262 #endif
263  virtual bool is_linear();
264 #if 0
265  virtual void set_send_p(bool state);
266  virtual void set_read_p(bool state);
267 #endif
268 #if 0
269  virtual void set_in_selection(bool state);
270 #endif
271 #if 0
272  virtual unsigned int width(bool constrained = false);
273  virtual unsigned int width(bool constrained);
274 #endif
275 
276  virtual int length();
277 
278  virtual int number_of_rows();
279 
280  virtual bool read_row(int row, DDS &dds,
281  ConstraintEvaluator &eval, bool ce_eval = true);
282 
283  virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
284  virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
285  virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
286 
288  void reset_row_number();
289 
291 
292  virtual int get_row_stride();
293 
294  virtual int get_ending_row_number();
295 
296  virtual void set_row_number_constraint(int start, int stop, int stride = 1);
297 
300  {
301  return d_unsent_data;
302  }
303 
305  void set_unsent_data(bool usd)
306  {
307  d_unsent_data = usd;
308  }
309 
310 #if 0
311  // Move me!
312  virtual unsigned int val2buf(void *val, bool reuse = false);
313  virtual unsigned int buf2val(void **val);
314 #endif
315 
316  virtual void set_value(SequenceValues &values);
317  virtual SequenceValues value();
318 #if 0
319  virtual BaseType *var(const string &name, bool exact_match = true,btp_stack *s = 0);
320  virtual BaseType *var(const string &n, btp_stack &s);
321 #endif
322 
323  virtual BaseType *var_value(size_t row, const string &name);
324 
325  virtual BaseType *var_value(size_t row, size_t i);
326 
327  virtual BaseTypeRow *row_value(size_t row);
328 #if 0
329  virtual void add_var(BaseType *, Part part = nil);
330  virtual void add_var_nocopy(BaseType *, Part part = nil);
331 #endif
332  virtual void print_one_row(ostream &out, int row, string space,
333  bool print_row_num = false);
334  virtual void print_val_by_rows(ostream &out, string space = "",
335  bool print_decl_p = true,
336  bool print_row_numbers = true);
337  virtual void print_val(ostream &out, string space = "",
338  bool print_decl_p = true);
339 
340  virtual void print_one_row(FILE *out, int row, string space,
341  bool print_row_num = false);
342  virtual void print_val_by_rows(FILE *out, string space = "",
343  bool print_decl_p = true,
344  bool print_row_numbers = true);
345  virtual void print_val(FILE *out, string space = "",
346  bool print_decl_p = true);
347 #if 0
348  virtual bool check_semantics(string &msg, bool all = false);
349 #endif
350  virtual void set_leaf_p(bool state);
351 
352  virtual bool is_leaf_sequence();
353 
354  virtual void set_leaf_sequence(int lvl = 1);
355 
356  virtual void dump(ostream &strm) const ;
357 };
358 
359 } // namespace libdap
360 
361 #endif //_sequence_h
virtual void intern_data(ConstraintEvaluator &eval, DDS &dds)
Definition: Sequence.cc:995
virtual void set_in_selection(bool state)
Set the in_selection property.
Definition: Constructor.cc:625
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:1562
virtual BaseType * var(const string &name, bool exact_match=true, btp_stack *s=0)
btp_stack no longer needed; use back pointers (BaseType::get_parent())
Definition: Constructor.cc:183
Part
Names the parts of multi-section constructor data types.
Definition: BaseType.h:95
void set_unsent_data(bool usd)
Set the unsent data property.
Definition: Sequence.h:305
virtual bool read_row(int row, DDS &dds, ConstraintEvaluator &eval, bool ce_eval=true)
Definition: Sequence.cc:678
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Deserialize (read from the network) the entire Sequence.
Definition: Sequence.cc:1222
virtual bool is_dap2_only_type()
Definition: Sequence.cc:248
vector< BaseTypeRow * > SequenceValues
Definition: Sequence.h:72
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Definition: Sequence.cc:793
virtual bool serialize_leaf(DDS &dds, ConstraintEvaluator &eval, Marshaller &m, bool ce_eval)
Definition: Sequence.cc:908
virtual void add_var_nocopy(BaseType *bt, Part part=nil)
Definition: Constructor.cc:346
virtual BaseTypeRow * row_value(size_t row)
Get a whole row from the sequence.
Definition: Sequence.cc:479
virtual ~Sequence()
Definition: Sequence.cc:219
virtual void set_row_number_constraint(int start, int stop, int stride=1)
Definition: Sequence.cc:1328
virtual void add_var(BaseType *bt, Part part=nil)
Definition: Constructor.cc:321
virtual int element_count(bool leaves=false)
Count the members of constructor types.
Definition: Constructor.cc:110
virtual void print_val_by_rows(ostream &out, string space="", bool print_decl_p=true, bool print_row_numbers=true)
Definition: Sequence.cc:1425
stack< BaseType * > btp_stack
Definition: BaseType.h:233
virtual void intern_data_private(ConstraintEvaluator &eval, DDS &dds, sequence_values_stack_t &sequence_values_stack)
Definition: Sequence.cc:1013
virtual bool is_linear()
Check to see whether this variable can be printed simply.
Definition: Sequence.cc:286
virtual void intern_data_for_leaf(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
Definition: Sequence.cc:1143
bool get_unsent_data()
Get the unsent data property.
Definition: Sequence.h:299
Sequence(const string &n)
The Sequence constructor.
Definition: Sequence.cc:165
virtual void set_leaf_sequence(int lvl=1)
Mark the Sequence which holds the leaf elements.
Definition: Sequence.cc:1519
Sequence & operator=(const Sequence &rhs)
Definition: Sequence.cc:232
Holds a sequence.
Definition: Sequence.h:172
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
Definition: Constructor.cc:583
virtual int length()
Definition: Sequence.cc:605
virtual unsigned int val2buf(void *, bool)
Loads class data.
Definition: Constructor.h:99
vector< BaseType * > BaseTypeRow
Definition: Sequence.h:69
virtual void serialize_parent_part_two(DDS &dds, ConstraintEvaluator &eval, Marshaller &m)
Definition: Sequence.cc:876
virtual bool is_leaf_sequence()
Definition: Sequence.cc:1489
string name() const
Returns the name of the class instance.
Definition: BaseType.cc:254
virtual string toString()
Definition: Sequence.cc:254
BaseType * m_leaf_match(const string &name, btp_stack *s=0)
Definition: Constructor.cc:208
int get_starting_row_number()
Get the starting row number.
Definition: Sequence.cc:1281
virtual unsigned int width(bool constrained=false)
Definition: Constructor.cc:165
Evaluate a constraint expression.
virtual SequenceValues value()
Definition: Sequence.cc:501
friend class SequenceTest
Definition: Sequence.h:213
virtual int number_of_rows()
Definition: Sequence.cc:612
void reset_row_number()
Rest the row number counter.
Definition: Sequence.cc:621
virtual unsigned int buf2val(void **)
Reads the class data.
Definition: Constructor.h:102
virtual void intern_data_parent_part_two(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
Definition: Sequence.cc:1091
The basic data type for the DODS DAP types.
Definition: BaseType.h:199
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:512
virtual void print_one_row(ostream &out, int row, string space, bool print_row_num=false)
Definition: Sequence.cc:1370
virtual void intern_data_parent_part_one(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
Definition: Sequence.cc:1026
BaseType * m_exact_match(const string &name, btp_stack *s=0)
Definition: Constructor.cc:235
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition: Sequence.cc:1456
virtual bool serialize_parent_part_one(DDS &dds, ConstraintEvaluator &eval, Marshaller &m)
Definition: Sequence.cc:810
virtual void set_leaf_p(bool state)
Definition: Sequence.cc:1483
stack< SequenceValues * > sequence_values_stack_t
Definition: Sequence.h:217
void m_duplicate(const Sequence &s)
Definition: Sequence.cc:82
virtual int get_ending_row_number()
Get the ending row number.
Definition: Sequence.cc:1314
virtual void set_send_p(bool state)
Definition: Constructor.cc:124
virtual BaseType * ptr_duplicate()
Definition: Sequence.cc:197
virtual int get_row_stride()
Get the row stride.
Definition: Sequence.cc:1297
virtual void set_value(SequenceValues &values)
Definition: Sequence.cc:493
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Definition: Constructor.cc:134