52 #include "Structure.h" 57 #include "ConstraintEvaluator.h" 59 #include "D4Attributes.h" 62 #include "XDRStreamMarshaller.h" 65 #include "InternalErr.h" 79 Structure::m_duplicate(
const Structure &s)
81 Constructor::m_duplicate(s);
85 DBG(cerr <<
"Copying structure: " <<
name() << endl);
87 for (Vars_iter i = cs.d_vars.begin(); i != cs.d_vars.end(); i++) {
88 DBG(cerr <<
"Copying field: " << (*i)->name() << endl);
94 BaseType *btp = (*i)->ptr_duplicate();
95 btp->set_parent(
this);
96 d_vars.push_back(btp);
128 DBG(cerr <<
"In Structure::copy_ctor for " <<
name() << endl);
132 Structure::~Structure()
169 Structure::operator=(
const Structure &rhs)
171 DBG(cerr <<
"Entering Structure::operator=" << endl);
179 DBG(cerr <<
"Exiting Structure::operator=" << endl);
188 return d_vars.size();
191 for (Vars_iter j = d_vars.begin(); j != d_vars.end(); j++) {
192 i += (*j)->element_count(leaves);
203 for (Vars_iter i = d_vars.begin(); linear && i != d_vars.end(); i++) {
204 if ((*i)->type() == dods_structure_c)
205 linear = linear && static_cast<Structure*>((*i))->
is_linear();
207 linear = linear && (*i)->is_simple_type();
217 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
218 (*i)->set_send_p(state);
227 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
228 (*i)->set_read_p(state);
243 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
244 (*i)->set_in_selection(state);
255 if ((*i)->type() == dods_sequence_c)
256 static_cast<Sequence&>(**i).set_leaf_sequence(++level);
257 else if ((*i)->type() == dods_structure_c)
258 static_cast<Structure&>(**i).set_leaf_sequence(level);
273 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
275 if (bt->is_dap4_only_type())
276 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 Structure.");
285 d_vars.push_back(btp);
296 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
298 if (bt->is_dap4_only_type())
299 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 Structure.");
301 bt->set_parent(
this);
302 d_vars.push_back(bt);
312 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
313 if ((*i)->name() == n) {
331 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
347 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
366 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
369 sz += (*i)->width(constrained);
372 sz += (*i)->width(constrained);
384 DBG(cerr <<
"Structure::intern_data: " <<
name() << endl);
388 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
389 if ((*i)->send_p()) {
390 (*i)->intern_data(eval, dds);
397 Marshaller &m,
bool ce_eval)
399 #if USE_LOCAL_TIMEOUT_SCHEME 406 if (ce_eval && !eval.eval_selection(dds,
dataset()))
409 #if USE_LOCAL_TIMEOUT_SCHEME 412 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
413 if ((*i)->send_p()) {
415 XDRStreamMarshaller *sm =
dynamic_cast<XDRStreamMarshaller*
>(&m);
416 if (sm && sm->checksums() && (*i)->type() != dods_structure_c && (*i)->type() != dods_grid_c)
417 sm->reset_checksum();
419 (*i)->serialize(eval, dds, m,
false);
421 if (sm && sm->checksums() && (*i)->type() != dods_structure_c && (*i)->type() != dods_grid_c)
424 (*i)->serialize(eval, dds, m,
false);
435 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
436 (*i)->deserialize(um, dds, reuse);
470 Structure::var(
const string &name,
bool exact_match, btp_stack *s)
475 return m_exact_match(n, s);
477 return m_leaf_match(n, s);
490 return m_leaf_match(
name, &s);
497 Structure::m_leaf_match(
const string &name, btp_stack *s)
499 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
500 if ((*i)->name() ==
name) {
502 DBG(cerr <<
"Pushing " << this->
name() << endl);
503 s->push(static_cast<BaseType *>(
this));
507 if ((*i)->is_constructor_type()) {
511 DBG(cerr <<
"Pushing " << this->
name() << endl);
512 s->push(static_cast<BaseType *>(
this));
526 Structure::m_exact_match(
const string &name, btp_stack *s)
529 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
530 if ((*i)->name() ==
name) {
532 s->push(static_cast<BaseType *>(
this));
540 string::size_type dot_pos =
name.find(
".");
541 if (dot_pos != string::npos) {
542 string aggregate =
name.substr(0, dot_pos);
543 string field =
name.substr(dot_pos + 1);
548 s->push(static_cast<BaseType *>(
this));
550 return agg_ptr->var(field,
true, s);
565 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
577 for (Vars_citer i = d_vars.begin(); i != d_vars.end();
578 i++, (void)(i != d_vars.end() && out <<
", ")) {
579 (*i)->print_val(out,
"",
false);
602 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
604 if (!(*i)->check_semantics(msg,
true)) {
627 strm << DapIndent::LMarg <<
"Structure::dump - (" 628 << (
void *)
this <<
")" << endl ;
629 DapIndent::Indent() ;
631 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.
virtual BaseType * ptr_duplicate()
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.
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
Structure(const string &n)
virtual BaseType * transform_to_dap4(D4Group *root, Constructor *container)
BaseType * transform_to_dap4(D4Group *root, Constructor *dest)
DAP2 to DAP4 transform.
virtual void add_var_nocopy(BaseType *bt, Part part=nil)
Holds a structure (aggregate) type.
virtual void add_var(BaseType *bt, Part part=nil)
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)
virtual void set_leaf_sequence(int level=1)
Traverse Structure, set Sequence leaf nodes.
A class for software fault reporting.
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 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 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 unsigned int val2buf(void *, bool)
Loads class data.
virtual void dump(ostream &strm) const
dumps information about this object
virtual BaseType * ptr_duplicate()=0
string www2id(const string &in, const string &escape, const string &except)
virtual unsigned int buf2val(void **)
Reads the class data.
The basic data type for the DODS DAP types.
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.
virtual bool is_linear()
Check to see whether this variable can be printed simply.
virtual void dump(ostream &strm) const
dumps information about this object
virtual void intern_data()
Read data into this variable.
virtual void del_var(const string &name)
virtual void set_send_p(bool state)
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.