46 #include "Constructor.h" 50 #include "XMLWriter.h" 51 #include "D4StreamMarshaller.h" 52 #include "D4StreamUnMarshaller.h" 54 #include "D4Attributes.h" 60 #include "InternalErr.h" 69 Constructor::m_duplicate(
const Constructor &c)
71 DBG(cerr <<
"In Constructor::m_duplicate for " << c.name() << endl);
76 Vars_citer i = c.d_vars.begin();
77 while (i != c.d_vars.end()) {
78 BaseType *btp = (*i++)->ptr_duplicate();
79 btp->set_parent(
this);
80 d_vars.push_back(btp);
83 DBG(cerr <<
"Exiting Constructor::m_duplicate for " << c.name() << endl);
88 Constructor::Constructor(
const string &name,
const Type &type,
bool is_dap4)
89 : BaseType(name, type, is_dap4)
102 Constructor::Constructor(
const string &name,
const string &dataset,
const Type &type,
bool is_dap4)
103 :
BaseType(name, dataset, type, is_dap4)
108 DBG(cerr <<
"In Constructor::copy_ctor for " << rhs.
name() << endl);
112 Constructor::~Constructor()
114 Vars_iter i = d_vars.begin();
115 while (i != d_vars.end()) {
123 DBG(cerr <<
"Entering Constructor::operator=" << endl);
127 dynamic_cast<BaseType &
>(*this) = rhs;
131 DBG(cerr <<
"Exiting Constructor::operator=" << endl);
150 dest->set_is_dap4(
true);
172 return d_vars.size();
175 for (Vars_iter j = d_vars.begin(); j != d_vars.end(); j++) {
176 i += (*j)->element_count(leaves);
185 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
186 (*i)->set_send_p(state);
195 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
196 (*i)->set_read_p(state);
209 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
228 for (Vars_citer i = d_vars.begin(); i != d_vars.end(); i++) {
231 sz += (*i)->width(constrained);
234 sz += (*i)->width(constrained);
247 return m_exact_match(n, s);
249 return m_leaf_match(n, s);
260 BaseType *btp = m_exact_match(name, &s);
264 return m_leaf_match(name, &s);
269 Constructor::m_leaf_match(
const string &
name, btp_stack *s)
271 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
272 if ((*i)->name() ==
name) {
274 DBG(cerr <<
"Pushing " << this->
name() << endl);
275 s->push(static_cast<BaseType *>(
this));
279 if ((*i)->is_constructor_type()) {
283 DBG(cerr <<
"Pushing " << this->
name() << endl);
284 s->push(static_cast<BaseType *>(
this));
296 Constructor::m_exact_match(
const string &name, btp_stack *s)
299 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
300 if ((*i)->name() ==
name) {
302 s->push(static_cast<BaseType *>(
this));
310 string::size_type dot_pos = name.find(
".");
311 if (dot_pos != string::npos) {
312 string aggregate = name.substr(0, dot_pos);
313 string field = name.substr(dot_pos + 1);
318 s->push(static_cast<BaseType *>(
this));
320 return agg_ptr->
var(field,
true, s);
330 Constructor::Vars_iter
333 return d_vars.begin() ;
338 Constructor::Vars_iter
341 return d_vars.end() ;
345 Constructor::Vars_riter
348 return d_vars.rbegin();
353 Constructor::Vars_riter
356 return d_vars.rend();
362 Constructor::Vars_iter
365 return d_vars.begin() + i;
374 return *(d_vars.begin() + i);
387 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
389 if (bt->is_dap4_only_type())
390 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 Structure.");
399 d_vars.push_back(btp);
410 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
412 if (bt->is_dap4_only_type())
413 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 Structure.");
416 d_vars.push_back(bt);
426 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
427 if ((*i)->name() == n) {
453 DBG(cerr <<
"Entering Constructor::read..." << endl);
455 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
467 DBG(cerr <<
"Constructor::intern_data: " <<
name() << endl);
471 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
472 if ((*i)->send_p()) {
473 (*i)->intern_data(eval, dds);
481 #if USE_LOCAL_TIMEOUT_SCHEME 489 #if USE_LOCAL_TIMEOUT_SCHEME 492 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
493 if ((*i)->send_p()) {
496 if (sm && sm->checksums() && (*i)->type() != dods_structure_c && (*i)->type() != dods_grid_c)
497 sm->reset_checksum();
499 (*i)->serialize(eval, dds, m,
false);
501 if (sm && sm->checksums() && (*i)->type() != dods_structure_c && (*i)->type() != dods_grid_c)
506 (*i)->serialize(eval, dds, m,
true);
517 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
518 (*i)->deserialize(um, dds, reuse);
527 throw InternalErr(__FILE__, __LINE__,
"Computing a checksum alone is not supported for Constructor types.");
533 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
534 if ((*i)->send_p()) {
572 if (filter && !eval.eval_selection(dmr,
dataset()))
576 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
577 if ((*i)->send_p()) {
578 (*i)->serialize(m, dmr, filter);
586 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
587 (*i)->deserialize(um, dmr);
593 bool constraint_info,
bool constrained)
596 print_decl(oss, space, print_semi, constraint_info, constrained);
597 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
602 bool constraint_info,
bool constrained)
604 if (constrained && !
send_p())
608 for (Vars_citer i = d_vars.begin(); i != d_vars.end(); i++) {
609 (*i)->print_decl(out, space +
" ",
true, constraint_info, constrained);
613 if (constraint_info) {
615 out <<
": Send True";
617 out <<
": Send False";
629 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
641 for (Vars_citer i = d_vars.begin(), e = d_vars.end(); i != e;
642 i++, (void)(i != e && out <<
", ")) {
644 DBG(cerr << (*i)->name() <<
" isa " << (*i)->type_name() << endl);
646 (*i)->print_val(out,
"",
false);
663 fwrite(xml.get_doc(),
sizeof(char), xml.get_doc_size(), out);
674 out << xml.get_doc();
677 class PrintFieldXMLWriter :
public unary_function<BaseType *, void>
682 PrintFieldXMLWriter(
XMLWriter &x,
bool c)
683 : d_xml(x), d_constrained(c)
695 if (constrained && !
send_p())
698 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
type_name().c_str()) < 0)
702 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
703 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
724 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
728 class PrintDAP4FieldXMLWriter :
public unary_function<BaseType *, void>
733 PrintDAP4FieldXMLWriter(
XMLWriter &x,
bool c) : d_xml(x), d_constrained(c) {}
745 if (constrained && !
send_p())
748 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
type_name().c_str()) < 0)
752 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
753 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
757 for_each(
var_begin(),
var_end(), PrintDAP4FieldXMLWriter(xml, constrained));
761 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
776 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
777 if (!(*i)->check_semantics(msg,
true)) {
811 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
812 (*i)->set_in_selection(state);
829 strm << DapIndent::LMarg <<
"Constructor::dump - (" 830 << (
void *)
this <<
")" << endl ;
831 DapIndent::Indent() ;
833 strm << DapIndent::LMarg <<
"vars: " << endl ;
834 DapIndent::Indent() ;
835 Vars_citer i = d_vars.begin() ;
836 Vars_citer ie = d_vars.end() ;
837 for (; i != ie; i++) {
840 DapIndent::UnIndent() ;
841 DapIndent::UnIndent() ;
virtual unsigned int width(bool constrained=false) const
virtual bool read_p()
Has this variable been read?
virtual string name() const
Returns the name of the class instance.
virtual void set_in_selection(bool state)
Set the in_selection property.
abstract base class used to unmarshall/deserialize dap data objects
virtual void print_dap4(XMLWriter &xml, bool constrained=false)
virtual void dump(ostream &strm) const
dumps information about this object
virtual std::string FQN() const
virtual BaseType * var(const string &name, bool exact_match=true, btp_stack *s=0)
btp_stack no longer needed; use back pointers (BaseType::get_parent())
Part
Names the parts of multi-section constructor data types.
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
Read data from the stream made by D4StreamMarshaller.
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
virtual void compute_checksum(Crc32 &checksum)
include the data for this variable in the checksum DAP4 includes a checksum with every data response...
BaseType * transform_to_dap4(D4Group *root, Constructor *dest)
DAP2 to DAP4 transform.
void print_xml_writer(XMLWriter &xml)
virtual void add_var_nocopy(BaseType *bt, Part part=nil)
virtual void add_var(BaseType *bt, Part part=nil)
Type
Identifies the data type.
virtual void set_in_selection(bool state)
virtual int element_count(bool leaves=false)
Count the members of constructor types.
virtual void set_parent(BaseType *parent)
A class for software fault reporting.
virtual std::string FQN() const
virtual void print_xml(ostream &out, string space=" ", bool constrained=false)
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
Returns a pointer to a member of a constructor class.
virtual bool is_linear()
Check to see whether this variable can be printed simply.
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
virtual void set_send_p(bool state)
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 Type type() const
Returns the type of the class instance.
BaseType * get_var_index(int i)
virtual bool read()
simple implementation of read that iterates through vars and calls read on them
virtual void set_read_p(bool state)
Sets the value of the read_p property.
virtual D4Attributes * attributes()
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.
virtual void dump(ostream &strm) const
dumps information about this object
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
virtual BaseType * ptr_duplicate()=0
string www2id(const string &in, const string &escape, const string &except)
Evaluate a constraint expression.
virtual AttrTable & get_attr_table()
virtual BaseType * get_parent() const
The basic data type for the DODS DAP types.
abstract base class used to marshal/serialize dap data objects
virtual void print_decl(ostream &out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false)
Print an ASCII representation of the variable structure.
virtual string type_name() const
Returns the type of the class instance as a string.
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 ...
Vars_iter get_vars_iter(int i)
virtual void intern_data()
Read data into this variable.
void print_dap4(XMLWriter &xml, bool constrained=false)
virtual void del_var(const string &name)
virtual void set_send_p(bool state)
void transform_to_dap4(AttrTable &at)
copy attributes from DAP2 to DAP4
Marshaller that knows how serialize dap data objects to a C++ iostream using XDR. ...
virtual bool send_p()
Should this variable be sent?
string id2www(string in, const string &allowable)
virtual string dataset() const
Returns the name of the dataset used to create this instance.
virtual void set_read_p(bool state)
Sets the value of the read_p property.
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
virtual BaseType * transform_to_dap4(D4Group *root, Constructor *container)
DAP2 to DAP4 transform.