libdap::BaseType Class Reference

The basic data type for the DODS DAP types. More...

#include <BaseType.h>

Inheritance diagram for libdap::BaseType:

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

Collaboration graph
[legend]

List of all members.

Public Types

typedef stack< BaseType * > btp_stack

Public Member Functions

virtual void add_var (BaseType *bt, Part part=nil)
 Add a variable.
 BaseType (const BaseType &copy_from)
 The BaseType copy constructor.
 BaseType (const string &n="", const Type &t=dods_null_c)
 The BaseType constructor.
virtual bool check_semantics (string &msg, bool all=false)
 Compare an object's current state with the semantics of its type.
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 BaseTypeget_parent ()
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_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.
string name () const
 Returns the name of the class instance.
BaseTypeoperator= (const BaseType &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_xml (ostream &out, string space=" ", bool constrained=false)
virtual void print_xml (FILE *out, string space=" ", bool constrained=false)
virtual BaseTypeptr_duplicate ()=0
virtual bool read (const string &dataset)
 Read data into a local buffer.
virtual bool read_p ()
 Has this variable been read?
virtual bool send_p ()
 Should this variable be sent?
virtual void set_attr_table (const AttrTable &at)
virtual void set_in_selection (bool state)
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_send_p (bool state)
virtual void set_synthesized_p (bool state)
void set_type (const Type &t)
 Sets the type of the class instance.
virtual bool synthesized_p ()
virtual string toString ()
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 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 ~BaseType ()
Abstract Methods


virtual unsigned int buf2val (void **val)=0
 Reads the class data.
virtual bool deserialize (UnMarshaller &um, DDS *dds, bool reuse=false)=0
 Receive data from the net.
virtual void intern_data (const string &dataset, ConstraintEvaluator &eval, DDS &dds)
virtual void print_val (ostream &out, string space="", bool print_decl_p=true)=0
 Prints the value of the variable.
virtual void print_val (FILE *out, string space="", bool print_decl_p=true)=0
 Prints the value of the variable.
virtual bool serialize (const string &dataset, ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)=0
 Move data to the net.
virtual unsigned int val2buf (void *val, bool reuse=false)=0
 Loads class data.
virtual unsigned int width ()=0
 Returns the size of the class instance data.

Protected Member Functions

void _duplicate (const BaseType &bt)
 Perform a deep copy.


Detailed Description

This defines the basic data type features for the DODS data access protocol (DAP) data types. All the DAP type classes (Float64, Array, etc.) subclass it. This class is an abstract one; no variables will ever be stored as BaseType instances, only as instances of its child classes.

These classes and their methods give a user the capacity to set up sophisticated data types. They do not provide sophisticated ways to access and use this data. On the server side, in many cases, the class instances will have no data in them at all until the serialize function is called to send data to the client. On the client side, most DODS application programs will unpack the data promptly into whatever local data structure the programmer deems the most useful.

In order to use these classes on the server side of a DODS client/server connection, you must write a read method for each of the data types you expect to encounter in the application. This function, whose purpose is to read data from a local source into the class instance data buffer, is called in serialize, when the data is about to be sent to the client. The read function may be called earlier, in the case of data subset requests (constraint expressions) whose evaluation requires it. (For example, the constraint expression ``a,b&b>c'' requires that c be read even though it will not be sent.)

For some data types, the read function must be aware of the constraints to be returned. These cautions are outlined where they occur.

Todo:
We really need a better way to get values out of these types, esp. the Float32, Int16, ..., types. In most cases we know the type, so a type specific method (one that requires a downcast to use) is OK. For example, Byte might have a method dods_byte Byte::value(). Sure you have to downcast from BaseType to Byte in order to use it, but you have to figure out you have a Byte to use Byte::buf2val() anyway, so what's the big deal? Having a method that returns the value would simplify code that reads from data sets to extract meta data (like lat/lon corner points, et c.).

Definition at line 188 of file BaseType.h.


Member Typedef Documentation

Definition at line 211 of file BaseType.h.


Constructor & Destructor Documentation

libdap::BaseType::BaseType ( const string &  n = "",
const Type t = dods_null_c 
)

The BaseType constructor needs a name and a type. The BaseType class exists to provide data to type classes that inherit from it. The constructors of those classes call the BaseType constructor; it is never called directly.

Parameters:
n A string containing the name of the new variable.
t The type of the variable. data in this variable to a client DODS process.
See also:
Type

Definition at line 93 of file BaseType.cc.

libdap::BaseType::BaseType ( const BaseType copy_from  ) 

Definition at line 99 of file BaseType.cc.

References _duplicate().

Here is the call graph for this function:

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

Definition at line 104 of file BaseType.cc.

References DBG.


Member Function Documentation

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

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 _name, _read_p, _send_p, _synthesized_p, _type, d_attr, d_in_selection, and d_parent.

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

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

Adds a variable to an instance of a constructor class, such as Array, Structure et cetera. This function is only used by those classes. For constructors with more than one variable, the variables appear in the same order in which they were added (i.e., the order in which add_var() was called). Since this method is only for use by Vectors and Constructors, the BaseType implementation throws InternalErr.

Note:
For the implementation of this method in Structure, Sequence, et c., first copy bt and then insert the copy. If bt is itself a constructor type you must either use the var() method to get a pointer to the actual instance added to *this or you must first add all of bt's children to it before adding it to *this. The implementations should use _duplicate() to perform a deep copy of bt.
Todo:
We should get rid of the Part parameter and adopt the convention that the first variable is the Array and all subsequent ones are Maps (when dealing with a Grid, the only time Part matters). This would enable several methods to migrate from Structure, Sequence and Grid to Constructor.
Parameters:
bt The variable to be added to this instance. The caller of this method must free memory it allocates for v. This method will make a deep copy of the object pointed to by v.
part The part of the constructor data to be modified. Only meaningful for Grid variables.
See also:
Part

Reimplemented in libdap::Array, libdap::Grid, libdap::Sequence, libdap::Structure, and libdap::Vector.

Definition at line 614 of file BaseType.cc.

Referenced by libdap::DDXParser::ddx_end_element().

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

Reads the class data into the memory referenced by val. The caller should either allocate enough storage to val to hold the class data or set *val to null. If *val is NULL, memory will be allocated by this function with new(). If the memory is allocated this way, the caller is responsible for deallocating that memory. Array and values for simple types are stored as C would store an array.

Deprecated:
Use value() in the leaf classes.
Parameters:
val A pointer to a pointer to the memory into which the class data will be copied. If the value pointed to is NULL, memory will be allocated to hold the data, and the pointer value modified accordingly. The calling program is responsible for deallocating the memory references by this pointer.
Returns:
The size (in bytes) of the information copied to val.

Implemented in libdap::Byte, libdap::Float32, libdap::Float64, libdap::Grid, libdap::Int16, libdap::Int32, libdap::Sequence, libdap::Str, libdap::Structure, libdap::UInt16, libdap::UInt32, and libdap::Vector.

bool libdap::BaseType::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 in libdap::Array, libdap::Grid, libdap::Sequence, libdap::Structure, and libdap::Vector.

Definition at line 932 of file BaseType.cc.

References libdap::dods_null_c.

Referenced by libdap::Vector::check_semantics(), libdap::Structure::check_semantics(), libdap::Sequence::check_semantics(), libdap::Grid::check_semantics(), and libdap::Array::check_semantics().

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

Receives data from the network connection identified by the source parameter. The data is put into the class data buffer according to the input dds.

This function is only used on the client side of the DODS client/server connection.

Parameters:
um An UnMarshaller that knows how to deserialize data types
dds The Data Descriptor Structure object corresponding to this dataset. See The DODS User Manual for information about this structure. This would have been received from the server in an earlier transmission.
reuse A boolean value, indicating whether the class internal data storage can be reused or not. If this argument is TRUE, the class buffer is assumed to be large enough to hold the incoming data, and it is not reallocated. If FALSE, new storage is allocated. If the internal buffer has not been allocated at all, this argument has no effect.
Returns:
Always returns TRUE.
Exceptions:
Error when a problem reading from the UnMarshaller is found.
See also:
DDS

Implemented in libdap::Byte, libdap::Float32, libdap::Float64, libdap::Grid, libdap::Int16, libdap::Int32, libdap::Sequence, libdap::Str, libdap::Structure, libdap::UInt16, libdap::UInt32, and libdap::Vector.

Referenced by libdap::Sequence::deserialize(), and libdap::Grid::deserialize().

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

int libdap::BaseType::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 in libdap::Grid, libdap::Sequence, libdap::Structure, and libdap::Vector.

Definition at line 357 of file BaseType.cc.

Referenced by libdap::Vector::element_count().

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

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(), print_xml(), and libdap::Array::print_xml_core().

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

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(), libdap::Sequence::intern_data_for_leaf(), libdap::Sequence::intern_data_parent_part_two(), libdap::Sequence::serialize_leaf(), and libdap::Sequence::serialize_parent_part_two().

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

Similar to using serialize() and deserialize() together in one object. Data are read as for serialize and those values are stored in the objects as deserialize() does but does not write and then read data to/from a stream.

This method is defined by the various data type classes. It calls the read() abstract method.

Parameters:
dataset The (local) name of dataset to be read.
eval Use this as the constraint expression evaluator.
dds The Data Descriptor Structure object corresponding to this dataset. See The DODS User Manual for information about this structure.

Reimplemented in libdap::Grid, libdap::Sequence, libdap::Structure, and libdap::Vector.

Definition at line 699 of file BaseType.cc.

References read(), read_p(), libdap::DDS::timeout_off(), and libdap::DDS::timeout_on().

Referenced by libdap::Grid::intern_data().

Here is the call graph for this function:

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

bool libdap::BaseType::is_in_selection (  )  [virtual]

Does this variable appear in either the selection part or as a function argument in the current constrain expression. If this property is set (true) then implementations of the read() method should read this variable.

Note:
This method does not check, nor does it know about the semantics of, string arguments passed to functions. Those functions might include variable names in strings; they are responsible for reading those variables. See the grid (func_grid_select()) for an example.
See also:
BaseType::read()

Definition at line 505 of file BaseType.cc.

bool libdap::BaseType::is_simple_type (  )  [virtual]

bool libdap::BaseType::is_vector_type (  )  [virtual]

string libdap::BaseType::name (  )  const

BaseType & libdap::BaseType::operator= ( const BaseType rhs  ) 

Definition at line 111 of file BaseType.cc.

References _duplicate().

Here is the call graph for this function:

bool libdap::BaseType::ops ( BaseType b,
int  op,
const string &  dataset 
) [virtual]

This method contains the relational operators used by the constraint expression evaluator in the DDS class. Each class that wants to be able to evaluate relational expressions must overload this function. The implementation in BaseType throws an InternalErr exception. The DAP library classes Byte, ..., Url provide specializations of this method. It is not meaningful for classes such as Array because relational expressions using Array are not supported.

The op argument refers to a table generated by bison from the constraint expression parser. Use statements like the following to correctly interpret its value:

    switch (op) {
        case EQUAL: return i1 == i2;
        case NOT_EQUAL: return i1 != i2;
        case GREATER: return i1 > i2;
        case GREATER_EQL: return i1 >= i2;
        case LESS: return i1 < i2;
        case LESS_EQL: return i1 <= i2;
        case REGEXP: throw Error("Regular expressions are not supported for integer values");
        default: throw Error("Unknown operator");
    }
    

This function is used by the constraint expression evaluator.

Parameters:
b Compare the value of this instance with b.
op An integer index indicating which relational operator is implied. Choose one from the following: EQUAL, NOT_EQUAL, GREATER, GREATER_EQL, LESS, LESS_EQL, and REGEXP.
dataset The name of the dataset from which the instance's data has come (or is to come).
Returns:
The boolean value of the comparison.

Reimplemented in libdap::Byte, libdap::Float32, libdap::Float64, libdap::Int16, libdap::Int32, libdap::Str, libdap::UInt16, and libdap::UInt32.

Definition at line 979 of file BaseType.cc.

Referenced by libdap::Clause::value().

void libdap::BaseType::print_decl ( ostream &  out,
string  space = "    ",
bool  print_semi = true,
bool  constraint_info = false,
bool  constrained = false 
) [virtual]

Write the variable's declaration in a C-style syntax. This function is used to create textual representation of the Data Descriptor Structure (DDS). See The DODS User Manual for information about this structure.

A simple array declaration might look like this:

    Float64 lat[lat = 180];
    
While a more complex declaration (for a Grid, in this case), would look like this:
    Grid {
    ARRAY:
    Int32 sst[time = 404][lat = 180][lon = 360];
    MAPS:
    Float64 time[time = 404];
    Float64 lat[lat = 180];
    Float64 lon[lon = 360];
    } sst;
    

Parameters:
out The output stream on which to print the declaration.
space Each line of the declaration will begin with the characters in this string. Usually used for leading spaces.
print_semi A boolean value indicating whether to print a semicolon at the end of the declaration.
constraint_info A boolean value indicating whether constraint information is to be printed with the declaration. If the value of this parameter is TRUE, print_decl() prints the value of the variable's send_p() flag after the declaration.
constrained If this boolean value is TRUE, the variable's declaration is only printed if is the send_p() flag is TRUE. If a constraint expression is in place, and this variable is not requested, the send_p() flag is FALSE.
See also:
DDS

DDS::CE

Reimplemented in libdap::Array, libdap::Constructor, and libdap::Grid.

Definition at line 817 of file BaseType.cc.

References libdap::id2www(), send_p(), and type_name().

Here is the call graph for this function:

void libdap::BaseType::print_decl ( FILE *  out,
string  space = "    ",
bool  print_semi = true,
bool  constraint_info = false,
bool  constrained = false 
) [virtual]

Write the variable's declaration in a C-style syntax. This function is used to create textual representation of the Data Descriptor Structure (DDS). See The DODS User Manual for information about this structure.

A simple array declaration might look like this:

    Float64 lat[lat = 180];
    
While a more complex declaration (for a Grid, in this case), would look like this:
    Grid {
    ARRAY:
    Int32 sst[time = 404][lat = 180][lon = 360];
    MAPS:
    Float64 time[time = 404];
    Float64 lat[lat = 180];
    Float64 lon[lon = 360];
    } sst;
    

Parameters:
out The output stream on which to print the declaration.
space Each line of the declaration will begin with the characters in this string. Usually used for leading spaces.
print_semi A boolean value indicating whether to print a semicolon at the end of the declaration.
constraint_info A boolean value indicating whether constraint information is to be printed with the declaration. If the value of this parameter is TRUE, print_decl() prints the value of the variable's send_p() flag after the declaration.
constrained If this boolean value is TRUE, the variable's declaration is only printed if is the send_p() flag is TRUE. If a constraint expression is in place, and this variable is not requested, the send_p() flag is FALSE.
See also:
DDS

DDS::CE

Reimplemented in libdap::Array, libdap::Constructor, and libdap::Grid.

Definition at line 752 of file BaseType.cc.

References libdap::id2www(), send_p(), and type_name().

Referenced by libdap::DODSFilter::functional_constraint(), libdap::Grid::print_decl(), libdap::Array::print_decl(), libdap::UInt32::print_val(), libdap::UInt16::print_val(), libdap::Str::print_val(), libdap::Int32::print_val(), libdap::Int16::print_val(), libdap::Float64::print_val(), libdap::Float32::print_val(), and libdap::Byte::print_val().

Here is the call graph for this function:

virtual void libdap::BaseType::print_val ( ostream &  out,
string  space = "",
bool  print_decl_p = true 
) [pure virtual]

Prints the value of the variable, with its declaration. This function is primarily intended for debugging DODS applications. However, it can be overloaded and used to do some useful things. Take a look at the asciival and writeval clients, both of which overload this to output the values of variables in different ways.

Parameters:
out The output ostream on which to print the value.
space This value is passed to the print_decl() function, and controls the leading spaces of the output.
print_decl_p A boolean value controlling whether the variable declaration is printed as well as the value.

Implemented in libdap::Array, libdap::Byte, libdap::Float32, libdap::Float64, libdap::Grid, libdap::Int16, libdap::Int32, libdap::Sequence, libdap::Str, libdap::Structure, libdap::UInt16, and libdap::UInt32.

virtual void libdap::BaseType::print_val ( FILE *  out,
string  space = "",
bool  print_decl_p = true 
) [pure virtual]

Prints the value of the variable, with its declaration. This function is primarily intended for debugging DODS applications. However, it can be overloaded and used to do some useful things. Take a look at the asciival and writeval clients, both of which overload this to output the values of variables in different ways.

Parameters:
out The output FILE on which to print the value.
space This value is passed to the print_decl() function, and controls the leading spaces of the output.
print_decl_p A boolean value controlling whether the variable declaration is printed as well as the value.

Implemented in libdap::Array, libdap::Byte, libdap::Float32, libdap::Float64, libdap::Grid, libdap::Int16, libdap::Int32, libdap::Sequence, libdap::Str, libdap::Structure, libdap::UInt16, and libdap::UInt32.

Referenced by libdap::Sequence::deserialize(), libdap::Sequence::print_one_row(), and libdap::Grid::print_val().

void libdap::BaseType::print_xml ( ostream &  out,
string  space = "    ",
bool  constrained = false 
) [virtual]

Write the XML representation of this variable. This method is used to build the DDX XML response.

Parameters:
out Destination output stream
space Use this to indent child declarations. Default is "".
constrained If true, only print this if it's part part of the current projection. Default is False.

Reimplemented in libdap::Array, libdap::Constructor, and libdap::Grid.

Definition at line 872 of file BaseType.cc.

References get_attr_table(), libdap::AttrTable::get_size(), libdap::id2xml(), libdap::AttrTable::print_xml(), send_p(), and type_name().

Here is the call graph for this function:

void libdap::BaseType::print_xml ( FILE *  out,
string  space = "    ",
bool  constrained = false 
) [virtual]

Write the XML representation of this variable. This method is used to build the DDX XML response.

Parameters:
out Destination.
space Use this to indent child declarations. Default is "".
constrained If true, only print this if it's part part of the current projection. Default is False.

Reimplemented in libdap::Array, libdap::Constructor, and libdap::Grid.

Definition at line 845 of file BaseType.cc.

References get_attr_table(), libdap::AttrTable::get_size(), libdap::id2xml(), libdap::AttrTable::print_xml(), send_p(), and type_name().

Referenced by libdap::Array::print_xml_core().

Here is the call graph for this function:

virtual BaseType* libdap::BaseType::ptr_duplicate (  )  [pure virtual]

Clone this instance. Allocate a new instance and copy *this into it. This method must perform a deep copy.

Note:
This method should not copy data values, but must copy all other fields in the object.
Returns:
A newly allocated copy of this.

Implemented in libdap::Array, libdap::Byte, libdap::Float32, libdap::Float64, libdap::Grid, libdap::Int16, libdap::Int32, libdap::Sequence, libdap::Str, libdap::Structure, libdap::UInt16, libdap::UInt32, libdap::Url, and libdap::Vector.

Referenced by libdap::Vector::_duplicate(), libdap::Vector::add_var(), libdap::Structure::add_var(), libdap::Sequence::add_var(), libdap::Grid::add_var(), libdap::DDS::add_var(), libdap::Vector::deserialize(), libdap::function_geoarray(),