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

Generated on Wed Jun 27 12:56:39 2007 for libdap++ by  doxygen 1.4.7