libdap  Updated for version 3.17.0
D4Sequence.h
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) 2013 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 #ifndef _d4sequence_h
00026 #define _d4sequence_h 1
00027 
00028 #include "Constructor.h"
00029 
00030 // DAP2 Sequence supported subsetting using the array notation. This might
00031 // be introduced into DAP4 later on.
00032 #define INDEX_SUBSETTING 0
00033 
00034 class Crc32;
00035 
00036 namespace libdap
00037 {
00038 class BaseType;
00039 
00042 typedef vector<BaseType *> D4SeqRow;
00043 
00045 typedef vector<D4SeqRow *> D4SeqValues;
00046 
00124 class D4Sequence: public Constructor
00125 {
00126 private:
00127 
00128 protected:
00129     // This holds the values of the sequence. Values are stored in
00130     // instances of BaseTypeRow objects which hold instances of BaseType.
00131     //
00132     // Allow these values to be accessed by subclasses
00133     D4SeqValues d_values;
00134 
00135     int64_t d_length;   // How many elements are in the sequence; -1 if not currently known
00136 
00137 #if INDEX_SUBSETTING
00138     int d_starting_row_number;
00139     int d_row_stride;
00140     int d_ending_row_number;
00141 #endif
00142 
00143     void m_duplicate(const D4Sequence &s);
00144 
00145     friend class D4SequenceTest;
00146 
00147 public:
00148 
00149     D4Sequence(const string &n);
00150     D4Sequence(const string &n, const string &d);
00151 
00152     D4Sequence(const D4Sequence &rhs);
00153 
00154     virtual ~D4Sequence();
00155 
00156     D4Sequence &operator=(const D4Sequence &rhs);
00157 
00158     virtual BaseType *ptr_duplicate();
00159 
00160     virtual void clear_local_data();
00161 
00170     virtual int length() const { return (int)d_length; }
00171 
00176     virtual void set_length(int count) { d_length = (int64_t)count; }
00177 
00178     virtual bool read_next_instance(/*DMR &dmr, ConstraintEvaluator &eval,*/ bool filter);
00179 
00180     virtual void intern_data(ConstraintEvaluator &, DDS &) {
00181         throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
00182     }
00183     virtual bool serialize(ConstraintEvaluator &, DDS &, Marshaller &, bool ) {
00184         throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
00185     }
00186     virtual bool deserialize(UnMarshaller &, DDS *, bool ) {
00187         throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
00188     }
00189 
00190     // DAP4
00191     virtual void intern_data(/*Crc32 &checksum, DMR &dmr, ConstraintEvaluator &eval*/);
00192     virtual void serialize(D4StreamMarshaller &m, DMR &dmr, /*ConstraintEvaluator &eval,*/ bool filter = false);
00193 #if 0
00194     virtual void serialize_no_release(D4StreamMarshaller &m, DMR &dmr, bool filter = false);
00195 #endif
00196     virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);
00197 
00198 #if INDEX_SUBSETTING
00199 
00210     virtual int get_starting_row_number() const { return d_starting_row_number; }
00211 
00222     virtual int get_row_stride() const { return d_row_stride; }
00223 
00235     virtual int get_ending_row_number() const { return d_ending_row_number; }
00236 
00237     virtual void set_row_number_constraint(int start, int stop, int stride = 1);
00238 #endif
00239 
00249     virtual void set_value(D4SeqValues &values) { d_values = values; d_length = d_values.size(); }
00250 
00258     virtual D4SeqValues value() const { return d_values; }
00259 
00260     virtual D4SeqRow *row_value(size_t row);
00261     virtual BaseType *var_value(size_t row, const string &name);
00262     virtual BaseType *var_value(size_t row, size_t i);
00263 
00264     virtual void print_one_row(ostream &out, int row, string space,
00265                                bool print_row_num = false);
00266     virtual void print_val_by_rows(ostream &out, string space = "",
00267                                    bool print_decl_p = true,
00268                                    bool print_row_numbers = true);
00269     virtual void print_val(ostream &out, string space = "",
00270                            bool print_decl_p = true);
00271 
00272     virtual void dump(ostream &strm) const ;
00273 };
00274 
00275 } // namespace libdap
00276 
00277 #endif //_sequence_h