libdap
Updated for version 3.17.0
|
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 #include <stack> 00046 00047 #include "Constructor.h" 00048 00049 #ifndef S_XDRUtils_h 00050 #include "XDRUtils.h" 00051 #endif 00052 00053 namespace libdap { 00054 00055 class BaseType; 00056 class ConstraintEvaluator; 00057 class D4Group; 00058 00061 typedef vector<BaseType *> BaseTypeRow; 00062 00064 typedef vector<BaseTypeRow *> SequenceValues; 00065 00162 class Sequence: public Constructor 00163 { 00164 private: 00165 // This holds the values read off the wire. Values are stored in 00166 // instances of BaseTypeRow objects which hold instances of BaseType. 00167 SequenceValues d_values; 00168 00169 // The number of the row that has just been deserialized. Before 00170 // deserialized has been called, this field is -1. 00171 int d_row_number; 00172 00173 // If a client asks for certain rows of a sequence using the bracket 00174 // notation (<tt>[<start>:<stride>:<stop>]</tt>) primarily intended for 00175 // arrays 00176 // and grids, record that information in the next three fields. This 00177 // information can be used by the translation software. s.a. the accessor 00178 // and mutator methods for these members. Values of -1 indicate that 00179 // these have not yet been set. 00180 int d_starting_row_number; 00181 int d_row_stride; 00182 int d_ending_row_number; 00183 00184 // Used to track if data has not already been sent. 00185 bool d_unsent_data; 00186 00187 // Track if the Start Of Instance marker has been written. Needed to 00188 // properly send EOS for only the outer Sequence when a selection 00189 // returns an empty Sequence. 00190 bool d_wrote_soi; 00191 00192 // This signals whether the sequence is a leaf or parent. 00193 bool d_leaf_sequence; 00194 00195 // In a hierarchy of sequences, is this the top most? 00196 bool d_top_most; 00197 00198 bool is_end_of_rows(int i); 00199 00200 friend class SequenceTest; 00201 00202 protected: 00203 void m_duplicate(const Sequence &s); 00204 typedef stack<SequenceValues*> sequence_values_stack_t; 00205 00206 virtual bool serialize_parent_part_one(DDS &dds, ConstraintEvaluator &eval, Marshaller &m); 00207 virtual void serialize_parent_part_two(DDS &dds, ConstraintEvaluator &eval, Marshaller &m); 00208 virtual bool serialize_leaf(DDS &dds, ConstraintEvaluator &eval, Marshaller &m, bool ce_eval); 00209 00210 virtual void intern_data_private(ConstraintEvaluator &eval, DDS &dds, 00211 sequence_values_stack_t &sequence_values_stack); 00212 virtual void intern_data_for_leaf(DDS &dds, ConstraintEvaluator &eval, 00213 sequence_values_stack_t &sequence_values_stack); 00214 00215 virtual void intern_data_parent_part_one(DDS &dds, ConstraintEvaluator &eval, 00216 sequence_values_stack_t &sequence_values_stack); 00217 00218 virtual void intern_data_parent_part_two(DDS &dds, ConstraintEvaluator &eval, 00219 sequence_values_stack_t &sequence_values_stack); 00220 #if 0 00221 // See note in Sequence.cc 00222 virtual void load_prototypes_with_values(int d_row_number); 00223 #endif 00224 00225 public: 00226 00227 Sequence(const string &n); 00228 Sequence(const string &n, const string &d); 00229 00230 Sequence(const Sequence &rhs); 00231 00232 virtual ~Sequence(); 00233 00234 Sequence &operator=(const Sequence &rhs); 00235 00236 virtual BaseType *ptr_duplicate(); 00237 00238 virtual void clear_local_data(); 00239 00240 virtual BaseType *transform_to_dap4(D4Group *root, Constructor *container); 00241 00242 virtual bool is_dap2_only_type(); 00243 00244 virtual string toString(); 00245 00246 virtual bool is_linear(); 00247 00248 virtual int length() const; 00249 00250 virtual int number_of_rows() const; 00251 00252 virtual bool read_row(int row, DDS &dds, ConstraintEvaluator &eval, bool ce_eval = true); 00253 00254 virtual void intern_data(ConstraintEvaluator &eval, DDS &dds); 00255 virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true); 00256 #if 0 00257 virtual bool serialize_no_release(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true); 00258 #endif 00259 virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false); 00260 00262 void reset_row_number(); 00263 00264 int get_starting_row_number(); 00265 00266 virtual int get_row_stride(); 00267 00268 virtual int get_ending_row_number(); 00269 00270 virtual void set_row_number_constraint(int start, int stop, int stride = 1); 00271 00273 bool get_unsent_data() 00274 { 00275 return d_unsent_data; 00276 } 00277 00279 void set_unsent_data(bool usd) 00280 { 00281 d_unsent_data = usd; 00282 } 00283 00284 virtual void set_value(SequenceValues &values); 00285 virtual SequenceValues value(); 00286 virtual SequenceValues &value_ref(); 00287 00288 virtual BaseType *var_value(size_t row, const string &name); 00289 00290 virtual BaseType *var_value(size_t row, size_t i); 00291 00292 virtual BaseTypeRow *row_value(size_t row); 00293 virtual void print_one_row(ostream &out, int row, string space, bool print_row_num = false); 00294 virtual void print_val_by_rows(ostream &out, string space = "", bool print_decl_p = true, bool print_row_numbers = 00295 true); 00296 virtual void print_val(ostream &out, string space = "", bool print_decl_p = true); 00297 00298 virtual void print_one_row(FILE *out, int row, string space, bool print_row_num = false); 00299 virtual void print_val_by_rows(FILE *out, string space = "", bool print_decl_p = true, 00300 bool print_row_numbers = true); 00301 virtual void print_val(FILE *out, string space = "", bool print_decl_p = true); 00302 00303 virtual void set_leaf_p(bool state); 00304 00305 virtual bool is_leaf_sequence(); 00306 00307 virtual void set_leaf_sequence(int lvl = 1); 00308 00309 virtual void dump(ostream &strm) const; 00310 }; 00311 00312 } // namespace libdap 00313 00314 #endif //_sequence_h