BaseType.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>
// Dan Holloway <dan@hollywood.gso.uri.edu>
// Reza Nekovei <reza@intcomm.net>
//
// 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>
// dan Dan Holloway <dan@hollywood.gso.uri.edu>
// reza Reza Nekovei <reza@intcomm.net>
// Abstract base class for the variables in a dataset. This is used to store
// the type-invariant information that describes a variable as given in the
// DODS API.
//
// jhrg 9/6/94
#ifndef _basetype_h
#define _basetype_h 1
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include "AttrTable.h"
#include "D4AttributeType.h"
#include "D4Attributes.h"
#include "InternalErr.h"
#include "Type.h"
#include "dods-datatypes.h"
#include "DapObj.h"
using namespace std;
class Crc32;
namespace libdap {
class ConstraintEvaluator;
class DDS;
class Marshaller;
class UnMarshaller;
class Constructor;
class XMLWrter;
class DMR;
class D4Group;
class XMLWriter;
class D4StreamMarshaller;
class D4StreamUnMarshaller;
class D4Attributes;
class BaseType : public DapObj {
private:
string d_name; // name of the instance
Type d_type; // instance's type
string d_dataset; // name of the dataset used to create this BaseType
bool d_is_read; // true if the value has been read
bool d_is_send; // Is the variable in the projection?
// d_parent points to the Constructor or Vector which holds a particular
// variable. It is null for simple variables. The Vector and Constructor
// classes must maintain this variable.
BaseType *d_parent;
// Attributes for this variable. Added 05/20/03 jhrg
AttrTable d_attr;
D4Attributes *d_attributes;
bool d_is_dap4; // True if this is a DAP4 variable, false ... DAP2
// These are non-empty only for DAP4 variables. Added 9/27/12 jhrg
// These were/are used for DAP2 CEs, but not for DAP4 ones
bool d_in_selection; // Is the variable in the selection?
bool d_is_synthesized; // true if the variable is synthesized
protected:
void m_duplicate(const BaseType &bt);
public:
typedef stack<BaseType *> btp_stack;
// These ctors assume is_dap4 is false
BaseType(const string &n, const Type &t, bool is_dap4 = false);
BaseType(const string &n, const string &d, const Type &t, bool is_dap4 = false);
BaseType(const BaseType &copy_from);
~BaseType() override;
virtual string toString();
virtual void transform_to_dap4(D4Group *root, Constructor *container);
virtual std::vector<BaseType *> *transform_to_dap2(AttrTable *parent_attr_table);
void dump(ostream &strm) const override;
BaseType &operator=(const BaseType &rhs);
virtual void clear_local_data() { set_read_p(false); }
virtual bool is_dap4() const { return d_is_dap4; }
virtual void set_is_dap4(const bool v) { d_is_dap4 = v; }
virtual BaseType *ptr_duplicate() = 0;
virtual string name() const;
virtual void set_name(const string &n);
virtual std::string FQN() const;
virtual Type type() const;
virtual void set_type(const Type &t);
virtual string type_name() const;
virtual string dataset() const;
virtual int length() const { return 1; }
virtual int64_t length_ll() const { return 1; }
virtual void set_length(int64_t) { /* empty since the length of a BaseType is always one element. jhrg 8/12/22 */ }
virtual void set_length_ll(int64_t) { /* empty since the length of a BaseType is always one element. jhrg 8/12/22 */
}
virtual bool is_simple_type() const;
virtual bool is_vector_type() const;
virtual bool is_constructor_type() const;
virtual bool synthesized_p();
virtual void set_synthesized_p(bool state);
virtual int element_count(bool leaves = false);
virtual bool read_p();
virtual void set_read_p(bool state);
virtual bool send_p();
virtual void set_send_p(bool state);
virtual AttrTable &get_attr_table();
virtual void set_attr_table(const AttrTable &at);
// DAP4 attributes
virtual D4Attributes *attributes();
virtual void set_attributes(D4Attributes *);
virtual void set_attributes_nocopy(D4Attributes *);
virtual bool is_in_selection();
virtual void set_in_selection(bool state);
virtual void set_parent(BaseType *parent);
virtual BaseType *get_parent() const;
virtual BaseType *get_ancestor();
virtual void transfer_attributes(AttrTable *at);
// I put this comment here because the version in BaseType.cc does not
// include the exact_match or s variables since they are not used. Doxygen
// was gaging on the comment.
virtual BaseType *var(const string &name = "", bool exact_match = true, btp_stack *s = nullptr);
virtual BaseType *var(const string &name, btp_stack &s);
virtual void add_var(BaseType *bt, Part part = nil);
virtual void add_var_nocopy(BaseType *bt, Part part = nil);
virtual bool read();
virtual bool check_semantics(string &msg, bool all = false);
virtual bool ops(BaseType *b, int op);
virtual bool d4_ops(BaseType *b, int op);
virtual unsigned int width(bool constrained = false) const;
virtual int64_t width_ll(bool constrained = false) const;
virtual void print_decl(FILE *out, string space = " ", bool print_semi = true, bool constraint_info = false,
bool constrained = false);
virtual void print_xml(FILE *out, string space = " ", bool constrained = false);
virtual void print_decl(ostream &out, string space = " ", bool print_semi = true, bool constraint_info = false,
bool constrained = false);
virtual void print_xml(ostream &out, string space = " ", bool constrained = false);
virtual void print_xml_writer(XMLWriter &xml, bool constrained = false);
virtual void print_dap4(XMLWriter &xml, bool constrained = false);
virtual unsigned int buf2val(void **val) = 0;
virtual unsigned int val2buf(void *val, bool reuse = false) = 0;
virtual void intern_data(ConstraintEvaluator &eval, DDS &dds);
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval = true);
virtual void compute_checksum(Crc32 &checksum) = 0;
virtual void intern_data();
virtual void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter = false);
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse = false);
virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);
virtual void print_val(FILE *out, string space = "", bool print_decl_p = true);
virtual void print_val(ostream &out, string space = "", bool print_decl_p = true) = 0;
virtual bool is_dap4_projected(std::vector<string> &projected_dap4_inventory);
};
} // namespace libdap
#endif // _basetype_h
Crc32
Definition crc.h:45
libdap::AttrTable
Contains the attributes for a dataset.
Definition AttrTable.h:150
libdap::BaseType
The basic data type for the DODS DAP types.
Definition BaseType.h:118
libdap::BaseType::m_duplicate
void m_duplicate(const BaseType &bt)
Perform a deep copy.
Definition BaseType.cc:85
libdap::BaseType::is_dap4_projected
virtual bool is_dap4_projected(std::vector< string > &projected_dap4_inventory)
Definition BaseType.cc:1148
libdap::BaseType::print_xml_writer
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
Definition BaseType.cc:987
libdap::BaseType::type_name
virtual string type_name() const
Returns the type of the class instance as a string.
Definition BaseType.cc:335
libdap::BaseType::intern_data
virtual void intern_data()
Read data into this variable.
Definition BaseType.cc:805
libdap::BaseType::read
virtual bool read()
Read data into a local buffer.
Definition BaseType.cc:775
libdap::BaseType::deserialize
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
Definition BaseType.cc:814
libdap::BaseType::get_attr_table
virtual AttrTable & get_attr_table()
Definition BaseType.cc:498
libdap::BaseType::name
virtual string name() const
Returns the name of the class instance.
Definition BaseType.cc:296
libdap::BaseType::set_in_selection
virtual void set_in_selection(bool state)
Definition BaseType.cc:611
libdap::BaseType::print_decl
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.
Definition BaseType.cc:868
libdap::BaseType::get_parent
virtual BaseType * get_parent() const
Definition BaseType.cc:636
libdap::BaseType::read_p
virtual bool read_p()
Has this variable been read?
Definition BaseType.cc:410
libdap::BaseType::width
virtual unsigned int width(bool constrained=false) const
How many bytes does this variable use Return the number of bytes of storage this variable uses....
Definition BaseType.cc:1138
libdap::BaseType::set_read_p
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Definition BaseType.cc:442
libdap::BaseType::dataset
virtual string dataset() const
Returns the name of the dataset used to create this instance.
Definition BaseType.cc:326
libdap::BaseType::d4_ops
virtual bool d4_ops(BaseType *b, int op)
Evaluator a relop for DAP4.
Definition BaseType.cc:1125
libdap::BaseType::set_length_ll
virtual void set_length_ll(int64_t)
Set the number of elements in this variable This version of the function deprecates set_length() whic...
Definition BaseType.h:232
libdap::BaseType::set_attr_table
virtual void set_attr_table(const AttrTable &at)
Definition BaseType.cc:502
libdap::BaseType::set_synthesized_p
virtual void set_synthesized_p(bool state)
Definition BaseType.cc:397
libdap::BaseType::set_parent
virtual void set_parent(BaseType *parent)
Definition BaseType.cc:622
libdap::BaseType::element_count
virtual int element_count(bool leaves=false)
Count the members of constructor types.
Definition BaseType.cc:385
libdap::BaseType::dump
void dump(ostream &strm) const override
dumps information about this object
Definition BaseType.cc:269
libdap::BaseType::toString
virtual string toString()
Definition BaseType.cc:170
libdap::BaseType::is_vector_type
virtual bool is_vector_type() const
Returns true if the instance is a vector (i.e., array) type variable.
Definition BaseType.cc:352
libdap::BaseType::print_xml
virtual void print_xml(FILE *out, string space=" ", bool constrained=false)
Definition BaseType.cc:962
libdap::BaseType::set_name
virtual void set_name(const string &n)
Sets the name of the class instance.
Definition BaseType.cc:314
libdap::BaseType::is_constructor_type
virtual bool is_constructor_type() const
Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable.
Definition BaseType.cc:358
libdap::BaseType::print_val
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)=0
Prints the value of the variable.
libdap::BaseType::attributes
virtual D4Attributes * attributes()
Definition BaseType.cc:507
libdap::BaseType::FQN
virtual std::string FQN() const
Definition BaseType.cc:304
libdap::BaseType::send_p
virtual bool send_p()
Should this variable be sent?
Definition BaseType.cc:478
libdap::BaseType::set_length
virtual void set_length(int64_t)
Set the number of elements for this variable. use -1 to indicate nothing set.
Definition BaseType.h:224
libdap::BaseType::length
virtual int length() const
How many elements are in this variable? Uses -1 in places.
Definition BaseType.h:207
libdap::BaseType::clear_local_data
virtual void clear_local_data()
Definition BaseType.h:179
libdap::BaseType::is_simple_type
virtual bool is_simple_type() const
Returns true if the instance is a numeric, string or URL type variable.
Definition BaseType.cc:347
libdap::BaseType::set_send_p
virtual void set_send_p(bool state)
Definition BaseType.cc:488
libdap::BaseType::ptr_duplicate
virtual BaseType * ptr_duplicate()=0
libdap::BaseType::val2buf
virtual unsigned int val2buf(void *val, bool reuse=false)=0
Loads class data.
libdap::BaseType::length_ll
virtual int64_t length_ll() const
Get the number of elements in this variable This version of the function deprecates length() which is...
Definition BaseType.h:216
libdap::BaseType::buf2val
virtual unsigned int buf2val(void **val)=0
Reads the class data.
libdap::BaseType::compute_checksum
virtual void compute_checksum(Crc32 &checksum)=0
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
libdap::BaseType::transform_to_dap4
virtual void transform_to_dap4(D4Group *root, Constructor *container)
DAP2 to DAP4 transform.
Definition BaseType.cc:200
libdap::BaseType::serialize
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Move data to the net, then remove them from the object.
Definition BaseType.cc:810
libdap::BaseType::add_var
virtual void add_var(BaseType *bt, Part part=nil)
Add a variable.
Definition BaseType.cc:697
libdap::BaseType::transfer_attributes
virtual void transfer_attributes(AttrTable *at)
Definition BaseType.cc:544
libdap::BaseType::is_in_selection
virtual bool is_in_selection()
Is this variable part of the current selection?
Definition BaseType.cc:600
libdap::BaseType::synthesized_p
virtual bool synthesized_p()
Definition BaseType.cc:390
libdap::BaseType::check_semantics
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
Definition BaseType.cc:1056
libdap::BaseType::var
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=nullptr)
Returns a pointer to a member of a constructor class.
Definition BaseType.cc:646
libdap::BaseType::set_type
virtual void set_type(const Type &t)
Sets the type of the class instance.
Definition BaseType.cc:332
libdap::BaseType::type
virtual Type type() const
Returns the type of the class instance.
Definition BaseType.cc:329
libdap::BaseType::print_val
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition BaseType.cc:949
libdap::BaseType::print_dap4
virtual void print_dap4(XMLWriter &xml, bool constrained=false)
Definition BaseType.cc:1015
libdap::BaseType::transform_to_dap2
virtual std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table)
DAP4 to DAP2 transform.
Definition BaseType.cc:240
libdap::ConstraintEvaluator
Evaluate a constraint expression.
Definition ConstraintEvaluator.h:41
libdap::Constructor
Definition Constructor.h:42
libdap::D4Attributes
Definition D4Attributes.h:98
libdap::D4Group
Definition D4Group.h:44
libdap::D4StreamMarshaller
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
Definition D4StreamMarshaller.h:71
libdap::D4StreamUnMarshaller
Read data from the stream made by D4StreamMarshaller.
Definition D4StreamUnMarshaller.h:65
libdap::DDS
Definition DDS.h:176
libdap::DMR
Definition DMR.h:56
libdap::DapObj
libdap base object for common functionality of libdap objects
Definition DapObj.h:49
libdap::Marshaller
abstract base class used to marshal/serialize dap data objects
Definition Marshaller.h:50
libdap::UnMarshaller
abstract base class used to unmarshall/deserialize dap data objects
Definition UnMarshaller.h:53
libdap::XMLWriter
Definition XMLWriter.h:39
libdap
top level DAP object to house generic methods
Definition AlarmHandler.h:35
libdap::Type
Type
Identifies the data type.
Definition Type.h:94
libdap::Part
Part
Names the parts of multi-section constructor data types.
Definition Type.h:48