libdap
Updated for version 3.20.3
libdap4 is an implementation of OPeNDAP's DAP protocol.
|
52 #include "Structure.h"
57 #include "ConstraintEvaluator.h"
59 #include "D4Attributes.h"
62 #include "XDRStreamMarshaller.h"
65 #include "InternalErr.h"
67 #include "DapIndent.h"
80 Structure::m_duplicate(
const Structure &s)
82 Constructor::m_duplicate(s);
86 DBG(cerr <<
"Copying structure: " <<
name() << endl);
88 for (Vars_iter i = cs.d_vars.begin(); i != cs.d_vars.end(); i++) {
89 DBG(cerr <<
"Copying field: " << (*i)->name() << endl);
95 BaseType *btp = (*i)->ptr_duplicate();
96 btp->set_parent(
this);
97 d_vars.push_back(btp);
129 DBG(cerr <<
"In Structure::copy_ctor for " <<
name() << endl);
133 Structure::~Structure()
155 DBG(cerr << __func__ <<
"() - BEGIN" << endl;);
161 DBG(cerr << __func__ <<
"() - Calling Constructor::transform_to_dap4("<<
162 "'" << root->
name() <<
"':" << (
void*)root <<
","
163 "'" << dest->
name() <<
"':" << (
void*)dest <<
")"
167 DBG(cerr << __func__ <<
"() - Added new Structure '" << dest->name() <<
"' (" << (
void*)dest <<
168 ") to the container '" << container->
name() <<
"'" << endl;);
169 DBG(cerr << __func__ <<
"() - END"<< endl;);
182 DBG(cerr <<
" " << __func__ <<
" BEGIN" << endl);
187 dest->set_is_dap4(
false);
189 vector<BaseType *> dropped_vars;
191 vector<BaseType *> *new_vars = (*i)->transform_to_dap2(attrs);
194 vector<BaseType*>::iterator vIter = new_vars->begin();
195 vector<BaseType*>::iterator end = new_vars->end();
196 for( ; vIter!=end ; vIter++ ){
207 dropped_vars.push_back(*i);
211 AttrTable *dv_attr_table = make_dropped_vars_attr_table(&dropped_vars);
213 DBG(cerr <<
" " << __func__ <<
"() - Adding "<< dv_attr_table->
get_name() <<
" AttrTable" << endl);
216 DBG(attrs->
print(cerr,
"",
true););
221 vector<BaseType *> *result =
new vector<BaseType *>();
222 result->push_back(dest);
223 DBG(cerr <<
" " << __func__ <<
" END" << endl);
232 Structure::operator=(
const Structure &rhs)
234 DBG(cerr <<
"Entering Structure::operator=" << endl);
242 DBG(cerr <<
"Exiting Structure::operator=" << endl);
251 return d_vars.size();
254 for (Vars_iter j = d_vars.begin(); j != d_vars.end(); j++) {
255 i += (*j)->element_count(leaves);
266 for (Vars_iter i = d_vars.begin(); linear && i != d_vars.end(); i++) {
267 if ((*i)->type() == dods_structure_c)
270 linear = linear && (*i)->is_simple_type();
280 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
281 (*i)->set_send_p(state);
290 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
291 (*i)->set_read_p(state);
306 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
307 (*i)->set_in_selection(state);
318 if ((*i)->type() == dods_sequence_c)
320 else if ((*i)->type() == dods_structure_c)
336 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
338 if (bt->is_dap4_only_type())
339 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 Structure.");
348 d_vars.push_back(btp);
359 throw InternalErr(__FILE__, __LINE__,
"The BaseType parameter cannot be null.");
361 if (bt->is_dap4_only_type())
362 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 Structure.");
364 bt->set_parent(
this);
365 d_vars.push_back(bt);
375 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
376 if ((*i)->name() == n) {
394 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
410 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
429 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
432 sz += (*i)->width(constrained);
435 sz += (*i)->width(constrained);
447 DBG(cerr <<
"Structure::intern_data: " <<
name() << endl);
451 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
452 if ((*i)->send_p()) {
453 (*i)->intern_data(eval, dds);
460 Marshaller &m,
bool ce_eval)
462 #if USE_LOCAL_TIMEOUT_SCHEME
469 if (ce_eval && !eval.eval_selection(dds,
dataset()))
472 #if USE_LOCAL_TIMEOUT_SCHEME
475 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
476 if ((*i)->send_p()) {
478 XDRStreamMarshaller *sm =
dynamic_cast<XDRStreamMarshaller*
>(&m);
479 if (sm && sm->checksums() && (*i)->type() != dods_structure_c && (*i)->type() != dods_grid_c)
480 sm->reset_checksum();
482 (*i)->serialize(eval, dds, m,
false);
484 if (sm && sm->checksums() && (*i)->type() != dods_structure_c && (*i)->type() != dods_grid_c)
487 (*i)->serialize(eval, dds, m,
false);
498 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
499 (*i)->deserialize(um, dds, reuse);
533 Structure::var(
const string &name,
bool exact_match, btp_stack *s)
538 return m_exact_match(n, s);
540 return m_leaf_match(n, s);
553 return m_leaf_match(
name, &s);
560 Structure::m_leaf_match(
const string &name, btp_stack *s)
562 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
563 if ((*i)->name() ==
name) {
565 DBG(cerr <<
"Pushing " << this->
name() << endl);
566 s->push(
static_cast<BaseType *
>(
this));
570 if ((*i)->is_constructor_type()) {
574 DBG(cerr <<
"Pushing " << this->
name() << endl);
575 s->push(
static_cast<BaseType *
>(
this));
589 Structure::m_exact_match(
const string &name, btp_stack *s)
592 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
593 if ((*i)->name() ==
name) {
595 s->push(
static_cast<BaseType *
>(
this));
603 string::size_type dot_pos =
name.find(
".");
604 if (dot_pos != string::npos) {
605 string aggregate =
name.substr(0, dot_pos);
606 string field =
name.substr(dot_pos + 1);
611 s->push(
static_cast<BaseType *
>(
this));
613 return agg_ptr->var(field,
true, s);
628 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
640 for (Vars_citer i = d_vars.begin(); i != d_vars.end();
641 i++, (
void)(i != d_vars.end() && out <<
", ")) {
642 (*i)->print_val(out,
"",
false);
665 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
667 if (!(*i)->check_semantics(msg,
true)) {
690 strm << DapIndent::LMarg <<
"Structure::dump - ("
691 << (
void *)
this <<
")" << endl ;
692 DapIndent::Indent() ;
694 DapIndent::UnIndent() ;
virtual void set_attr_table(const AttrTable &at)
virtual BaseType * ptr_duplicate()=0
virtual void set_read_p(bool state)
Sets the value of the read_p property.
virtual unsigned int width(bool constrained=false) const
virtual vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table)
DAP4 to DAP2 transform.
virtual string name() const
Returns the name of the class instance.
virtual BaseType * ptr_duplicate()
virtual void add_var(BaseType *bt, Part part=nil)
virtual void del_var(const string &name)
virtual void transform_to_dap4(D4Group *root, Constructor *container)
A class for software fault reporting.
Part
Names the parts of multi-section constructor data types.
virtual int element_count(bool leaves=false)
Count the members of constructor types.
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
virtual void dump(ostream &strm) const
dumps information about this object
Structure(const string &n)
virtual D4Attributes * attributes()
virtual void set_leaf_sequence(int lvl=1)
Mark the Sequence which holds the leaf elements.
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
virtual void add_var_nocopy(BaseType *bt, Part part=nil)
AttrTable * get_AttrTable(const std::string name)
copy attributes from DAP4 to DAP2
virtual bool read()
simple implementation of read that iterates through vars and calls read on them
top level DAP object to house generic methods
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
virtual void dump(ostream &strm) const
dumps information about this object
virtual void set_parent(BaseType *parent)
virtual void intern_data()
Read data into this variable.
virtual string dataset() const
Returns the name of the dataset used to create this instance.
virtual void set_in_selection(bool state)
virtual void set_send_p(bool state)
virtual bool read_p()
Has this variable been read?
Contains the attributes for a dataset.
Holds a structure (aggregate) type.
virtual void set_leaf_sequence(int level=1)
Traverse Structure, set Sequence leaf nodes.
virtual void print(FILE *out, string pad=" ", bool dereference=false)
Prints the attribute table.
virtual void set_in_selection(bool state)
Set the in_selection property.
virtual void transform_to_dap4(D4Group *root, Constructor *dest)
DAP2 to DAP4 transform.
string www2id(const string &in, const string &escape, const string &except)
virtual void set_read_p(bool state)
Sets the value of the read_p property.
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 unsigned int buf2val(void **)
Reads the class data.
The basic data type for the DODS DAP types.
virtual AttrTable * append_container(const string &name)
Add a container to the attribute table.
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 void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.
virtual bool is_linear()
Check to see whether this variable can be printed simply.
virtual unsigned int val2buf(void *, bool)
Loads class data.
virtual string get_name() const
Get the name of this attribute table.
virtual string type_name() const
Returns the type of the class instance as a string.
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())
virtual void set_send_p(bool state)