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 namespace libdap
00064 {
00065 
00068 typedef vector<BaseType *> BaseTypeRow;
00069 
00071 typedef vector<BaseTypeRow *> SequenceValues;
00072 
00171 class Sequence: public Constructor
00172 {
00173 private:
00174     // This holds the values read off the wire. Values are stored in
00175     // instances of BaseTypeRow objects which hold instances of BaseType.
00176     SequenceValues d_values;
00177 
00178     // The number of the row that has just been deserialized. Before
00179     // deserialized has been called, this field is -1.
00180     int d_row_number;
00181 
00182     // If a client asks for certain rows of a sequence using the bracket
00183     // notation (<tt>[<start>:<stride>:<stop>]</tt>) primarily intended for
00184     // arrays
00185     // and grids, record that information in the next three fields. This
00186     // information can be used by the translation software. s.a. the accessor
00187     // and mutator methods for these members. Values of -1 indicate that
00188     // these have not yet been set.
00189     int d_starting_row_number;
00190     int d_row_stride;
00191     int d_ending_row_number;
00192 
00193     // Used to track if data has not already been sent.
00194     bool d_unsent_data;
00195 
00196     // Track if the Start Of Instance marker has been written. Needed to
00197     // properly send EOS for only the outer Sequence when a selection
00198     // returns an empty Sequence.
00199     bool d_wrote_soi;
00200 
00201     // This signals whether the sequence is a leaf or parent.
00202     bool d_leaf_sequence;
00203 
00204     // In a hierarchy of sequences, is this the top most?
00205     bool d_top_most;
00206 
00207     void _duplicate(const Sequence &s);
00208     BaseType *m_leaf_match(const string &name, btp_stack *s = 0);
00209     BaseType *m_exact_match(const string &name, btp_stack *s = 0);
00210 
00211     bool is_end_of_rows(int i);
00212 
00213     friend class SequenceTest;
00214 
00215 protected:
00216 
00217     typedef stack<SequenceValues*> sequence_values_stack_t;
00218 
00219     virtual bool serialize_parent_part_one(const string &dataset, DDS &dds,
00220                                            ConstraintEvaluator &eval,
00221                                            Marshaller &m);
00222     virtual void serialize_parent_part_two(const string &dataset, DDS &dds,
00223                                            ConstraintEvaluator &eval,
00224                                            Marshaller &m);
00225     virtual bool serialize_leaf(const string &dataset, DDS &dds,
00226                                 ConstraintEvaluator &eval,
00227                                 Marshaller &m, bool ce_eval);
00228 
00229     virtual void intern_data_private(const string &dataset,
00230                                        ConstraintEvaluator &eval,
00231                                        DDS &dds,
00232                                        sequence_values_stack_t &sequence_values_stack);
00233     virtual void intern_data_for_leaf(const string &dataset, DDS &dds,
00234                                         ConstraintEvaluator &eval,
00235                                         sequence_values_stack_t &sequence_values_stack);
00236 
00237     virtual void intern_data_parent_part_one(const string &dataset, DDS &dds,
00238             ConstraintEvaluator &eval,
00239             sequence_values_stack_t &sequence_values_stack);
00240 
00241     virtual void intern_data_parent_part_two(const string &dataset, DDS &dds,
00242             ConstraintEvaluator &eval,
00243             sequence_values_stack_t &sequence_values_stack);
00244 
00245 public:
00246 
00247     Sequence(const string &n = "");
00248 
00249     Sequence(const Sequence &rhs);
00250 
00251     virtual ~Sequence();
00252 
00253     Sequence &operator=(const Sequence &rhs);
00254 
00255     virtual BaseType *ptr_duplicate();
00256 
00257     virtual string toString();
00258 
00259     virtual int element_count(bool leaves = false);
00260 
00261     virtual bool is_linear();
00262 
00263     virtual void set_send_p(bool state);
00264     virtual void set_read_p(bool state);
00265     virtual void set_in_selection(bool state);
00266 
00267     virtual unsigned int width();
00268 
00269     virtual int length();
00270 
00271     virtual int number_of_rows();
00272 
00273     virtual bool read_row(int row, const string &dataset, DDS &dds,
00274                           ConstraintEvaluator &eval, bool ce_eval = true);
00275 
00276     virtual void intern_data(const string &dataset, ConstraintEvaluator &eval,
00277                              DDS &dds);
00278     virtual bool serialize(const string &dataset, ConstraintEvaluator &eval,
00279                            DDS &dds, Marshaller &m, bool ce_eval = true);
00280     virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
00281 
00283     void reset_row_number();
00284 
00285     int get_starting_row_number();
00286 
00287     virtual int get_row_stride();
00288 
00289     virtual int get_ending_row_number();
00290 
00291     virtual void set_row_number_constraint(int start, int stop, int stride = 1);
00292 
00294     bool get_unsent_data()
00295     {
00296         return d_unsent_data;
00297     }
00298 
00300     void set_unsent_data(bool usd)
00301     {
00302         d_unsent_data = usd;
00303     }
00304 
00305     // Move me!
00306     virtual unsigned int val2buf(void *val, bool reuse = false);
00307     virtual unsigned int buf2val(void **val);
00308 
00309     virtual void set_value(SequenceValues &values);
00310     virtual SequenceValues value();
00311 
00312     virtual BaseType *var(const string &name, bool exact_match = true,
00313                           btp_stack *s = 0);
00314     virtual BaseType *var(const string &n, btp_stack &s);
00315 
00316     virtual BaseType *var_value(size_t row, const string &name);
00317 
00318     virtual BaseType *var_value(size_t row, size_t i);
00319 
00320     virtual BaseTypeRow *row_value(size_t row);
00321 
00322     virtual void add_var(BaseType *, Part part = nil);
00323     virtual void print_one_row(FILE *out, int row, string space,
00324                                bool print_row_num = false);
00325     virtual void print_one_row(ostream &out, int row, string space,
00326                                bool print_row_num = false);
00327     virtual void print_val_by_rows(FILE *out, string space = "",
00328                                    bool print_decl_p = true,
00329                                    bool print_row_numbers = true);
00330     virtual void print_val_by_rows(ostream &out, string space = "",
00331                                    bool print_decl_p = true,
00332                                    bool print_row_numbers = true);
00333     virtual void print_val(FILE *out, string space = "",
00334                            bool print_decl_p = true);
00335     virtual void print_val(ostream &out, string space = "",
00336                            bool print_decl_p = true);
00337 
00338     virtual bool check_semantics(string &msg, bool all = false);
00339 
00340     virtual void set_leaf_p(bool state);
00341 
00342     virtual bool is_leaf_sequence();
00343 
00344     virtual void set_leaf_sequence(int lvl = 1);
00345 
00346     virtual void dump(ostream &strm) const ;
00347 };
00348 
00349 } // namespace libdap
00350 
00351 #endif //_sequence_h

Generated on Tue Mar 4 18:01:55 2008 for libdap++ by  doxygen 1.5.1