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

Generated on Wed Nov 14 03:15:44 2007 for libdap++ by  doxygen 1.5.1