libdap::Sequence Class Reference

Holds a sequence. More...

#include <Sequence.h>

Inheritance diagram for libdap::Sequence:

Inheritance graph
[legend]
Collaboration diagram for libdap::Sequence:

Collaboration graph
[legend]

List of all members.

Public Types

typedef stack< BaseType * > btp_stack
typedef std::vector< BaseType * >
::const_iterator 
Vars_citer
typedef std::vector< BaseType * >
::iterator 
Vars_iter
typedef std::vector< BaseType * >
::reverse_iterator 
Vars_riter

Public Member Functions

virtual void add_var (BaseType *, Part part=nil)
 Adds a variable to the Sequence.
virtual unsigned int buf2val (void **val)
virtual bool check_semantics (string &msg, bool all=false)
 Compare an object's current state with the semantics of its type.
virtual bool deserialize (UnMarshaller &um, DDS *dds, bool reuse=false)
 Deserialize (read from the network) the entire Sequence.
virtual void dump (ostream &strm) const
 dumps information about this object
virtual int element_count (bool leaves=false)
 Count the members of constructor types.
virtual AttrTableget_attr_table ()
virtual int get_ending_row_number ()
 Get the ending row number.
virtual BaseTypeget_parent ()
virtual int get_row_stride ()
 Get the row stride.
int get_starting_row_number ()
 Get the starting row number.
bool get_unsent_data ()
 Get the unsent data property.
BaseTypeget_var_index (int i)
Vars_iter get_vars_iter (int i)
virtual void intern_data (const string &dataset, ConstraintEvaluator &eval, DDS &dds)
virtual bool is_constructor_type ()
 Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable.
virtual bool is_in_selection ()
 Is this variable part of the current selection?
virtual bool is_leaf_sequence ()
virtual bool is_linear ()
 Check to see whether this variable can be printed simply.
virtual bool is_simple_type ()
 Returns true if the instance is a numeric, string or URL type variable.
virtual bool is_vector_type ()
 Returns true if the instance is a vector (i.e., array) type variable.
virtual int length ()
string name () const
 Returns the name of the class instance.
virtual int number_of_rows ()
Sequenceoperator= (const Sequence &rhs)
virtual bool ops (BaseType *b, int op, const string &dataset)
 Evaluate relational operators.
virtual void print_decl (ostream &out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false)
 Print an ASCII representation of the variable structure.
virtual void print_decl (FILE *out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false)
 Print an ASCII representation of the variable structure.
virtual void print_one_row (ostream &out, int row, string space, bool print_row_num=false)
virtual void print_one_row (FILE *out, int row, string space, bool print_row_num=false)
virtual void print_val (ostream &out, string space="", bool print_decl_p=true)
 Prints the value of the variable.
virtual void print_val (FILE *out, string space="", bool print_decl_p=true)
 Prints the value of the variable.
virtual void print_val_by_rows (ostream &out, string space="", bool print_decl_p=true, bool print_row_numbers=true)
virtual void print_val_by_rows (FILE *out, string space="", bool print_decl_p=true, bool print_row_numbers=true)
virtual void print_xml (ostream &out, string space=" ", bool constrained=false)
virtual void print_xml (FILE *out, string space=" ", bool constrained=false)
virtual BaseTypeptr_duplicate ()
virtual bool read (const string &dataset)
 Read data into a local buffer.
virtual bool read_p ()
 Has this variable been read?
virtual bool read_row (int row, const string &dataset, DDS &dds, ConstraintEvaluator &eval, bool ce_eval=true)
void reset_row_number ()
 Rest the row number counter.
virtual BaseTypeRowrow_value (size_t row)
 Get a whole row from the sequence.
virtual bool send_p ()
 Should this variable be sent?
 Sequence (const Sequence &rhs)
 The Sequence copy constructor.
 Sequence (const string &n="")
 The Sequence constructor.
