libdap++  Updated for version 3.8.2
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 // FIXME
61 #include "XDRUtils.h"
62 
63 #define FILE_METHODS 1
64 
65 namespace libdap
66 {
67 
70 typedef vector<BaseType *> BaseTypeRow;
71 
73 typedef vector<BaseTypeRow *> SequenceValues;
74 
173 class Sequence: public Constructor
174 {
175 private:
176  // This holds the values read off the wire. Values are stored in
177  // instances of BaseTypeRow objects which hold instances of BaseType.
178  SequenceValues d_values;
179 
180  // The number of the row that has just been deserialized. Before
181  // deserialized has been called, this field is -1.
182  int d_row_number;
183 
184  // If a client asks for certain rows of a sequence using the bracket
185  // notation (<tt>[<start>:<stride>:<stop>]</tt>) primarily intended for
186  // arrays
187  // and grids, record that information in the next three fields. This
188  // information can be used by the translation software. s.a. the accessor
189  // and mutator methods for these members. Values of -1 indicate that
190  // these have not yet been set.
191  int d_starting_row_number;
192  int d_row_stride;
193  int d_ending_row_number;
194 
195  // Used to track if data has not already been sent.
196  bool d_unsent_data;
197 
198  // Track if the Start Of Instance marker has been written. Needed to
199  // properly send EOS for only the outer Sequence when a selection
200  // returns an empty Sequence.
201  bool d_wrote_soi;
202 
203  // This signals whether the sequence is a leaf or parent.
204  bool d_leaf_sequence;
205 
206  // In a hierarchy of sequences, is this the top most?
207  bool d_top_most;
208 
209  void _duplicate(const Sequence &s);
210  BaseType *m_leaf_match(const string &name, btp_stack *s = 0);
211  BaseType *m_exact_match(const string &name, btp_stack *s = 0);
212 
213  bool is_end_of_rows(int i);
214 
215  friend class SequenceTest;
216 
217 protected:
218 
219  typedef stack<SequenceValues*> sequence_values_stack_t;
220 
221  virtual bool serialize_parent_part_one(DDS &dds,
222  ConstraintEvaluator &eval,
223  Marshaller &m);
224  virtual void serialize_parent_part_two(DDS &dds,
225  ConstraintEvaluator &eval,
226  Marshaller &m);
227  virtual bool serialize_leaf(DDS &dds,
228  ConstraintEvaluator &eval,
229  Marshaller &m, bool ce_eval);
230 
231  virtual void intern_data_private( ConstraintEvaluator &eval,
232  DDS &dds,
233  sequence_values_stack_t &sequence_values_stack);
234  virtual void intern_data_for_leaf(DDS &dds,
235  ConstraintEvaluator &eval,
236  sequence_values_stack_t &sequence_values_stack);
237 
238  virtual void intern_data_parent_part_one(DDS &dds,
239  ConstraintEvaluator &eval,
240  sequence_values_stack_t &sequence_values_stack);
241 
242  virtual void intern_data_parent_part_two(DDS &dds,
243  ConstraintEvaluator &eval,
244  sequence_values_stack_t &sequence_values_stack);
245 
246 public:
247 
248  Sequence(const string &n);
249  Sequence(const string &n, const string &d);
250 
251  Sequence(const Sequence &rhs);
252 
253  virtual ~Sequence();
254 
255  Sequence &operator=(const Sequence &rhs);
256 
257  virtual BaseType *ptr_duplicate();
258 
259  virtual string toString();
260 
261  virtual int element_count(bool leaves = false);
262 
263  virtual bool is_linear();
264 
265  virtual void set_send_p(bool state);
266  virtual void set_read_p(bool state);
267  virtual void set_in_selection(bool state);
268 
269  virtual unsigned int width();
270 
271  virtual int length();
272 
273  virtual int number_of_rows();
274 
275  virtual bool read_row(int row, DDS &dds,
276  ConstraintEvaluator &eval, bool ce_eval = true);
277 
278  virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
279  virtual bool serialize(ConstraintEvaluator &eval, DDS &dds,
280  Marshaller &m, bool ce_eval = true);
281  virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
282 
284  void reset_row_number();
285 
287 
288  virtual int get_row_stride();
289 
290  virtual int get_ending_row_number();
291 
292  virtual void set_row_number_constraint(int start, int stop, int stride = 1);
293 
296  {
297  return d_unsent_data;
298  }
299 
301  void set_unsent_data(bool usd)
302  {
303  d_unsent_data = usd;
304  }
305 
306  // Move me!
307  virtual unsigned int val2buf(void *val, bool reuse = false);
308  virtual unsigned int buf2val(void **val);
309 
310  virtual void set_value(SequenceValues &values);
311  virtual SequenceValues value();
312 
313  virtual BaseType *var(const string &name, bool exact_match = true,
314  btp_stack *s = 0);
315  virtual BaseType *var(const string &n, btp_stack &s);
316 
317  virtual BaseType *var_value(size_t row, const string &name);
318 
319  virtual BaseType *var_value(size_t row, size_t i);
320 
321  virtual BaseTypeRow *row_value(size_t row);
322 
323  virtual void add_var(BaseType *, Part part = nil);
324  virtual void print_one_row(ostream &out, int row, string space,
325  bool print_row_num = false);
326  virtual void print_val_by_rows(ostream &out, string space = "",
327  bool print_decl_p = true,
328  bool print_row_numbers = true);
329  virtual void print_val(ostream &out, string space = "",
330  bool print_decl_p = true);
331 
332 #if FILE_METHODS
333  virtual void print_one_row(FILE *out, int row, string space,
334  bool print_row_num = false);
335  virtual void print_val_by_rows(FILE *out, string space = "",
336  bool print_decl_p = true,
337  bool print_row_numbers = true);
338  virtual void print_val(FILE *out, string space = "",
339  bool print_decl_p = true);
340 #endif
341 
342  virtual bool check_semantics(string &msg, bool all = false);
343 
344  virtual void set_leaf_p(bool state);
345 
346  virtual bool is_leaf_sequence();
347 
348  virtual void set_leaf_sequence(int lvl = 1);
349 
350  virtual void dump(ostream &strm) const ;
351 };
352 
353 } // namespace libdap
354 
355 #endif //_sequence_h
string name() const
Returns the name of the class instance.
Definition: BaseType.cc:210
virtual void intern_data(ConstraintEvaluator &eval, DDS &dds)
Definition: Sequence.cc:928
abstract base class used to unmarshall/deserialize dap data objects
Definition: UnMarshaller.h:54
Part
Names the parts of multi-section constructor data types.
Definition: BaseType.h:98
void set_unsent_data(bool usd)
Set the unsent data property.
Definition: Sequence.h:301
virtual bool read_row(int row, DDS &dds, ConstraintEvaluator &eval, bool ce_eval=true)
Definition: Sequence.cc:606
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Deserialize (read from the network) the entire Sequence.
Definition: Sequence.cc:1153
virtual int element_count(bool leaves=false)
Count the members of constructor types.
Definition: Sequence.cc:258
vector< BaseTypeRow * > SequenceValues
Definition: Sequence.h:73
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Definition: Sequence.cc:726
virtual bool serialize_leaf(DDS &dds, ConstraintEvaluator &eval, Marshaller &m, bool ce_eval)
Definition: Sequence.cc:841
virtual BaseTypeRow * row_value(size_t row)
Get a whole row from the sequence.
Definition: Sequence.cc:433
virtual ~Sequence()
Definition: Sequence.cc:216
virtual void set_row_number_constraint(int start, int stop, int stride=1)
Definition: Sequence.cc:1259
virtual void print_val_by_rows(ostream &out, string space="", bool print_decl_p=true, bool print_row_numbers=true)
Definition: Sequence.cc:1403
stack< BaseType * > btp_stack
Definition: BaseType.h:214
virtual void intern_data_private(ConstraintEvaluator &eval, DDS &dds, sequence_values_stack_t &sequence_values_stack)
Definition: Sequence.cc:946
virtual bool is_linear()
Check to see whether this variable can be printed simply.
Definition: Sequence.cc:272
virtual void intern_data_for_leaf(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
Definition: Sequence.cc:1074
bool get_unsent_data()
Get the unsent data property.
Definition: Sequence.h:295
Sequence(const string &n)
The Sequence constructor.
Definition: Sequence.cc:162
virtual void set_leaf_sequence(int lvl=1)
Mark the Sequence which holds the leaf elements.
Definition: Sequence.cc:1498
Sequence & operator=(const Sequence &rhs)
Definition: Sequence.cc:229
Holds a sequence.
Definition: Sequence.h:173
virtual unsigned int buf2val(void **val)
Definition: Sequence.cc:1283
virtual void set_in_selection(bool state)
Definition: Sequence.cc:321
virtual int length()
Definition: Sequence.cc:532
vector< BaseType * > BaseTypeRow
Definition: Sequence.h:70
virtual void serialize_parent_part_two(DDS &dds, ConstraintEvaluator &eval, Marshaller &m)
Definition: Sequence.cc:809
virtual bool is_leaf_sequence()
Definition: Sequence.cc:1468
virtual string toString()
Definition: Sequence.cc:242
int get_starting_row_number()
Get the starting row number.
Definition: Sequence.cc:1212
Evaluate a constraint expression.
virtual SequenceValues value()
Definition: Sequence.cc:455
friend class SequenceTest
Definition: Sequence.h:215
virtual int number_of_rows()
Definition: Sequence.cc:539
void reset_row_number()
Rest the row number counter.
Definition: Sequence.cc:548
virtual void intern_data_parent_part_two(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
Definition: Sequence.cc:1024
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Definition: Sequence.cc:311
virtual bool check_semantics(string &msg, bool all=false)
Compare an object&#39;s current state with the semantics of its type.
Definition: Sequence.cc:1443
The basic data type for the DODS DAP types.
Definition: BaseType.h:190
abstract base class used to marshal/serialize dap data objects
Definition: Marshaller.h:53
virtual unsigned int val2buf(void *val, bool reuse=false)
Definition: Sequence.cc:1272
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:466
virtual void print_one_row(ostream &out, int row, string space, bool print_row_num=false)
Definition: Sequence.cc:1330
virtual void add_var(BaseType *, Part part=nil)
Adds a variable to the Sequence.
Definition: Sequence.cc:340
virtual void intern_data_parent_part_one(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
Definition: Sequence.cc:959
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition: Sequence.cc:1436
virtual bool serialize_parent_part_one(DDS &dds, ConstraintEvaluator &eval, Marshaller &m)
Definition: Sequence.cc:743
virtual void set_leaf_p(bool state)
Definition: Sequence.cc:1462
virtual void dump(ostream &strm) const
dumps information about this object
Definition: Sequence.cc:1541
stack< SequenceValues * > sequence_values_stack_t
Definition: Sequence.h:219
virtual int get_ending_row_number()
Get the ending row number.
Definition: Sequence.cc:1245
virtual unsigned int width()
Returns the size of the class instance data.
Definition: Sequence.cc:502
virtual void set_send_p(bool state)
Definition: Sequence.cc:301
virtual BaseType * ptr_duplicate()
Definition: Sequence.cc:194
virtual int get_row_stride()
Get the row stride.
Definition: Sequence.cc:1228
virtual BaseType * var(const string &name, bool exact_match=true, btp_stack *s=0)
Returns a pointer to a member of a constructor class.
Definition: Sequence.cc:367
virtual void set_value(SequenceValues &values)
Definition: Sequence.cc:447