40 #include "Constructor.h"
44 #include "XMLWriter.h"
45 #include "D4StreamMarshaller.h"
46 #include "D4StreamUnMarshaller.h"
49 #include "D4Attributes.h"
53 #include "InternalErr.h"
54 #include "DapIndent.h"
65 Constructor::m_duplicate(
const Constructor &c)
71 for (
auto var: c.d_vars) {
72 BaseType *btp = var->ptr_duplicate();
73 btp->set_parent(
this);
74 d_vars.push_back(btp);
86 for (Constructor::Vars_citer i = var_begin(), e = var_end(); i != e; ++i) {
98 dest->set_is_dap4(
true);
102 Constructor::FQN()
const
104 if (get_parent() == 0)
106 else if (get_parent()->type() == dods_group_c)
107 return get_parent()->FQN() + name();
108 else if (get_parent()->type() == dods_array_c)
109 return get_parent()->FQN();
111 return get_parent()->FQN() +
"." + name();
115 Constructor::element_count(
bool leaves)
118 return d_vars.size();
121 for (
auto var: d_vars) {
122 i += var->element_count(leaves);
129 Constructor::set_send_p(
bool state)
131 for (
auto var: d_vars) {
132 var->set_send_p(state);
135 BaseType::set_send_p(state);
150 Constructor::set_read_p(
bool state)
152 for (
auto var: d_vars) {
153 var->set_read_p(state);
156 BaseType::set_read_p(state);
167 Constructor::width(
bool constrained)
const
171 for (
auto var: d_vars) {
174 sz += var->width(constrained);
177 sz += var->width(constrained);
185 Constructor::var(
const string &name,
bool exact_match, btp_stack *s)
190 return m_exact_match(n, s);
192 return m_leaf_match(n, s);
197 Constructor::var(
const string &n, btp_stack &s)
203 BaseType *btp = m_exact_match(name, &s);
207 return m_leaf_match(name, &s);
212 Constructor::m_leaf_match(
const string &name, btp_stack *s)
214 for (
auto var: d_vars) {
215 if (var->name() == name) {
217 s->push(
static_cast<BaseType *
>(
this));
221 if (var->is_constructor_type()) {
222 BaseType *btp = var->
var(name,
false, s);
225 s->push(
static_cast<BaseType *
>(
this));
237 Constructor::m_exact_match(
const string &name, btp_stack *s)
240 for (
auto var: d_vars) {
241 if (var->name() == name) {
243 s->push(
static_cast<BaseType *
>(
this));
251 string::size_type dot_pos = name.find(
".");
252 if (dot_pos != string::npos) {
253 string aggregate = name.substr(0, dot_pos);
254 string field = name.substr(dot_pos + 1);
256 BaseType *agg_ptr = var(aggregate);
259 s->push(
static_cast<BaseType *
>(
this));
261 return agg_ptr->var(field,
true, s);
271 Constructor::Vars_iter
272 Constructor::var_begin()
274 return d_vars.begin();
279 Constructor::Vars_iter
280 Constructor::var_end()
286 Constructor::Vars_riter
287 Constructor::var_rbegin()
289 return d_vars.rbegin();
294 Constructor::Vars_riter
295 Constructor::var_rend()
297 return d_vars.rend();
303 Constructor::Vars_iter
304 Constructor::get_vars_iter(
int i)
306 return d_vars.begin() + i;
313 Constructor::get_var_index(
int i)
315 return *(d_vars.begin() + i);
328 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
337 d_vars.push_back(btp);
348 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
351 d_vars.push_back(bt);
362 Constructor::del_var(
const string &n)
364 auto to_remove = stable_partition(d_vars.begin(), d_vars.end(),
365 [n](
BaseType* btp){ return btp->name() != n; });
366 for_each(to_remove, d_vars.end(), [](
BaseType* btp){ delete btp; });
367 d_vars.erase(to_remove, d_vars.end());
376 Constructor::del_var(Vars_iter i)
393 bool Constructor::read()
396 for (
auto var: d_vars) {
401 BaseType::set_read_p(
true);
413 for (
auto var: d_vars) {
415 var->intern_data(eval, dds);
429 for (
auto var: d_vars) {
433 if (sm && sm->checksums() && var->type() != dods_structure_c && var->type() != dods_grid_c)
434 sm->reset_checksum();
436 var->serialize(eval, dds, m,
false);
438 if (sm && sm->checksums() && var->type() != dods_structure_c && var->type() != dods_grid_c)
443 var->serialize(eval, dds, m,
true);
454 for (
auto var: d_vars) {
455 var->deserialize(um, dds, reuse);
462 Constructor::compute_checksum(
Crc32 &)
464 throw InternalErr(__FILE__, __LINE__,
"Computing a checksum alone is not supported for Constructor types.");
468 Constructor::intern_data()
470 for (
auto var: d_vars) {
504 for (
auto var: d_vars) {
506 var->serialize(m, dmr, filter);
514 for (
auto var: d_vars) {
515 var->deserialize(um, dmr);
520 Constructor::print_decl(FILE *out,
string space,
bool print_semi,
521 bool constraint_info,
bool constrained)
524 print_decl(oss, space, print_semi, constraint_info, constrained);
525 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
529 Constructor::print_decl(ostream &out,
string space,
bool print_semi,
530 bool constraint_info,
bool constrained)
532 if (constrained && !send_p())
536 for (
auto var: d_vars) {
537 var->print_decl(out, space +
" ",
true, constraint_info, constrained);
539 out << space <<
"} " <<
id2www(name()) ;
541 if (constraint_info) {
543 out <<
": Send True";
545 out <<
": Send False";
553 Constructor::print_val(FILE *out,
string space,
bool print_decl_p)
556 print_val(oss, space, print_decl_p);
557 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
561 Constructor::print_val(ostream &out,
string space,
bool print_decl_p)
564 print_decl(out, space,
false);
569 for (Vars_citer i = d_vars.begin(), e = d_vars.end(); i != e; i++, (
void)(i != e && out <<
", ")) {
570 (*i)->print_val(out,
"",
false);
583 Constructor::print_xml(FILE *out,
string space,
bool constrained)
586 print_xml_writer(xml, constrained);
587 fwrite(xml.get_doc(),
sizeof(
char), xml.get_doc_size(), out);
594 Constructor::print_xml(ostream &out,
string space,
bool constrained)
597 print_xml_writer(xml, constrained);
598 out << xml.get_doc();
602 Constructor::print_xml_writer(
XMLWriter &xml,
bool constrained)
604 if (constrained && !send_p())
607 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
type_name().c_str()) < 0)
611 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)name().c_str()) < 0)
612 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
616 if (!is_dap4() && get_attr_table().get_size() > 0)
617 get_attr_table().print_xml_writer(xml);
620 for_each(d_vars.begin(), d_vars.end(),
621 [&xml, constrained](
BaseType *btp) { btp->print_xml_writer(xml, constrained); });
624 attributes()->print_dap4(xml);
626 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
631 Constructor::print_dap4(
XMLWriter &xml,
bool constrained)
633 if (constrained && !send_p())
636 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
type_name().c_str()) < 0)
640 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)name().c_str()) < 0)
641 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
644 for_each(d_vars.begin(), d_vars.end(),
645 [&xml, constrained](
BaseType *btp) { btp->print_dap4(xml, constrained); });
647 attributes()->print_dap4(xml);
649 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
654 Constructor::check_semantics(
string &msg,
bool all)
656 if (!BaseType::check_semantics(msg))
659 if (!unique_names(d_vars, name(),
type_name(), msg))
663 for (
auto var: d_vars) {
664 if (!var->check_semantics(msg,
true)) {
683 Constructor::is_linear()
694 Constructor::set_in_selection(
bool state)
696 for (
auto var: d_vars) {
697 var->set_in_selection(state);
700 BaseType::set_in_selection(state);
703 void Constructor::transfer_attributes(
AttrTable *at_container)
708 BaseType::transfer_attributes(at_container);
709 for (
auto var: d_vars) {
710 var->transfer_attributes(at);
716 Constructor::make_dropped_vars_attr_table(vector<BaseType *> *dropped_vars)
719 if (!dropped_vars->empty()) {
721 dv_table->
set_name(
"dap4:dropped_members");
723 vector<BaseType *>::iterator dvIter = dropped_vars->begin();
724 vector<BaseType *>::iterator dvEnd = dropped_vars->end();
726 for (; dvIter != dvEnd; dvIter++, i++) {
736 type_name = array->prototype()->type_name();
739 for (; d_iter < end; d_iter++) {
741 ostringstream dim_size;
742 dim_size << (*d_iter).size;
748 bt_attr_table->
append_attr(
"dap4:type",
"String", type_name);
767 Constructor::dump(ostream &strm)
const {
768 strm << DapIndent::LMarg <<
"Constructor::dump - (" << (
void *)
this <<
")" << endl;
770 BaseType::dump(strm);
771 strm << DapIndent::LMarg <<
"vars: " << endl;
774 for (
auto var: d_vars) {
778 DapIndent::UnIndent();
779 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.
The basic data type for the DODS DAP types.
virtual BaseType * ptr_duplicate()=0
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_parent(BaseType *parent)
virtual bool is_vector_type() const
Returns true if the instance is a vector (i.e., array) type variable.
virtual D4Attributes * attributes()
virtual void transform_to_dap4(D4Group *root, Constructor *container)
DAP2 to DAP4 transform.
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=nullptr)
Returns a pointer to a member of a constructor class.
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 ...
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 transform_to_dap4(AttrTable &at)
copy attributes from DAP2 to DAP4
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 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)