41#include "Constructor.h"
46#include "D4StreamMarshaller.h"
47#include "D4StreamUnMarshaller.h"
50#include "D4Attributes.h"
54#include "InternalErr.h"
66Constructor::m_duplicate(
const Constructor &c)
72 for (
auto var: c.d_vars) {
75 d_vars.push_back(btp);
99 dest->set_is_dap4(
true);
119 return d_vars.size();
122 for (
auto var: d_vars) {
132 for (
auto var: d_vars) {
153 for (
auto var: d_vars) {
173 for (
auto var: d_vars) {
196 for (
auto var: d_vars) {
199 sz +=
var->width_ll(constrained);
202 sz +=
var->width_ll(constrained);
215 return m_exact_match(n, s);
217 return m_leaf_match(n, s);
232 return m_leaf_match(
name, &s);
237Constructor::m_leaf_match(
const string &name, btp_stack *s)
239 for (
auto var: d_vars) {
242 s->push(
static_cast<BaseType *
>(
this));
250 s->push(
static_cast<BaseType *
>(
this));
262Constructor::m_exact_match(
const string &name, btp_stack *s)
265 for (
auto var: d_vars) {
268 s->push(
static_cast<BaseType *
>(
this));
276 string::size_type dot_pos =
name.find(
".");
277 if (dot_pos != string::npos) {
278 string aggregate =
name.substr(0, dot_pos);
279 string field =
name.substr(dot_pos + 1);
284 s->push(
static_cast<BaseType *
>(
this));
286 return agg_ptr->var(field,
true, s);
296Constructor::Vars_iter
299 return d_vars.begin();
304Constructor::Vars_iter
311Constructor::Vars_riter
314 return d_vars.rbegin();
319Constructor::Vars_riter
322 return d_vars.rend();
328Constructor::Vars_iter
331 return d_vars.begin() + i;
340 return *(d_vars.begin() + i);
355 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
357 if (i<0 || i>= (
int)(d_vars.size()))
358 throw InternalErr(__FILE__, __LINE__,
"The index must be within the variable vector range..");
380 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
398 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
401 d_vars.push_back(bt);
418 auto to_remove = stable_partition(d_vars.begin(), d_vars.end(),
419 [n](
BaseType* btp){ return btp->name() != n; });
420 for_each(to_remove, d_vars.end(), [](
BaseType* btp){ delete btp; });
421 d_vars.erase(to_remove, d_vars.end());
450 for (
auto var: d_vars) {
465 throw Error(
string(
"A method usable only with DAP2 variables was called on a DAP4 variable (").append(
name()).append(
")."), __FILE__, __LINE__);
470 for (
auto var: d_vars) {
486 for (
auto var: d_vars) {
490 if (sm && sm->checksums() &&
var->
type() != dods_structure_c &&
var->
type() != dods_grid_c)
491 sm->reset_checksum();
495 if (sm && sm->checksums() &&
var->
type() != dods_structure_c &&
var->
type() != dods_grid_c)
511 for (
auto var: d_vars) {
521 throw InternalErr(__FILE__, __LINE__,
"Computing a checksum alone is not supported for Constructor types.");
530 for (
auto var: d_vars) {
564 for (
auto var: d_vars) {
574 for (
auto var: d_vars) {
583 print_decl(oss, space, print_semi, constraint_info, constrained);
584 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
590 if (constrained && !
send_p())
594 for (
auto var: d_vars) {
595 var->
print_decl(out, space +
" ",
true, constraint_info, constrained);
599 if (constraint_info) {
601 out <<
": Send True";
603 out <<
": Send False";
615 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
627 for (Vars_citer i = d_vars.begin(), e = d_vars.end(); i != e; i++, (
void)(i != e && out <<
", ")) {
628 (*i)->print_val(out,
"",
false);
645 fwrite(xml.get_doc(),
sizeof(
char), xml.get_doc_size(), out);
656 out << xml.get_doc();
662 if (constrained && !
send_p())
665 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
type_name().c_str()) < 0)
669 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
670 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
678 for_each(d_vars.begin(), d_vars.end(),
679 [&xml, constrained](
BaseType *btp) { btp->print_xml_writer(xml, constrained); });
684 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
691 if (constrained && !
send_p())
694 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
type_name().c_str()) < 0)
698 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
699 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
702 for_each(d_vars.begin(), d_vars.end(),
703 [&xml, constrained](
BaseType *btp) { btp->print_dap4(xml, constrained); });
707 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
721 for (
auto var: d_vars) {
754 for (
auto var: d_vars) {
767 for (
auto var: d_vars) {
774Constructor::make_dropped_vars_attr_table(vector<BaseType *> *dropped_vars)
777 if (!dropped_vars->empty()) {
779 dv_table->
set_name(
"dap4:dropped_members");
781 vector<BaseType *>::iterator dvIter = dropped_vars->begin();
782 vector<BaseType *>::iterator dvEnd = dropped_vars->end();
784 for (; dvIter != dvEnd; dvIter++, i++) {
794 type_name = array->prototype()->type_name();
797 for (; d_iter < end; d_iter++) {
799 ostringstream dim_size;
800 dim_size << (*d_iter).size;
825 bool has_projected_dap4 =
false;
832 return has_projected_dap4;
846 strm << DapIndent::LMarg <<
"Constructor::dump - (" << (
void *)
this <<
")" << endl;
849 strm << DapIndent::LMarg <<
"vars: " << endl;
852 for (
auto var: d_vars) {
856 DapIndent::UnIndent();
857 DapIndent::UnIndent();
A multidimensional array of identical data types.
std::vector< dimension >::iterator Dim_iter
Contains the attributes for a dataset.
virtual AttrTable * append_container(const string &name)
Add a container to the attribute table.
virtual void set_name(const string &n)
Set the name of this attribute table.
virtual AttrTable * get_attr_table(const string &name)
Get an attribute container.
virtual unsigned int append_attr(const string &name, const string &type, const string &value)
Add an attribute to the table.
virtual string get_name() const
Get the name of this attribute table.
void print_xml_writer(XMLWriter &xml)
The basic data type for the DODS DAP types.
virtual bool is_dap4_projected(std::vector< string > &projected_dap4_inventory)
virtual string type_name() const
Returns the type of the class instance as a string.
virtual bool read()
Read data into a local buffer.
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
virtual AttrTable & get_attr_table()
virtual string name() const
Returns the name of the class instance.
virtual void set_in_selection(bool state)
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 BaseType * get_parent() const
virtual bool read_p()
Has this variable been read?
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....
virtual void set_read_p(bool state)
Sets the value of the read_p property.
virtual string dataset() const
Returns the name of the dataset used to create this instance.
virtual void set_parent(BaseType *parent)
virtual int element_count(bool leaves=false)
Count the members of constructor types.
void dump(ostream &strm) const override
dumps information about this object
virtual bool is_vector_type() const
Returns true if the instance is a vector (i.e., array) type variable.
virtual void intern_data(ConstraintEvaluator &eval, DDS &dds)
virtual bool is_constructor_type() const
Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable.
virtual D4Attributes * attributes()
virtual std::string FQN() const
virtual bool send_p()
Should this variable be sent?
virtual void set_send_p(bool state)
virtual BaseType * ptr_duplicate()=0
virtual void transform_to_dap4(D4Group *root, Constructor *container)
DAP2 to DAP4 transform.
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Move data to the net, then remove them from the object.
virtual void transfer_attributes(AttrTable *at)
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=nullptr)
Returns a pointer to a member of a constructor class.
virtual Type type() const
Returns the type of the class instance.
Evaluate a constraint expression.
bool eval_selection(DDS &dds, const std::string &dataset)
Evaluate a boolean-valued constraint expression. This is main method for the evaluator and is called ...
int element_count(bool leaves=false) override
Count the members of constructor types.
void compute_checksum(Crc32 &checksum) override
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
void transform_to_dap4(D4Group *root, Constructor *dest) override
DAP2 to DAP4 transform.
Vars_iter get_vars_iter(int i)
BaseType * var(const string &name, bool exact_match=true, btp_stack *s=nullptr) override
btp_stack no longer needed; use back pointers (BaseType::get_parent())
void set_var_index(BaseType *bt, int i)
Set the ith element of d_vars to a variable object.
void add_var(BaseType *bt, Part part=nil) override
void transfer_attributes(AttrTable *at) override
void print_xml_writer(XMLWriter &xml, bool constrained=false) override
void print_decl(ostream &out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false) override
Print an ASCII representation of the variable structure.
void print_xml(ostream &out, string space=" ", bool constrained=false) override
bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false) override
Receive data from the net.
void intern_data() override
Read data into this variable.
void set_read_p(bool state) override
Set the 'read_p' property for the Constructor and its members.
void print_val(FILE *out, string space="", bool print_decl_p=true) override
Prints the value of the variable.
void set_send_p(bool state) override
bool is_dap4_projected(std::vector< std::string > &inventory) override
bool read() override
Read the elements of Constructor marked for transmission.
void set_in_selection(bool state) override
Set the in_selection property.
bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true) override
Move data to the net, then remove them from the object.
void add_var_nocopy(BaseType *bt, Part part=nil) override
const vector< BaseType * > & variables() const
unsigned int width(bool constrained=false) const override
BaseType * get_var_index(int i)
bool check_semantics(string &msg, bool all=false) override
Compare an object's current state with the semantics of its type.
void print_dap4(XMLWriter &xml, bool constrained=false) override
std::string FQN() const override
virtual bool is_linear()
Check to see whether this variable can be printed simply.
virtual void del_var(const string &name)
Remove an element from a Constructor.
void dump(ostream &strm) const override
dumps information about this object
int64_t width_ll(bool constrained=false) const override
Get the width of the Constructor's fields.
void transform_to_dap4(AttrTable &at)
copy attributes from DAP2 to DAP4
bool has_dap4_types(const std::string &path, std::vector< std::string > &inventory) const
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
Read data from the stream made by D4StreamMarshaller.
A class for error processing.
A class for software fault reporting.
abstract base class used to marshal/serialize dap data objects
abstract base class used to unmarshall/deserialize dap data objects
Marshaller that knows how serialize dap data objects to a C++ iostream using XDR.
top level DAP object to house generic methods
string www2id(const string &in, const string &escape, const string &except)
string AttrType_to_String(const AttrType at)
Part
Names the parts of multi-section constructor data types.
string id2www(string in, const string &allowable)