libdap++ Updated for version 3.8.2

Sequence.h

Go to the documentation of this file.
00001 // -*- mode: c++; c-basic-offset:4 -*-
00002 
00003 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
00004 // Access Protocol.
00005 
00006 // Copyright (c) 2002,2003 OPeNDAP, Inc.
00007 // Author: James Gallagher <jgallagher@opendap.org>
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 //
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
00024 
00025 // (c) COPYRIGHT URI/MIT 1994-1999
00026 // Please read the full copyright statement in the file COPYRIGHT_URI.
00027 //
00028 // Authors:
00029 //      jhrg,jimg       James Gallagher <jgallagher@gso.uri.edu>
00030 
00031 // Interface for the class Sequence. A sequence contains a single set
00032 // of variables, all at the same lexical level just like a structure
00033 // (and like a structure, it may contain other ctor types...). Unlike
00034 // a structure, a sequence defines a pattern that is repeated N times
00035 // for a sequence of N elements. Thus, Sequence { String name; Int32
00036 // age; } person; means a sequence of N persons where each contain a
00037 // name and age. The sequence can be arbitrarily long (i.e., you don't
00038 // know N by looking at the sequence declaration.
00039 //
00040 // jhrg 9/14/94
00041 
00042 #ifndef _sequence_h
00043 #define _sequence_h 1
00044 
00045 
00046 #include <stack>
00047 
00048 #ifndef _basetype_h
00049 #include "BaseType.h"
00050 #endif
00051 
00052 #ifndef _constructor_h
00053 #include "Constructor.h"
00054 #endif
00055 
00056 #ifndef constraint_evaluator_h
00057 #include "ConstraintEvaluator.h"
00058 #endif
00059 
00060 // FIXME
00061 #include "XDRUtils.h"
00062 
00063 #define FILE_METHODS 1
00064 
00065 namespace libdap
00066 {
00067 
00070 typedef vector<BaseType *> BaseTypeRow;
00071 
00073 typedef vector<BaseTypeRow *> SequenceValues;
00074 
00173 class Sequence: public Constructor
00174 {
00175 private:
00176     // This holds the values read off the wire. Values are stored in
00177     // instances of BaseTypeRow objects which hold instances of BaseType.
00178     SequenceValues d_values;
00179 
00180     // The number of the row that has just been deserialized. Before
00181     // deserialized has been called, this field is -1.
00182     int d_row_number;
00183 
00184     // If a client asks for certain rows of a sequence using the bracket
00185     // notation (<tt>[<start>:<stride>:<stop>]</tt>) primarily intended for
00186     // arrays
00187     // and grids, record that information in the next three fields. This
00188     // information can be used by the translation software. s.a. the accessor
00189     // and mutator methods for these members. Values of -1 indicate that
00190     // these have not yet been set.
00191     int d_starting_row_number;
00192     int d_row_stride;
00193     int d_ending_row_number;
00194 
00195     // Used to track if data has not already been sent.
00196     bool d_unsent_data;
00197 
00198     // Track if the Start Of Instance marker has been written. Needed to
00199     // properly send EOS for only the outer Sequence when a selection
00200     // returns an empty Sequence.
00201     bool d_wrote_soi;
00202 
00203     // This signals whether the sequence is a leaf or parent.
00204     bool d_leaf_sequence;
00205 
00206     // In a hierarchy of sequences, is this the top most?
00207     bool d_top_most;
00208 
00209     void _duplicate(const Sequence &s);
00210     BaseType *m_leaf_match(const string &name, btp_stack *s = 0);
00211     BaseType *m_exact_match(const string &name, btp_stack *s = 0);
00212 
00213     bool is_end_of_rows(int i);
00214 
00215     friend class SequenceTest;
00216 
00217 protected:
00218 
00219     typedef stack<SequenceValues*> sequence_values_stack_t;
00220 
00221     virtual bool serialize_parent_part_one(DDS &dds,
00222                                            ConstraintEvaluator &eval,
00223                                            Marshaller &m);
00224     virtual void serialize_parent_part_two(DDS &dds,
00225                                            ConstraintEvaluator &eval,
00226                                            Marshaller &m);
00227     virtual bool serialize_leaf(DDS &dds,
00228                                 ConstraintEvaluator &eval,
00229                                 Marshaller &m, bool ce_eval);
00230 
00231     virtual void intern_data_private( ConstraintEvaluator &eval,
00232                                       DDS &dds,
00233                                       sequence_values_stack_t &sequence_values_stack);
00234     virtual void intern_data_for_leaf(DDS &dds,
00235                                       ConstraintEvaluator &eval,
00236                                       sequence_values_stack_t &sequence_values_stack);
00237 
00238     virtual void intern_data_parent_part_one(DDS &dds,
00239             ConstraintEvaluator &eval,
00240             sequence_values_stack_t &sequence_values_stack);
00241 
00242     virtual void intern_data_parent_part_two(DDS &dds,
00243             ConstraintEvaluator &eval,
00244             sequence_values_stack_t &sequence_values_stack);
00245 
00246 public:
00247 
00248     Sequence(const string &n);
00249     Sequence(const string &n, const string &d);
00250 
00251     Sequence(const Sequence &rhs);
00252 
00253     virtual ~Sequence();
00254 
00255     Sequence &operator=(const Sequence &rhs);
00256 
00257     virtual BaseType *ptr_duplicate();
00258 
00259     virtual string toString();
00260 
00261     virtual int element_count(bool leaves = false);
00262 
00263     virtual bool is_linear();
00264 
00265     virtual void set_send_p(bool state);
00266     virtual void set_read_p(bool state);
00267     virtual void set_in_selection(bool state);
00268 
00269     virtual unsigned int width();
00270 
00271     virtual int length();
00272 
00273     virtual int number_of_rows();
00274 
00275     virtual bool read_row(int row, DDS &dds,
00276                           ConstraintEvaluator &eval, bool ce_eval = true);
00277 
00278     virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
00279     virtual bool serialize(ConstraintEvaluator &eval, DDS &dds,
00280                            Marshaller &m, bool ce_eval = true);
00281     virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
00282 
00284     void reset_row_number();
00285 
00286     int get_starting_row_number();
00287 
00288     virtual int get_row_stride();
00289 
00290     virtual int get_ending_row_number();
00291 
00292     virtual void set_row_number_constraint(int start, int stop, int stride = 1);
00293 
00295     bool get_unsent_data()
00296     {
00297         return d_unsent_data;
00298     }
00299 
00301     void set_unsent_data(bool usd)
00302     {
00303         d_unsent_data = usd;
00304     }
00305 
00306     // Move me!
00307     virtual unsigned int val2buf(void *val, bool reuse = false);
00308     virtual unsigned int buf2val(void **val);
00309 
00310     virtual void set_value(SequenceValues &values);
00311     virtual SequenceValues value();
00312 
00313     virtual BaseType *var(const string &name, bool exact_match = true,
00314                           btp_stack *s = 0);
00315     virtual BaseType *var(const string &n, btp_stack &s);
00316 
00317     virtual BaseType *var_value(size_t row, const string &name);
00318 
00319     virtual BaseType *var_value(size_t row, size_t i);
00320 
00321     virtual BaseTypeRow *row_value(size_t row);
00322 
00323     virtual void add_var(BaseType *, Part part = nil);
00324     virtual void print_one_row(ostream &out, int row, string space,
00325                                bool print_row_num = false);
00326     virtual void print_val_by_rows(ostream &out, string space = "",
00327                                    bool print_decl_p = true,
00328                                    bool print_row_numbers = true);
00329     virtual void print_val(ostream &out, string space = "",
00330                            bool print_decl_p = true);
00331 
00332 #if FILE_METHODS
00333     virtual void print_one_row(FILE *out, int row, string space,
00334                                bool print_row_num = false);
00335     virtual void print_val_by_rows(FILE *out, string space = "",
00336                                    bool print_decl_p = true,
00337                                    bool print_row_numbers = true);
00338     virtual void print_val(FILE *out, string space = "",
00339                            bool print_decl_p = true);
00340 #endif
00341 
00342     virtual bool check_semantics(string &msg, bool all = false);
00343 
00344     virtual void set_leaf_p(bool state);
00345 
00346     virtual bool is_leaf_sequence();
00347 
00348     virtual void set_leaf_sequence(int lvl = 1);
00349 
00350     virtual void dump(ostream &strm) const ;
00351 };
00352 
00353 } // namespace libdap
00354 
00355 #endif //_sequence_h