virtual bool serialize (const string &dataset, ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
virtual void set_attr_table (const AttrTable &at)
virtual void set_in_selection (bool state)
virtual void set_leaf_p (bool state)
virtual void set_leaf_sequence (int lvl=1)
 Mark the Sequence which holds the leaf elements.
virtual void set_name (const string &n)
 Sets the name of the class instance.
virtual void set_parent (BaseType *parent)
virtual void set_read_p (bool state)
 Sets the value of the read_p property.
virtual void set_row_number_constraint (int start, int stop, int stride=1)
virtual void set_send_p (bool state)
virtual void set_synthesized_p (bool state)
void set_type (const Type &t)
 Sets the type of the class instance.
void set_unsent_data (bool usd)
 Set the unsent data property.
virtual void set_value (SequenceValues &values)
virtual bool synthesized_p ()
virtual string toString ()
virtual void transfer_attributes (AttrTable::entry *entry)
Type type () const
 Returns the type of the class instance.
string type_name () const
 Returns the type of the class instance as a string.
virtual unsigned int val2buf (void *val, bool reuse=false)
virtual SequenceValues value ()
virtual BaseTypevar (const string &name, btp_stack &s)
virtual BaseTypevar (const string &name="", bool exact_match=true, btp_stack *s=0)
 Returns a pointer to a member of a constructor class.
virtual BaseTypevar (const string &n, btp_stack &s)
virtual BaseTypevar (const string &name, bool exact_match=true, btp_stack *s=0)
Vars_iter var_begin ()
Vars_iter var_end ()
Vars_riter var_rbegin ()
Vars_riter var_rend ()
virtual BaseTypevar_value (size_t row, size_t i)
 Get the BaseType pointer to the $i^{th}$ variable of row.
virtual BaseTypevar_value (size_t row, const string &name)
 Get the BaseType pointer to the named variable of a given row.
virtual unsigned int width ()
 Returns the size of the class instance data.
virtual ~Sequence ()

Protected Types

typedef stack< SequenceValues * > sequence_values_stack_t

Protected Member Functions

void _duplicate (const BaseType &bt)
 Perform a deep copy.
void _duplicate (const Constructor &s)
virtual AttrTablefind_matching_container (AttrTable::entry *source, BaseType **dest_variable)
virtual void intern_data_for_leaf (const string &dataset, DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
virtual void intern_data_parent_part_one (const string &dataset, DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
virtual void intern_data_parent_part_two (const string &dataset, DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
virtual void intern_data_private (const string &dataset, ConstraintEvaluator &eval, DDS &dds, sequence_values_stack_t &sequence_values_stack)
virtual bool serialize_leaf (const string &dataset, DDS &dds, ConstraintEvaluator &eval, Marshaller &m, bool ce_eval)
virtual bool serialize_parent_part_one (const string &dataset, DDS &dds, ConstraintEvaluator &eval, Marshaller &m)
virtual void serialize_parent_part_two (const string &dataset, DDS &dds, ConstraintEvaluator &eval, Marshaller &m)

Protected Attributes

std::vector< BaseType * > _vars

Friends

class SequenceTest


Detailed Description

This is the interface for the class Sequence. A sequence contains a single set of variables, all at the same lexical level just like a Structure. Like a Structure, a Sequence may contain other compound types, including other Sequences. Unlike a Structure, a Sequence defines a pattern that is repeated N times for a sequence of N elements. It is useful to think of a Sequence as representing a table of values (like a relational database), with each row of the table corresponding to a Sequence ``instance.'' (This usage can be confusing, since ``instance'' also refers to a particular item of class Sequence.) For example:

    Sequence {
      String name;
      Int32 age;
    } person;
    

This represents a Sequence of ``person'' records, each instance of which contains a name and an age:

    Fred       34
    Ralph      23
    Andrea     29
    ...
    

A Sequence can be arbitrarily long, which is to say that its length is not part of its declaration. A Sequence can contain other Sequences:

    Sequence {
      String name;
      Int32 age;
      Sequence {
        String friend;
      } friend_list;
    } person;
    

This is still represented as a single table, but each row contains the elements of both the main Sequence and the nested one:

    Fred       34     Norman
    Fred       34     Andrea
    Fred       34     Ralph
    Fred       34     Lisa
    Ralph      23     Norman
    Ralph      23     Andrea
    Ralph      23     Lisa
    Ralph      23     Marth
    Ralph      23     Throckmorton
    Ralph      23     Helga
    Ralph      23     Millicent
    Andrea     29     Ralph
    Andrea     29     Natasha
    Andrea     29     Norman
    ...        ..     ...
    

Internally, the Sequence is represented by a vector of vectors. The members of the outer vector are the members of the Sequence. This includes the nested Sequences, as in the above example.

NB: Note that in the past this class had a different behavior. It held only one row at a time and the deserialize(...) method had to be called from within a loop. This is no longer true. Now the deserailize(...) method should be called once and will read the entire sequence's values from the server. All the values are now stored in an instance of Sequence, not just a single row's.

Because the length of a Sequence is indeterminate, there are changes to the behavior of the functions to read this class of data. The read() function for Sequence must be written so that successive calls return values for successive rows of the Sequence.

Similar to a C structure, you refer to members of Sequence elements with a ``.'' notation. For example, if the Sequence has a member Sequence called ``Tom'' and Tom has a member Float32 called ``shoe_size'', you can refer to Tom's shoe size as ``Tom.shoe_size''.

Note:
This class contains the 'logic' for both the server- and client-side behavior. The field d_values is used by the client-side methods to store the entire Sequence. On the server-side, the read() method uses an underlying data system to read one row of data values which are then serialized using the serialize() methods of each variable.
Todo:
Refactor along with Structure moving methods up into Constructor.
Todo:
Add an isEmpty() method which returns true if the Sequence is empty. This should work before and after calling deserialize().

Definition at line 171 of file Sequence.h.


Member Typedef Documentation

typedef stack<BaseType *> libdap::BaseType::btp_stack [inherited]

Definition at line 211 of file BaseType.h.

Definition at line 217 of file Sequence.h.

typedef std::vector<BaseType *>::const_iterator libdap::Constructor::Vars_citer [inherited]

Definition at line 54 of file Constructor.h.

typedef std::vector<BaseType *>::iterator libdap::Constructor::Vars_iter [inherited]

Definition at line 55 of file Constructor.h.

typedef std::vector<BaseType *>::reverse_iterator libdap::Constructor::Vars_riter [inherited]

Definition at line 56 of file Constructor.h.


Constructor & Destructor Documentation

libdap::Sequence::Sequence ( const string &  n = ""  ) 

The Sequence constructor requires only the name of the variable to be created. The name may be omitted, which will create a nameless variable. This may be adequate for some applications.

Parameters:
n A string containing the name of the variable to be created.

Definition at line 148 of file Sequence.cc.

Referenced by ptr_duplicate().

libdap::Sequence::Sequence ( const Sequence rhs  ) 

Definition at line 156 of file Sequence.cc.

libdap::Sequence::~Sequence (  )  [virtual]

Definition at line 184 of file Sequence.cc.

References libdap::Constructor::_vars, and DBG2.


Member Function Documentation

void libdap::BaseType::_duplicate ( const BaseType bt  )  [protected, inherited]

Perform a deep copy. Copies the values of bt into *this. Pointers are dereferenced and their values are copied into a newly allocated instance.

Parameters:
bt The source object.

Definition at line 66 of file BaseType.cc.

References libdap::BaseType::_name, libdap::BaseType::_read_p, libdap::BaseType::_send_p, libdap::BaseType::_synthesized_p, libdap::BaseType::_type, libdap::BaseType::d_attr, libdap::BaseType::d_in_selection, and libdap::BaseType::d_parent.

Referenced by libdap::BaseType::BaseType(), and libdap::BaseType::operator=().

void libdap::Constructor::_duplicate ( const Constructor s  )  [protected, inherited]

Definition at line 57 of file Constructor.cc.

Referenced by libdap::Constructor::operator=().

void libdap::Sequence::add_var ( BaseType bt,
Part  part = nil 
) [virtual]

Remember that if you wish to add a member to a nested Sequence, you must use the add_var() of that Sequence. This means that variable names need not be unique among a set of nested Sequences.

Parameters:
bt A pointer to the DAP2 type variable to add to this Sequence.
part defaults to nil

Reimplemented from libdap::BaseType.

Definition at line 308 of file Sequence.cc.

References libdap::Constructor::_vars, libdap::BaseType::ptr_duplicate(), and libdap::BaseType::set_parent().

Here is the call graph for this function:

unsigned int libdap::Sequence::buf2val ( void **  val  )  [virtual]

Never use this interface for Sequence! Use Sequence::var_value() or Sequence::row_value().

Deprecated:

Implements libdap::BaseType.

Definition at line 1225 of file Sequence.cc.

bool libdap::Sequence::check_semantics ( string &  msg,
bool  all = false 
) [virtual]

This function checks the class instance for internal consistency. This is important to check for complex constructor classes. For BaseType, an object is semantically correct if it has both a non-null name and type.

For example, an Int32 instance would return FALSE if it had no name or no type defined. A Grid instance might return FALSE for more complex reasons, such as having Map arrays of the wrong size or shape.

This function is used by the DDS class, and will rarely, if ever, be explicitly called by a DODS application program. A variable must pass this test before it is sent, but there may be many other stages in a retrieve operation where it would fail.

Returns:
Returns FALSE when the current state violates some aspect of the type semantics, TRUE otherwise.
Parameters:
msg A returned string, containing a message indicating the source of any problem.
all For complex constructor types (Grid, Sequence, Structure), this flag indicates whether to check the semantics of the member variables, too.
See also:
DDS::check_semantics

Reimplemented from libdap::BaseType.

Definition at line 1408 of file Sequence.cc.

References libdap::Constructor::_vars, libdap::BaseType::check_semantics(), libdap::BaseType::name(), libdap::BaseType::type_name(), and libdap::unique_names().

Here is the call graph for this function:

bool libdap::Sequence::deserialize ( UnMarshaller um,
DDS dds,
bool  reuse = false 
) [virtual]

This method used to read a single row at a time. Now the entire sequence is read at once. The method used to return True to indicate that more data needed to be deserialized and False when the sequence was completely read. Now it simply returns false. This might seem odd, but making this method return false breaks existing software the least.

Parameters:
um An UnMarshaller that knows how to deserialize data
dds A DataDDS from which to read.
reuse Passed to child objects when they are deserialized. Some implementations of derialize() use this to determine if new storage should be allocated or existing storage reused.
Exceptions:
Error if a sequence stream marker cannot be read.
InternalErr if the dds param is not a DataDDS.
Returns:
A return value of false indicates that an EOS ("end of Sequence") marker was found, while a value of true indicates that there are more rows to be read. This version always reads the entire sequence, so it always returns false.

Implements libdap::BaseType.

Definition at line 1095 of file Sequence.cc.

References libdap::Constructor::_vars, DBG2, libdap::BaseType::deserialize(), libdap::DataDDS::get_protocol(), libdap::DataDDS::get_protocol_major(), libdap::DataDDS::get_protocol_minor(), libdap::BaseType::name(), and libdap::BaseType::print_val().

Here is the call graph for this function:

void libdap::Sequence::dump ( ostream &  strm  )  const [virtual]

Displays the pointer value of this instance and information about this instance.

Parameters:
strm C++ i/o stream to dump the information to
Returns:
void

Reimplemented from libdap::Constructor.

Definition at line 1506 of file Sequence.cc.

References libdap::Constructor::dump(), libdap::DapIndent::Indent(), libdap::DapIndent::LMarg(), and libdap::DapIndent::UnIndent().

Here is the call graph for this function:

int libdap::Sequence::element_count ( bool  leaves = false  )  [virtual]

Return a count of the total number of variables in this variable. This is used to count the number of variables held by a constructor variable - for simple type and vector variables it always returns 1.

For compound data types, there are two ways to count members. You can count the members, or you can count the simple members and add that to the count of the compound members. For example, if a Structure contains an Int32 and another Structure that itself contains two Int32 members, the element count of the top-level structure could be two (one Int32 and one Structure) or three (one Int32 by itself and two Int32's in the subsidiary Structure). Use the leaves parameter to control which kind of counting you desire.

Returns:
Returns 1 for simple types. For compound members, the count depends on the leaves argument.
Parameters:
leaves This parameter is only relevant if the object contains other compound data types. If FALSE, the function counts only the data variables mentioned in the object's declaration. If TRUE, it counts the simple members, and adds that to the sum of the counts for the compound members. This parameter has no effect for simple type variables.

Reimplemented from libdap::BaseType.

Definition at line 226 of file Sequence.cc.

References libdap::Constructor::_vars.

Referenced by print_one_row().

AttrTable * libdap::Constructor::find_matching_container ( AttrTable::entry source,
BaseType **  dest_variable 
) [protected, virtual, inherited]

Given an attribute container from a table, find or make a destination for its contents in the current constructor variable.

Definition at line 132 of file Constructor.cc.

References libdap::AttrTable::append_container(), libdap::Attr_container, DBG, libdap::dods_grid_c, libdap::AttrTable::find_container(), libdap::BaseType::get_attr_table(), libdap::BaseType::get_parent(), libdap::AttrTable::entry::name, libdap::BaseType::type(), libdap::AttrTable::entry::type, and libdap::BaseType::var().

Referenced by libdap::Constructor::transfer_attributes().

Here is the call graph for this function:

AttrTable & libdap::BaseType::get_attr_table (  )  [virtual, inherited]

Get this variable's AttrTable. It's generally a bad idea to return a reference to a contained object, but in this case it seems that building an interface inside BaseType is overkill.

Use the AttrTable methods to manipulate the table.

Definition at line 480 of file BaseType.cc.

Referenced by libdap::DDS::find_matching_container(), libdap::Constructor::find_matching_container(), libdap::Grid::print_xml(), libdap::Constructor::print_xml(), libdap::BaseType::print_xml(), and libdap::Array::print_xml_core().

int libdap::Sequence::get_ending_row_number (  )  [virtual]

Return the ending row number if the sequence was constrained using row numbers (instead of, or in addition to, a relational constraint). If a relational constraint was also given, the row number corresponds to the row number of the sequence after applying the relational constraint.

If the bracket notation was not used to constrain this sequence, this method returns -1.

Returns:
The ending row number.

Definition at line 1187 of file Sequence.cc.

Referenced by intern_data_for_leaf(), and intern_data_parent_part_one().

BaseType * libdap::BaseType::get_parent (  )  [virtual, inherited]

Return a pointer to the Constructor or Vector which holds (contains) this variable. If this variable is at the top level, this method returns null.

Returns:
A BaseType pointer to the variable's parent.

Definition at line 550 of file BaseType.cc.

Referenced by libdap::DDS::find_matching_container(), libdap::Constructor::find_matching_container(), libdap::function_linear_scale(), intern_data_for_leaf(), intern_data_parent_part_two(), serialize_leaf(), and serialize_parent_part_two().

int libdap::Sequence::get_row_stride (  )  [virtual]

Return the row stride number if the sequence was constrained using row numbers (instead of, or in addition to, a relational constraint). If a relational constraint was also given, the row stride is applied to the sequence after applying the relational constraint.

If the bracket notation was not used to constrain this sequence, this method returns -1.

Returns:
The row stride.

Definition at line 1170 of file Sequence.cc.

Referenced by intern_data_for_leaf(), and intern_data_parent_part_one().

int libdap::Sequence::get_starting_row_number (  ) 

Return the starting row number if the sequence was constrained using row numbers (instead of, or in addition to, a relational constraint). If a relational constraint was also given, the row number corresponds to the row number of the sequence after applying the relational constraint.

If the bracket notation was not used to constrain this sequence, this method returns -1.

Returns:
The starting row number.

Definition at line 1154 of file Sequence.cc.

Referenced by intern_data_for_leaf(), and intern_data_parent_part_one().

bool libdap::Sequence::get_unsent_data (  )  [inline]

Definition at line 294 of file Sequence.h.

Referenced by intern_data_parent_part_two().

BaseType * libdap::Constructor::get_var_index ( int  i  )  [inherited]

Return the BaseType pointer for the ith variable.

Parameters:
i This index
Returns:
The corresponding BaseType*.

Definition at line 270 of file Constructor.cc.

References libdap::Constructor::_vars.

Constructor::Vars_iter libdap::Constructor::get_vars_iter ( int  i  )  [inherited]

Return the iterator for the ith variable.

Parameters:
i the index
Returns:
The corresponding Vars_iter

Definition at line 261 of file Constructor.cc.

References libdap::Constructor::_vars.

void libdap::Sequence::intern_data ( const string &  dataset,
ConstraintEvaluator eval,
DDS dds 
) [virtual]

This method is used to evaluate a constraint and based on those results load the Sequence variable with data. This simulates having a server call the serialize() method and a client call the deserialize() method without the overhead of any IPC. Use this method on the server-side to 'load the d_values field with data' so that other code and work with those data.

The somewhat odd algorithm used by serialize() is largely copied here, so comments about logic in serialize() and the related methods apply here as well.

Note:
Even though each Sequence variable has a values field, only the top-most Sequence in a hierarchy of Sequences holds values. The field accessed by the var_value() method is completely linked object; access the values of nested Sequences using the BaseType objects returned by var_value().

Only call this method for top-most Sequences. Never call it for Sequences which have a parent (directly or indirectly) variable that is a Sequence.

Parameters:
dataset The name of the data set
eval Use this contraint evaluator
dds This DDS holds the variables for the data source

Reimplemented from libdap::BaseType.

Definition at line 895 of file Sequence.cc.

References DBG, DBG2, intern_data_private(), and libdap::BaseType::name().

Here is the call graph for this function:

void libdap::Sequence::intern_data_for_leaf ( const string &  dataset,
DDS dds,
ConstraintEvaluator eval,
sequence_values_stack_t sequence_values_stack 
) [protected, virtual]

void libdap::Sequence::intern_data_parent_part_one ( const string &  dataset,
DDS dds,
ConstraintEvaluator eval,
sequence_values_stack_t sequence_values_stack 
) [protected, virtual]

void libdap::Sequence::intern_data_parent_part_two ( const string &  dataset,
DDS dds,
ConstraintEvaluator eval,
sequence_values_stack_t sequence_values_stack 
) [protected, virtual]

void libdap::Sequence::intern_data_private ( const string &  dataset,
ConstraintEvaluator eval,
DDS dds,
sequence_values_stack_t sequence_values_stack 
) [protected, virtual]

Definition at line 913 of file Sequence.cc.

References DBG, intern_data_for_leaf(), intern_data_parent_part_one(), is_leaf_sequence(), and libdap::BaseType::name().

Referenced by intern_data().

Here is the call graph for this function:

bool libdap::BaseType::is_constructor_type (  )  [virtual, inherited]

Returns:
True if the instance is a Structure, Sequence or Grid, False otherwise.

Definition at line 306 of file BaseType.cc.

References libdap::dods_array_c, libdap::dods_byte_c, libdap::dods_float32_c, libdap::dods_float64_c, libdap::do