libdap++ Updated for version 3.8.2
|
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(DDS &dds, 00220 ConstraintEvaluator &eval, 00221 Marshaller &m); 00222 virtual void serialize_parent_part_two(DDS &dds, 00223 ConstraintEvaluator &eval, 00224 Marshaller &m); 00225 virtual bool serialize_leaf(DDS &dds, 00226 ConstraintEvaluator &eval, 00227 Marshaller &m, bool ce_eval); 00228 00229 virtual void intern_data_private( ConstraintEvaluator &eval, 00230 DDS &dds, 00231 sequence_values_stack_t &sequence_values_stack); 00232 virtual void intern_data_for_leaf(DDS &dds, 00233 ConstraintEvaluator &eval, 00234 sequence_values_stack_t &sequence_values_stack); 00235 00236 virtual void intern_data_parent_part_one(DDS &dds, 00237 ConstraintEvaluator &eval, 00238 sequence_values_stack_t &sequence_values_stack); 00239 00240 virtual void intern_data_parent_part_two(DDS &dds, 00241 ConstraintEvaluator &eval, 00242 sequence_values_stack_t &sequence_values_stack); 00243 00244 public: 00245 00246 Sequence(const string &n); 00247 Sequence(const string &n, const string &d); 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, DDS &dds, 00274 ConstraintEvaluator &eval, bool ce_eval = true); 00275 00276 virtual void intern_data(ConstraintEvaluator &eval, DDS &dds); 00277 virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, 00278 Marshaller &m, bool ce_eval = true); 00279 virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false); 00280 00282 void reset_row_number(); 00283 00284 int get_starting_row_number(); 00285 00286 virtual int get_row_stride(); 00287 00288 virtual int get_ending_row_number(); 00289 00290 virtual void set_row_number_constraint(int start, int stop, int stride = 1); 00291 00293 bool get_unsent_data() 00294 { 00295 return d_unsent_data; 00296 } 00297 00299 void set_unsent_data(bool usd) 00300 { 00301 d_unsent_data = usd; 00302 } 00303 00304 // Move me! 00305 virtual unsigned int val2buf(void *val, bool reuse = false); 00306 virtual unsigned int buf2val(void **val); 00307 00308 virtual void set_value(SequenceValues &values); 00309 virtual SequenceValues value(); 00310 00311 virtual BaseType *var(const string &name, bool exact_match = true, 00312 btp_stack *s = 0); 00313 virtual BaseType *var(const string &n, btp_stack &s); 00314 00315 virtual BaseType *var_value(size_t row, const string &name); 00316 00317 virtual BaseType *var_value(size_t row, size_t i); 00318 00319 virtual BaseTypeRow *row_value(size_t row); 00320 00321 virtual void add_var(BaseType *, Part part = nil); 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(ostream &out, string space = "", 00325 bool print_decl_p = true, 00326 bool print_row_numbers = true); 00327 virtual void print_val(ostream &out, string space = "", 00328 bool print_decl_p = true); 00329 00330 //#if FILE_METHODS 00331 virtual void print_one_row(FILE *out, int row, string space, 00332 bool print_row_num = false); 00333 virtual void print_val_by_rows(FILE *out, string space = "", 00334 bool print_decl_p = true, 00335 bool print_row_numbers = true); 00336 virtual void print_val(FILE *out, string space = "", 00337 bool print_decl_p = true); 00338 //#endif 00339 00340 virtual bool check_semantics(string &msg, bool all = false); 00341 00342 virtual void set_leaf_p(bool state); 00343 00344 virtual bool is_leaf_sequence(); 00345 00346 virtual void set_leaf_sequence(int lvl = 1); 00347 00348 virtual void dump(ostream &strm) const ; 00349 }; 00350 00351 } // namespace libdap 00352 00353 #endif //_sequence_h