46 #include "Constructor.h" 50 #include "XMLWriter.h" 51 #include "D4StreamMarshaller.h" 52 #include "D4StreamUnMarshaller.h" 55 #include "D4Attributes.h" 60 #include "InternalErr.h" 61 #include "DapIndent.h" 73 Constructor::m_duplicate(
const Constructor &c)
75 DBG(cerr <<
"In Constructor::m_duplicate for " << c.name() << endl);
80 Vars_citer i = c.d_vars.begin();
81 while (i != c.d_vars.end()) {
82 BaseType *btp = (*i++)->ptr_duplicate();
83 btp->set_parent(
this);
84 d_vars.push_back(btp);
87 DBG(cerr <<
"Exiting Constructor::m_duplicate for " << c.name() << endl);
92 Constructor::Constructor(
const string &name,
const Type &type,
bool is_dap4)
93 : BaseType(name, type, is_dap4)
106 Constructor::Constructor(
const string &name,
const string &dataset,
const Type &type,
bool is_dap4)
107 :
BaseType(name, dataset, type, is_dap4)
112 DBG(cerr <<
"In Constructor::copy_ctor for " << rhs.
name() << endl);
116 Constructor::~Constructor()
118 Vars_iter i = d_vars.begin();
119 while (i != d_vars.end()) {
127 DBG(cerr <<
"Entering Constructor::operator=" << endl);
131 dynamic_cast<BaseType &
>(*this) = rhs;
135 DBG(cerr <<
"Exiting Constructor::operator=" << endl);
143 DBG(cerr << __func__ <<
"() - BEGIN (name:"<<
name() <<
145 ")(root:'"<< root->
name()<<
"':"<<(
void*)root <<
146 ")(dest:'"<< dest->
name()<<
"':"<< (
void *) dest<<
")" 163 DBG(cerr << __func__ <<
"() - Transforming variable: '" <<
164 (*i)->name() <<
"'" << endl; );
165 (*i)->transform_to_dap4(root , dest );
168 DBG(cerr << __func__ <<
"() - Skipping variable: " <<
169 d4_var->
type_name() <<
" " << d4_var->
name() <<
" because a variable with" <<
170 " this name already exists in the root group." << endl; );
174 dest->set_is_dap4(
true);
175 DBG(cerr << __func__ <<
"() - END (name:"<<
name() <<
")(type:"<<
type_name()<<
")" << endl;);
197 return d_vars.size();
200 for (Vars_iter j = d_vars.begin(); j != d_vars.end(); j++) {
201 i += (*j)->element_count(leaves);
210 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
211 (*i)->set_send_p(state);
220 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
221 (*i)->set_read_p(state);
234 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
253 for (Vars_citer i = d_vars.begin(); i != d_vars.end(); i++) {
256 sz += (*i)->width(constrained);
259 sz += (*i)->width(constrained);
272 return m_exact_match(n, s);
274 return m_leaf_match(n, s);
285 BaseType *btp = m_exact_match(name, &s);
289 return m_leaf_match(name, &s);
294 Constructor::m_leaf_match(
const string &
name, btp_stack *s)
296 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
297 if ((*i)->name() ==
name) {
299 DBG(cerr <<
"Pushing " << this->
name() << endl);
300 s->push(static_cast<BaseType *>(
this));
304 if ((*i)->is_constructor_type()) {
308 DBG(cerr <<
"Pushing " << this->
name() << endl);
309 s->push(static_cast<BaseType *>(
this));
321 Constructor::m_exact_match(
const string &name, btp_stack *s)
324 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
325 if ((*i)->name() ==
name) {
327 s->push(static_cast<BaseType *>(
this));
335 string::size_type dot_pos = name.find(
".");
336 if (dot_pos != string::npos) {
337 string aggregate = name.substr(0, dot_pos);
338 string field = name.substr(dot_pos + 1);
343 s->push(static_cast<BaseType *>(
this));
345 return agg_ptr->
var(field,
true, s);
355 Constructor::Vars_iter
358 return d_vars.begin() ;
363 Constructor::Vars_iter
366 return d_vars.end() ;
370 Constructor::Vars_riter
373 return d_vars.rbegin();
378 Constructor::Vars_riter
381 return d_vars.rend();
387 Constructor::Vars_iter
390 return d_vars.begin() + i;
399 return *(d_vars.begin() + i);
412 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
414 if (bt->is_dap4_only_type())
415 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 Structure.");
424 d_vars.push_back(btp);
435 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
437 if (bt->is_dap4_only_type())
438 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 Structure.");
441 d_vars.push_back(bt);
451 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
452 if ((*i)->name() == n) {
478 DBG(cerr <<
"Entering Constructor::read..." << endl);
480 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
492 DBG(cerr <<
"Constructor::intern_data: " <<
name() << endl);
496 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
497 if ((*i)->send_p()) {
498 (*i)->intern_data(eval, dds);
506 #if USE_LOCAL_TIMEOUT_SCHEME 514 #if USE_LOCAL_TIMEOUT_SCHEME 517 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
518 if ((*i)->send_p()) {
521 if (sm && sm->checksums() && (*i)->type() != dods_structure_c && (*i)->type() != dods_grid_c)
522 sm->reset_checksum();
524 (*i)->serialize(eval, dds, m,
false);
526 if (sm && sm->checksums() && (*i)->type() != dods_structure_c && (*i)->type() != dods_grid_c)
531 (*i)->serialize(eval, dds, m,
true);
542 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
543 (*i)->deserialize(um, dds, reuse);
552 throw InternalErr(__FILE__, __LINE__,
"Computing a checksum alone is not supported for Constructor types.");
558 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
559 if ((*i)->send_p()) {
597 if (filter && !eval.eval_selection(dmr,
dataset()))
601 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
602 if ((*i)->send_p()) {
603 (*i)->serialize(m, dmr, filter);
611 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
612 (*i)->deserialize(um, dmr);
618 bool constraint_info,
bool constrained)
621 print_decl(oss, space, print_semi, constraint_info, constrained);
622 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
627 bool constraint_info,
bool constrained)
629 if (constrained && !
send_p())
633 for (Vars_citer i = d_vars.begin(); i != d_vars.end(); i++) {
634 (*i)->print_decl(out, space +
" ",
true, constraint_info, constrained);
638 if (constraint_info) {
640 out <<
": Send True";
642 out <<
": Send False";
654 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
666 for (Vars_citer i = d_vars.begin(), e = d_vars.end(); i != e;
667 i++, (void)(i != e && out <<
", ")) {
669 DBG(cerr << (*i)->name() <<
" isa " << (*i)->type_name() << endl);
671 (*i)->print_val(out,
"",
false);
688 fwrite(xml.get_doc(),
sizeof(char), xml.get_doc_size(), out);
699 out << xml.get_doc();
702 class PrintFieldXMLWriter :
public unary_function<BaseType *, void>
707 PrintFieldXMLWriter(
XMLWriter &x,
bool c)
708 : d_xml(x), d_constrained(c)
720 if (constrained && !
send_p())
723 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
type_name().c_str()) < 0)
727 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
728 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
749 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
753 class PrintDAP4FieldXMLWriter :
public unary_function<BaseType *, void>
758 PrintDAP4FieldXMLWriter(
XMLWriter &x,
bool c) : d_xml(x), d_constrained(c) {}
770 if (constrained && !
send_p())
773 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
type_name().c_str()) < 0)
777 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
778 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
782 for_each(
var_begin(),
var_end(), PrintDAP4FieldXMLWriter(xml, constrained));
786 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
801 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
802 if (!(*i)->check_semantics(msg,
true)) {
836 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
837 (*i)->set_in_selection(state);
847 DBG(cerr <<
"Constructor::transfer_attributes() - processing " <<
name() <<
"' addr: "<< (
void*) at << endl);
850 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
859 Constructor::make_dropped_vars_attr_table(vector<BaseType *> *dropped_vars) {
860 DBG( cerr << __func__ <<
"() - BEGIN" << endl;);
863 if(!dropped_vars->empty()){
865 dv_table->
set_name(
"dap4:dropped_members");
866 vector<BaseType *>::iterator dvIter = dropped_vars->begin();
867 vector<BaseType *>::iterator dvEnd = dropped_vars->end();
869 for( ; dvIter!=dvEnd ; dvIter++, i++){
877 type_name = array->prototype()->
type_name();
878 DBG( cerr << __func__ <<
"() - The variable " << bt->
name() <<
" is an Array of '"<< type_name <<
"'" << endl;);
881 for( ; d_iter< end ; d_iter++){
883 ostringstream dim_size;
884 dim_size << (*d_iter).size;
892 bt_attr_table->
append_attr(
"dap4:type",
"String", type_name);
893 dv_table->append_container(bt_attr_table,bt_attr_table->
get_name());
898 DBG( cerr << __func__ <<
"() - END " << endl;);
915 strm << DapIndent::LMarg <<
"Constructor::dump - (" 916 << (
void *)
this <<
")" << endl ;
917 DapIndent::Indent() ;
919 strm << DapIndent::LMarg <<
"vars: " << endl ;
920 DapIndent::Indent() ;
921 Vars_citer i = d_vars.begin() ;
922 Vars_citer ie = d_vars.end() ;
923 for (; i != ie; i++) {
926 DapIndent::UnIndent() ;
927 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.
Contains the attributes for a dataset.
string AttrType_to_String(const AttrType at)
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
virtual string get_name() const
Get the name of this attribute table.
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...
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)
top level DAP object to house generic methods
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_vector_type() const
Returns true if the instance is a vector (i.e., array) type variable.
virtual void transform_to_dap4(D4Group *root, Constructor *dest)
DAP2 to DAP4 transform.
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 AttrTable * get_attr_table(const string &name)
Get an attribute container.
virtual Type type() const
Returns the type of the class instance.
std::vector< dimension >::iterator Dim_iter
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
virtual unsigned int append_attr(const string &name, const string &type, const string &value)
Add an attribute to the table.
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 transfer_attributes(AttrTable *at)
virtual void intern_data()
Read data into this variable.
virtual void set_name(const string &n)
Set the name of this attribute table.
void print_dap4(XMLWriter &xml, bool constrained=false)
virtual void transfer_attributes(AttrTable *at)
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. ...
A multidimensional array of identical data types.
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.