Sequence.h
// -*- mode: c++; c-basic-offset:4 -*-
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.
// Copyright (c) 2002,2003 OPeNDAP, Inc.
// Author: James Gallagher <jgallagher@opendap.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
// (c) COPYRIGHT URI/MIT 1994-1999
// Please read the full copyright statement in the file COPYRIGHT_URI.
//
// Authors:
// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
// Interface for the class Sequence. A sequence contains a single set
// of variables, all at the same lexical level just like a structure
// (and like a structure, it may contain other ctor types...). Unlike
// a structure, a sequence defines a pattern that is repeated N times
// for a sequence of N elements. Thus, Sequence { String name; Int32
// age; } person; means a sequence of N persons where each contain a
// name and age. The sequence can be arbitrarily long (i.e., you don't
// know N by looking at the sequence declaration.
//
// jhrg 9/14/94
#ifndef _sequence_h
#define _sequence_h 1
#include <stack>
#include "Constructor.h"
#ifndef S_XDRUtils_h
#include "XDRUtils.h"
#endif
namespace libdap {
class BaseType;
class ConstraintEvaluator;
class D4Group;
typedef vector<BaseType *> BaseTypeRow;
typedef vector<BaseTypeRow *> SequenceValues;
class Sequence: public Constructor
{
private:
// This holds the values read off the wire. Values are stored in
// instances of BaseTypeRow objects which hold instances of BaseType.
SequenceValues d_values;
// The number of the row that has just been deserialized. Before
// deserialized has been called, this field is -1.
int d_row_number;
// If a client asks for certain rows of a sequence using the bracket
// notation (<tt>[<start>:<stride>:<stop>]</tt>) primarily intended for
// arrays
// and grids, record that information in the next three fields. This
// information can be used by the translation software. s.a. the accessor
// and mutator methods for these members. Values of -1 indicate that
// these have not yet been set.
int d_starting_row_number;
int d_row_stride;
int d_ending_row_number;
// Used to track if data has not already been sent.
bool d_unsent_data;
// Track if the Start Of Instance marker has been written. Needed to
// properly send EOS for only the outer Sequence when a selection
// returns an empty Sequence.
bool d_wrote_soi;
// This signals whether the sequence is a leaf or parent.
bool d_leaf_sequence;
// In a hierarchy of sequences, is this the top most?
bool d_top_most;
bool is_end_of_rows(int i);
friend class SequenceTest;
protected:
void m_duplicate(const Sequence &s);
typedef stack<SequenceValues*> sequence_values_stack_t;
virtual bool serialize_parent_part_one(DDS &dds, ConstraintEvaluator &eval, Marshaller &m);
virtual void serialize_parent_part_two(DDS &dds, ConstraintEvaluator &eval, Marshaller &m);
virtual bool serialize_leaf(DDS &dds, ConstraintEvaluator &eval, Marshaller &m, bool ce_eval);
virtual void intern_data_private(ConstraintEvaluator &eval, DDS &dds,
sequence_values_stack_t &sequence_values_stack);
virtual void intern_data_for_leaf(DDS &dds, ConstraintEvaluator &eval,
sequence_values_stack_t &sequence_values_stack);
virtual void intern_data_parent_part_one(DDS &dds, ConstraintEvaluator &eval,
sequence_values_stack_t &sequence_values_stack);
virtual void intern_data_parent_part_two(DDS &dds, ConstraintEvaluator &eval,
sequence_values_stack_t &sequence_values_stack);
public:
Sequence(const string &n);
Sequence(const string &n, const string &d);
Sequence(const Sequence &rhs);
virtual ~Sequence();
Sequence &operator=(const Sequence &rhs);
virtual BaseType *ptr_duplicate();
virtual void clear_local_data();
virtual void transform_to_dap4(D4Group *root, Constructor *container);
virtual bool is_dap2_only_type();
virtual string toString();
virtual bool is_linear();
virtual int length() const;
virtual int number_of_rows() const;
virtual bool read_row(int row, DDS &dds, ConstraintEvaluator &eval, bool ce_eval = true);
virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
void reset_row_number();
// I added a second method instead of a param with a default value because I think
// this will result only in an addition to the ABI/API, not a change. 5/16/15 jhrg
void reset_row_number(bool recur);
void increment_row_number(unsigned int i) { d_row_number += i; }
int get_row_number() const { return d_row_number; }
int get_starting_row_number();
virtual int get_row_stride();
virtual int get_ending_row_number();
virtual void set_row_number_constraint(int start, int stop, int stride = 1);
bool get_unsent_data() const
{
return d_unsent_data;
}
void set_unsent_data(bool usd)
{
d_unsent_data = usd;
}
virtual void set_value(SequenceValues &values);
virtual SequenceValues value();
virtual SequenceValues &value_ref();
virtual BaseType *var_value(size_t row, const string &name);
virtual BaseType *var_value(size_t row, size_t i);
virtual BaseTypeRow *row_value(size_t row);
virtual void print_one_row(ostream &out, int row, string space, bool print_row_num = false);
virtual void print_val_by_rows(ostream &out, string space = "", bool print_decl_p = true, bool print_row_numbers =
true);
virtual void print_val(ostream &out, string space = "", bool print_decl_p = true);
virtual void print_one_row(FILE *out, int row, string space, bool print_row_num = false);
virtual void print_val_by_rows(FILE *out, string space = "", bool print_decl_p = true,
bool print_row_numbers = true);
virtual void print_val(FILE *out, string space = "", bool print_decl_p = true);
virtual void set_leaf_p(bool state);
virtual bool is_leaf_sequence();
virtual void set_leaf_sequence(int lvl = 1);
virtual void dump(ostream &strm) const;
};
} // namespace libdap
#endif //_sequence_h
libdap::BaseType
The basic data type for the DODS DAP types.
Definition BaseType.h:120
libdap::BaseType::name
virtual string name() const
Returns the name of the class instance.
Definition BaseType.cc:317
libdap::ConstraintEvaluator
Evaluate a constraint expression.
Definition ConstraintEvaluator.h:43
libdap::Constructor
Definition Constructor.h:44
libdap::Constructor::intern_data
void intern_data() override
Read data into this variable.
Definition Constructor.cc:525
libdap::D4Group
Definition D4Group.h:44
libdap::DDS
Definition DDS.h:178
libdap::Marshaller
abstract base class used to marshal/serialize dap data objects
Definition Marshaller.h:50
libdap::Sequence
Holds a sequence.
Definition Sequence.h:163
libdap::Sequence::transform_to_dap4
virtual void transform_to_dap4(D4Group *root, Constructor *container)
Definition Sequence.cc:212
libdap::Sequence::value
virtual SequenceValues value()
Definition Sequence.cc:346
libdap::Sequence::toString
virtual string toString()
Definition Sequence.cc:279
libdap::Sequence::dump
virtual void dump(ostream &strm) const
dumps information about this object
Definition Sequence.cc:1282
libdap::Sequence::read_row
virtual bool read_row(int row, DDS &dds, ConstraintEvaluator &eval, bool ce_eval=true)
Definition Sequence.cc:501
libdap::Sequence::set_leaf_sequence
virtual void set_leaf_sequence(int lvl=1)
Mark the Sequence which holds the leaf elements.
Definition Sequence.cc:1240
libdap::Sequence::print_val
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition Sequence.cc:1201
libdap::Sequence::value_ref
virtual SequenceValues & value_ref()
Definition Sequence.cc:354
libdap::Sequence::set_value
virtual void set_value(SequenceValues &values)
Definition Sequence.cc:339
libdap::Sequence::ptr_duplicate
virtual BaseType * ptr_duplicate()
Definition Sequence.cc:192
libdap::Sequence::is_linear
virtual bool is_linear()
Check to see whether this variable can be printed simply.
Definition Sequence.cc:294
libdap::Sequence::var_value
virtual BaseType * var_value(size_t row, const string &name)
Get the BaseType pointer to the named variable of a given row.
Definition Sequence.cc:365
libdap::Sequence::clear_local_data
virtual void clear_local_data()
Definition Sequence.cc:252
libdap::Sequence::is_dap2_only_type
virtual bool is_dap2_only_type()
Definition Sequence.cc:274
libdap::Sequence::get_unsent_data
bool get_unsent_data() const
Get the unsent data property.
Definition Sequence.h:271
libdap::Sequence::get_starting_row_number
int get_starting_row_number()
Get the starting row number.
Definition Sequence.cc:1066
libdap::Sequence::reset_row_number
void reset_row_number()
Rest the row number counter.
Definition Sequence.cc:429
libdap::Sequence::set_unsent_data
void set_unsent_data(bool usd)
Set the unsent data property.
Definition Sequence.h:277
libdap::Sequence::serialize
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Definition Sequence.cc:609
libdap::Sequence::length
virtual int length() const
Definition Sequence.cc:415
libdap::Sequence::deserialize
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Deserialize (read from the network) the entire Sequence.
Definition Sequence.cc:1007
libdap::Sequence::get_row_stride
virtual int get_row_stride()
Get the row stride.
Definition Sequence.cc:1081
libdap::Sequence::get_ending_row_number
virtual int get_ending_row_number()
Get the ending row number.
Definition Sequence.cc:1097
libdap::Sequence::row_value
virtual BaseTypeRow * row_value(size_t row)
Get a whole row from the sequence.
Definition Sequence.cc:327
libdap::Sequence::set_row_number_constraint
virtual void set_row_number_constraint(int start, int stop, int stride=1)
Definition Sequence.cc:1110
libdap::UnMarshaller
abstract base class used to unmarshall/deserialize dap data objects
Definition UnMarshaller.h:55
libdap
top level DAP object to house generic methods
Definition AlarmHandler.h:36
libdap::BaseTypeRow
vector< BaseType * > BaseTypeRow
Definition D4Sequence.h:50
libdap::SequenceValues
vector< BaseTypeRow * > SequenceValues
Definition D4Sequence.h:53