41#include "Constructor.h"
45#include "D4StreamMarshaller.h"
46#include "D4StreamUnMarshaller.h"
50#include "D4Attributes.h"
53#include "InternalErr.h"
65void Constructor::m_duplicate(
const Constructor &c) {
70 for (
auto var : c.d_vars) {
72 btp->set_parent(
this);
73 d_vars.push_back(btp);
91 (*i)->transform_to_dap4(root , dest );
95 dest->set_is_dap4(
true);
111 return d_vars.size();
114 for (
auto var : d_vars) {
115 i +=
var->element_count(leaves);
122 for (
auto var : d_vars) {
123 var->set_send_p(state);
141 for (
auto var : d_vars) {
142 var->set_read_p(state);
159 for (
auto var : d_vars) {
162 sz +=
var->width(constrained);
164 sz +=
var->width(constrained);
179 for (
auto var : d_vars) {
182 sz +=
var->width_ll(constrained);
184 sz +=
var->width_ll(constrained);
195 return m_exact_match(n, s);
197 return m_leaf_match(n, s);
210 return m_leaf_match(
name, &s);
214BaseType *Constructor::m_leaf_match(
const string &name, btp_stack *s) {
215 for (
auto var : d_vars) {
218 s->push(
static_cast<BaseType *
>(
this));
222 if (
var->is_constructor_type()) {
226 s->push(
static_cast<BaseType *
>(
this));
237BaseType *Constructor::m_exact_match(
const string &name, btp_stack *s) {
239 for (
auto var : d_vars) {
242 s->push(
static_cast<BaseType *
>(
this));
250 string::size_type dot_pos =
name.find(
".");
251 if (dot_pos != string::npos) {
252 string aggregate =
name.substr(0, dot_pos);
253 string field =
name.substr(dot_pos + 1);
258 s->push(
static_cast<BaseType *
>(
this));
260 return agg_ptr->var(field,
true, s);
304 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
306 if (i < 0 || i >= (
int)(d_vars.size()))
307 throw InternalErr(__FILE__, __LINE__,
"The index must be within the variable vector range..");
326 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
342 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
345 d_vars.push_back(bt);
360 auto to_remove = stable_partition(d_vars.begin(), d_vars.end(), [n](
BaseType *btp) { return btp->name() != n; });
361 for_each(to_remove, d_vars.end(), [](
BaseType *btp) { delete btp; });
362 d_vars.erase(to_remove, d_vars.end());
388 for (
auto var : d_vars) {
401 throw Error(
string(
"A method usable only with DAP2 variables was called on a DAP4 variable (")
409 for (
auto var : d_vars) {
411 var->intern_data(eval, dds);
423 for (
auto var : d_vars) {
427 if (sm && sm->checksums() &&
var->type() != dods_structure_c &&
var->type() != dods_grid_c)
428 sm->reset_checksum();
430 var->serialize(eval, dds, m,
false);
432 if (sm && sm->checksums() &&
var->type() != dods_structure_c &&
var->type() != dods_grid_c)
437 var->serialize(eval, dds, m,
true);
446 for (
auto var : d_vars) {
447 var->deserialize(um, dds, reuse);
454 throw InternalErr(__FILE__, __LINE__,
"Computing a checksum alone is not supported for Constructor types.");
461 for (
auto var : d_vars) {
493 for (
auto var : d_vars) {
495 var->serialize(m, dmr, filter);
501 for (
auto var : d_vars) {
502 var->deserialize(um, dmr);
508 print_decl(oss, space, print_semi, constraint_info, constrained);
509 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
513 if (constrained && !
send_p())
517 for (
auto var : d_vars) {
518 var->print_decl(out, space +
" ",
true, constraint_info, constrained);
522 if (constraint_info) {
524 out <<
": Send True";
526 out <<
": Send False";
536 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
546 for (Vars_citer i = d_vars.begin(), e = d_vars.end(); i != e; i++, (
void)(i != e && out <<
", ")) {
547 (*i)->print_val(out,
"",
false);
562 fwrite(xml.get_doc(),
sizeof(
char), xml.get_doc_size(), out);
571 out << xml.get_doc();
575 if (constrained && !
send_p())
578 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar *)
type_name().c_str()) < 0)
582 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar *)
"name", (
const xmlChar *)
name().c_str()) < 0)
583 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
591 for_each(d_vars.begin(), d_vars.end(),
592 [&xml, constrained](
BaseType *btp) { btp->print_xml_writer(xml, constrained); });
597 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
602 if (constrained && !
send_p())
605 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar *)
type_name().c_str()) < 0)
609 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar *)
"name", (
const xmlChar *)
name().c_str()) < 0)
610 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
613 for_each(d_vars.begin(), d_vars.end(),
614 [&xml, constrained](
BaseType *btp) { btp->print_dap4(xml, constrained); });
618 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
630 for (
auto var : d_vars) {
631 if (!
var->check_semantics(msg,
true)) {
657 for (
auto var : d_vars) {
658 var->set_in_selection(state);
669 for (
auto var : d_vars) {
670 var->transfer_attributes(at);
675AttrTable *Constructor::make_dropped_vars_attr_table(vector<BaseType *> *dropped_vars) {
677 if (!dropped_vars->empty()) {
679 dv_table->
set_name(
"dap4:dropped_members");
684 for (; dvIter != dvEnd; dvIter++, i++) {
694 type_name = array->prototype()->type_name();
697 for (; d_iter < end; d_iter++) {
699 ostringstream dim_size;
700 dim_size << (*d_iter).size;
723 bool has_projected_dap4 =
false;
727 has_projected_dap4 |=
var->is_dap4_projected(inventory);
730 return has_projected_dap4;
742 strm << DapIndent::LMarg <<
"Constructor::dump - (" << (
void *)
this <<
")" << endl;
745 strm << DapIndent::LMarg <<
"vars: " << endl;
748 for (
auto var : d_vars) {
752 DapIndent::UnIndent();
753 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 string type_name() const
Returns the type of the class instance as a string.
virtual AttrTable & get_attr_table()
virtual string name() const
Returns the name of the class instance.
virtual void set_in_selection(bool state)
virtual BaseType * get_parent() const
virtual bool read_p()
Has this variable been read?
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)
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 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 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 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)