40 #include "XMLWriter.h" 41 #include "D4Attributes.h" 42 #include "D4Dimensions.h" 46 #include "D4StreamMarshaller.h" 47 #include "D4StreamUnMarshaller.h" 56 #undef INCLUDE_SOURCE_BYTE_ORDER 60 void D4Group::m_duplicate(
const D4Group &g)
62 DBG(cerr <<
"In D4Group::m_duplicate for " << g.name() << endl);
66 d_dims =
new D4Dimensions(*(g.d_dims));
67 d_dims->set_parent(
this);
75 Vars_citer vi = d_vars.begin();
76 while (vi != d_vars.end()) {
77 if ((*vi)->type() == dods_array_c)
78 static_cast<Array*>(*vi)->update_dimension_pointers(g.d_dims, d_dims);
85 Vars_citer vi = d_vars.begin();
86 while (vi != d_vars.end()) {
87 if ((*vi)->type() == dods_array_c)
88 static_cast<Array*>(*vi)->update_dimension_pointers(g.d_dims, d_dims);
94 if (g.d_enum_defs) d_enum_defs =
new D4EnumDefs(*g.d_enum_defs);
97 groupsCIter i = g.d_groups.begin();
98 while(i != g.d_groups.end()) {
104 DBG(cerr <<
"Exiting D4Group::m_duplicate" << endl);
118 :
Constructor(name, dods_group_c, true), d_dims(0), d_enum_defs(0)
132 :
Constructor(name, dataset, dods_group_c, true), d_dims(0), d_enum_defs(0)
138 DBG(cerr <<
"In D4Group::copy_ctor for " << rhs.
name() << endl);
147 groupsIter i = d_groups.begin();
148 while(i != d_groups.end())
164 D4Group::operator=(
const D4Group &rhs)
192 name_eq(
D4Group *g,
const string name)
194 return g->
name() == name;
198 D4Group::find_child_grp(
const string &grp_name)
200 groupsIter g = find_if(
grp_begin(),
grp_end(), bind2nd(ptr_fun(name_eq), grp_name));
201 return (g ==
grp_end()) ? 0: *g;
206 D4Group::find_first_var_that_uses_dimension(D4Dimension *dim)
219 if ((*i)->send_p() && (*i)->type() == dods_array_c) {
220 Array *a =
static_cast<Array*
>(*i);
221 for (
Array::Dim_iter di = a->dim_begin(), de = a->dim_end(); di != de; ++di) {
222 if (a->dimension_D4dim(di) == dim)
229 BaseType *btp = (*i)->find_first_var_that_uses_dimension(dim);
237 D4Group::find_first_var_that_uses_enumeration(D4EnumDef *enum_def)
250 if ((*i)->send_p() && (*i)->type() == dods_enum_c) {
251 D4Enum *e =
static_cast<D4Enum*
>(*i);
252 if (e->enumeration() == enum_def)
258 BaseType *btp = (*i)->find_first_var_that_uses_enumeration(enum_def);
280 if (lpath[0] ==
'/') {
282 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
284 lpath = lpath.substr(1);
287 string::size_type pos = lpath.find(
'/');
288 if (pos == string::npos) {
290 return dims()->find_dim(lpath);
294 string grp_name = lpath.substr(0, pos);
295 lpath = lpath.substr(pos + 1);
297 D4Group *grp = find_child_grp(grp_name);
298 return (grp == 0) ? 0: grp->
find_dim(lpath);
302 D4Group::find_map_source(
const string &path)
304 BaseType *map_source = m_find_map_source_helper(path);
307 if (map_source && map_source->
type() == dods_array_c)
return static_cast<Array*>(map_source);
313 D4Group::m_find_map_source_helper(
const string &path)
318 if (lpath[0] ==
'/') {
320 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
322 lpath = lpath.substr(1);
325 string::size_type pos = lpath.find(
'/');
326 if (pos == string::npos) {
332 string grp_name = lpath.substr(0, pos);
333 lpath = lpath.substr(pos + 1);
335 D4Group *grp = find_child_grp(grp_name);
336 return (grp == 0) ? 0: grp->var(lpath);
340 D4Group::find_enum_def(
const string &path)
345 if (lpath[0] ==
'/') {
347 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
349 lpath = lpath.substr(1);
352 string::size_type pos = lpath.find(
'/');
353 if (pos == string::npos) {
355 return enum_defs()->find_enum_def(lpath);
359 string grp_name = lpath.substr(0, pos);
360 lpath = lpath.substr(pos + 1);
362 D4Group *grp = find_child_grp(grp_name);
363 return (grp == 0) ? 0: grp->enum_defs()->find_enum_def(lpath);
379 if (lpath[0] ==
'/') {
381 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
383 lpath = lpath.substr(1);
386 string::size_type pos = lpath.find(
'/');
387 if (pos == string::npos) {
393 string grp_name = lpath.substr(0, pos);
394 lpath = lpath.substr(pos + 1);
396 D4Group *grp = find_child_grp(grp_name);
397 return (grp == 0) ? 0 : grp->
find_var(lpath);
415 size += (*v)->width(constrained);
418 size += (*v)->width(constrained);
425 groupsIter g = d_groups.begin();
426 while (g != d_groups.end())
427 size += (*g++)->request_size(constrained);
435 groupsIter g = d_groups.begin();
436 while (g != d_groups.end())
437 (*g++)->set_read_p(state);
445 groupsIter g = d_groups.begin();
446 while (g != d_groups.end())
447 (*g++)->set_send_p(state);
455 groupsIter g = d_groups.begin();
456 while (g != d_groups.end())
457 (*g++)->intern_data();
466 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
468 if ((*i)->send_p()) {
477 oss.setf(ios::hex, ios::basefield);
478 oss << setfill(
'0') << setw(8) << checksum.GetCrc32();
479 a->add_value(oss.str());
480 #if INCLUDE_SOURCE_BYTE_ORDER 481 if (um.is_source_big_endian())
482 a->add_value(
"source:big-endian");
484 a->add_value(
"source:little-endian");
486 (*i)->attributes()->add_attribute_nocopy(a);
487 DBG(cerr <<
"CRC32: " << oss.str() <<
" for " << (*i)->name() << endl);
519 groupsIter g = d_groups.begin();
520 while (g != d_groups.end())
521 (*g++)->serialize(m, dmr, filter);
530 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
532 if ((*i)->send_p()) {
535 DBG(cerr <<
"Serializing variable " << (*i)->type_name() <<
" " << (*i)->name() << endl);
536 (*i)->serialize(m, dmr, filter);
538 DBG(cerr <<
"Wrote CRC32: " << m.
get_checksum() <<
" for " << (*i)->name() << endl);
546 groupsIter g = d_groups.begin();
547 while (g != d_groups.end()) {
548 DBG(cerr <<
"Deserializing group " << (*g)->name() << endl);
553 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
554 DBG(cerr <<
"Deserializing variable " << (*i)->type_name() <<
" " << (*i)->name() << endl);
555 (*i)->deserialize(um, dmr);
558 string crc = um.get_checksum_str();
560 #if INCLUDE_SOURCE_BYTE_ORDER 562 a->add_value(
"source:big-endian");
564 a->add_value(
"source:little-endian");
566 DBG(cerr <<
"Read CRC32: " << crc <<
" for " << (*i)->name() << endl);
567 (*i)->attributes()->add_attribute_nocopy(a);
574 if (!
name().empty() &&
name() !=
"/") {
578 if (constrained && !
send_p())
581 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
type_name().c_str()) < 0)
584 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
585 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
589 if (!
dims()->empty())
590 dims()->print_dap4(xml, constrained);
594 enum_defs()->print_dap4(xml, constrained);
605 groupsIter g = d_groups.begin();
606 while (g != d_groups.end())
607 (*g++)->print_dap4(xml, constrained);
609 if (!
name().empty() &&
name() !=
"/") {
610 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
640 DBG( cerr << __func__ <<
"() - BEGIN ("<<
name() <<
" is_root: "<< (is_root?
"true":
"false") <<
")" << endl;);
641 vector<BaseType *> *results =
new vector<BaseType *>();
642 vector<BaseType *> dropped_vars;
651 DBG( cerr << __func__ <<
"() - Promoting group attributes to parent" << endl;);
653 for (AttrTable::Attr_iter i = group_attrs->
attr_begin(), e = group_attrs->
attr_end(); i != e; ++i) {
654 if ((*i)->type == Attr_container) {
668 group_attrs = parent_attr_table;
674 for (D4Group::Vars_citer varIter =
var_begin(), e =
var_end(); varIter != e; ++varIter) {
675 DBG( cerr << __func__ <<
"() - Processing member variable '" << (*varIter)->name() <<
676 "' root: " << (is_root?
"true":
"false") << endl;);
677 vector<BaseType *> *new_vars = (*varIter)->transform_to_dap2(group_attrs);
680 vector<BaseType*>::iterator vIter = new_vars->begin();
681 vector<BaseType*>::iterator end = new_vars->end();
682 for( ; vIter!=end ; vIter++ ){
685 string new_name = (is_root?
"":
FQN()) + new_var->
name();
687 results->push_back(new_var);
689 DBG( cerr << __func__ <<
"() - Added member variable '" << (*varIter)->name() <<
"' " <<
690 "to results vector. root: "<< (is_root?
"true":
"false") << endl;);
695 DBG( cerr << __func__ <<
"() - Dropping member variable " << (*varIter)->name() <<
696 " root: " << (is_root?
"true":
"false") << endl;);
698 dropped_vars.push_back(*varIter);
702 DBG( cerr << __func__ <<
"() - Processing " << dropped_vars.size() <<
" Dropped Variable(s)" << endl;);
703 AttrTable *dv_attr_table = make_dropped_vars_attr_table(&dropped_vars);
705 DBG( cerr << __func__ <<
"() - Adding Dropped Variables AttrTable" << endl;);
709 DBG( cerr << __func__ <<
"() - No Dropped Variables AttrTable returned." << endl;);
717 D4Group::groupsIter gEnd =
grp_end();
718 for( ; gIter!=gEnd ; gIter++){
720 DBG( cerr << __func__ <<
"() - Processing D4Group " << grp->
name() << endl;);
723 DBG( cerr << __func__ <<
"() - Processing " << grp->
name() <<
" Member Variables." << endl;);
724 vector<BaseType *>::iterator vIter = d2_vars->begin();
725 vector<BaseType *>::iterator vEnd = d2_vars->end();
726 for( ; vIter!=vEnd; vIter++){
727 DBG( cerr << __func__ <<
"() - Processing " << grp->
name() <<
" Member Variable: " << (*vIter)->name() << endl;);
728 results->push_back(*vIter);
740 DBG( cerr << __func__ <<
"() - END" << endl;);
virtual bool read_p()
Has this variable been read?
virtual string name() const
Returns the name of the class instance.
AttrTable * get_AttrTable(const std::string name)
copy attributes from DAP4 to DAP2
bool is_source_big_endian() const
Is the data source we are reading from a big-endian machine? We need this because the value of the CR...
virtual Attr_iter attr_end()
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())
Contains the attributes for a dataset.
virtual void set_name(const string &n)
Sets the name of the class instance.
string AttrType_to_String(const AttrType at)
D4Dimension * find_dim(const string &path)
Find the dimension using a path. Using the DAP4 name syntax, lookup a dimension. The dimension must b...
virtual string get_name() const
Get the name of this attribute table.
Read data from the stream made by D4StreamMarshaller.
D4Group(const string &name)
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
virtual void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter=false)
Serialize a Group.
A class for software fault reporting.
virtual BaseType * ptr_duplicate()
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
long request_size(bool constrained)
virtual AttrTable * append_container(const string &name)
Add a container to the attribute table.
virtual Type type() const
Returns the type of the class instance.
std::vector< dimension >::iterator Dim_iter
virtual bool read()
simple implementation of read that iterates through vars and calls read on them
groupsIter grp_end()
Get an iterator to the end of the values.
virtual D4Attributes * attributes()
virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr)
virtual void intern_data()
Read data into this variable.
virtual Attr_iter attr_begin()
groupsIter grp_begin()
Get an iterator to the start of the values.
virtual std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table)
DAP4 to DAP2 transform.
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.
virtual string type_name() const
Returns the type of the class instance as a string.
void print_dap4(XMLWriter &xml, bool constrained=false)
virtual std::string FQN() const
virtual string get_checksum()
virtual void set_name(const string &n)
Set the name of this attribute table.
virtual void put_checksum()
Write the checksum Write the checksum for the data sent since the last call to reset_checksum() to th...
D4EnumDefs * enum_defs()
Get the enumerations defined for this Group.
virtual void set_send_p(bool state)
virtual void reset_checksum()
A multidimensional array of identical data types.
virtual bool send_p()
Should this variable be sent?
virtual void set_read_p(bool state)
Sets the value of the read_p property.
virtual void set_send_p(bool state)
BaseType * find_var(const string &name)
D4Dimensions * dims()
Get the dimensions defined for this Group.
virtual void set_read_p(bool state)
Sets the value of the read_p property.