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) {
74 btp->set_parent(
this);
75 d_vars.push_back(btp);
95 (*i)->transform_to_dap4(root , dest );
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) {
172 for (
auto var: d_vars) {
191 return m_exact_match(n, s);
193 return m_leaf_match(n, s);
208 return m_leaf_match(
name, &s);
213Constructor::m_leaf_match(
const string &name, btp_stack *s)
215 for (
auto var: d_vars) {
218 s->push(
static_cast<BaseType *
>(
this));
226 s->push(
static_cast<BaseType *
>(
this));
238Constructor::m_exact_match(
const string &name, btp_stack *s)
241 for (
auto var: d_vars) {
244 s->push(
static_cast<BaseType *
>(
this));
252 string::size_type dot_pos =
name.find(
".");
253 if (dot_pos != string::npos) {
254 string aggregate =
name.substr(0, dot_pos);
255 string field =
name.substr(dot_pos + 1);
260 s->push(
static_cast<BaseType *
>(
this));
262 return agg_ptr->var(field,
true, s);
272Constructor::Vars_iter
275 return d_vars.begin();
280Constructor::Vars_iter
287Constructor::Vars_riter
290 return d_vars.rbegin();
295Constructor::Vars_riter
298 return d_vars.rend();
304Constructor::Vars_iter
307 return d_vars.begin() + i;
316 return *(d_vars.begin() + i);
329 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
337 btp->set_parent(
this);
338 d_vars.push_back(btp);
349 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
351 bt->set_parent(
this);
352 d_vars.push_back(bt);
365 auto to_remove = stable_partition(d_vars.begin(), d_vars.end(),
366 [n](
BaseType* btp){ return btp->name() != n; });
367 for_each(to_remove, d_vars.end(), [](
BaseType* btp){ delete btp; });
368 d_vars.erase(to_remove, d_vars.end());
397 for (
auto var: d_vars) {
414 for (
auto var: d_vars) {
430 for (
auto var: d_vars) {
434 if (sm && sm->checksums() &&
var->
type() != dods_structure_c &&
var->
type() != dods_grid_c)
435 sm->reset_checksum();
439 if (sm && sm->checksums() &&
var->
type() != dods_structure_c &&
var->
type() != dods_grid_c)
455 for (
auto var: d_vars) {
465 throw InternalErr(__FILE__, __LINE__,
"Computing a checksum alone is not supported for Constructor types.");
471 for (
auto var: d_vars) {
505 for (
auto var: d_vars) {
515 for (
auto var: d_vars) {
522 bool constraint_info,
bool constrained)
525 print_decl(oss, space, print_semi, constraint_info, constrained);
526 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
531 bool constraint_info,
bool constrained)
533 if (constrained && !
send_p())
537 for (
auto var: d_vars) {
538 var->
print_decl(out, space +
" ",
true, constraint_info, constrained);
542 if (constraint_info) {
544 out <<
": Send True";
546 out <<
": Send False";
558 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
570 for (Vars_citer i = d_vars.begin(), e = d_vars.end(); i != e; i++, (void)(i != e && out <<
", ")) {
571 (*i)->print_val(out,
"",
false);
588 fwrite(xml.get_doc(),
sizeof(
char), xml.get_doc_size(), out);
599 out << xml.get_doc();
605 if (constrained && !
send_p())
608 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
type_name().c_str()) < 0)
612 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
613 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
621 for_each(d_vars.begin(), d_vars.end(),
622 [&xml, constrained](
BaseType *btp) { btp->print_xml_writer(xml, constrained); });
627 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
634 if (constrained && !
send_p())
637 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
type_name().c_str()) < 0)
641 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
642 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
645 for_each(d_vars.begin(), d_vars.end(),
646 [&xml, constrained](
BaseType *btp) { btp->print_dap4(xml, constrained); });
650 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
664 for (
auto var: d_vars) {
697 for (
auto var: d_vars) {
710 for (
auto var: d_vars) {
717Constructor::make_dropped_vars_attr_table(vector<BaseType *> *dropped_vars)
720 if (!dropped_vars->empty()) {
722 dv_table->
set_name(
"dap4:dropped_members");
724 vector<BaseType *>::iterator dvIter = dropped_vars->begin();
725 vector<BaseType *>::iterator dvEnd = dropped_vars->end();
727 for (; dvIter != dvEnd; dvIter++, i++) {
731 bt_attr_table->set_name(bt->name());
734 if (bt->is_vector_type()) {
737 type_name = array->prototype()->type_name();
740 for (; d_iter < end; d_iter++) {
742 ostringstream dim_size;
743 dim_size << (*d_iter).size;
744 bt_attr_table->append_attr(
"array_dimensions",
AttrType_to_String(Attr_uint32), dim_size.str());
749 bt_attr_table->append_attr(
"dap4:type",
"String",
type_name);
750 dv_table->append_container(bt_attr_table, bt_attr_table->get_name());
769 strm << DapIndent::LMarg <<
"Constructor::dump - (" << (
void *)
this <<
")" << endl;
772 strm << DapIndent::LMarg <<
"vars: " << endl;
775 for (
auto var: d_vars) {
779 DapIndent::UnIndent();
780 DapIndent::UnIndent();
A multidimensional array of identical data types.
std::vector< dimension >::iterator Dim_iter
Contains the attributes for a dataset.
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.
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 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 int element_count(bool leaves=false)
Count the members of constructor types.
void dump(ostream &strm) const override
dumps information about this object
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 bool send_p()
Should this variable be sent?
virtual void set_send_p(bool state)
virtual BaseType * ptr_duplicate()=0
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 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 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
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
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)