42 #include "XMLWriter.h" 43 #include "D4Attributes.h" 44 #include "D4Dimensions.h" 48 #include "D4StreamMarshaller.h" 49 #include "D4StreamUnMarshaller.h" 58 #undef INCLUDE_SOURCE_BYTE_ORDER 62 void D4Group::m_duplicate(
const D4Group &g)
64 DBG(cerr <<
"In D4Group::m_duplicate for " << g.name() << endl);
68 d_dims =
new D4Dimensions(*(g.d_dims));
69 d_dims->set_parent(
this);
77 Vars_citer vi = d_vars.begin();
78 while (vi != d_vars.end()) {
79 if ((*vi)->type() == dods_array_c)
80 static_cast<Array*>(*vi)->update_dimension_pointers(g.d_dims, d_dims);
87 Vars_citer vi = d_vars.begin();
88 while (vi != d_vars.end()) {
89 if ((*vi)->type() == dods_array_c)
90 static_cast<Array*>(*vi)->update_dimension_pointers(g.d_dims, d_dims);
96 if (g.d_enum_defs) d_enum_defs =
new D4EnumDefs(*g.d_enum_defs);
99 groupsCIter i = g.d_groups.begin();
100 while(i != g.d_groups.end()) {
106 DBG(cerr <<
"Exiting D4Group::m_duplicate" << endl);
120 :
Constructor(name, dods_group_c, true), d_dims(0), d_enum_defs(0)
134 :
Constructor(name, dataset, dods_group_c, true), d_dims(0), d_enum_defs(0)
140 DBG(cerr <<
"In D4Group::copy_ctor for " << rhs.
name() << endl);
149 groupsIter i = d_groups.begin();
150 while(i != d_groups.end())
166 D4Group::operator=(
const D4Group &rhs)
200 D4Group::find_child_grp(
const string &grp_name)
202 groupsIter g = find_if(
grp_begin(),
grp_end(), bind2nd(ptr_fun(name_eq), grp_name));
203 return (g ==
grp_end()) ? 0: *g;
208 D4Group::find_first_var_that_uses_dimension(
D4Dimension *dim)
221 if ((*i)->send_p() && (*i)->type() == dods_array_c) {
224 if (a->dimension_D4dim(di) == dim)
231 BaseType *btp = (*i)->find_first_var_that_uses_dimension(dim);
239 D4Group::find_first_var_that_uses_enumeration(
D4EnumDef *enum_def)
252 if ((*i)->send_p() && (*i)->type() == dods_enum_c) {
254 if (e->enumeration() == enum_def)
260 BaseType *btp = (*i)->find_first_var_that_uses_enumeration(enum_def);
282 if (lpath[0] ==
'/') {
284 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
286 lpath = lpath.substr(1);
289 string::size_type pos = lpath.find(
'/');
290 if (pos == string::npos) {
292 return dims()->find_dim(lpath);
296 string grp_name = lpath.substr(0, pos);
297 lpath = lpath.substr(pos + 1);
299 D4Group *grp = find_child_grp(grp_name);
300 return (grp == 0) ? 0: grp->
find_dim(lpath);
304 D4Group::find_map_source(
const string &path)
306 BaseType *map_source = m_find_map_source_helper(path);
309 if (map_source && map_source->
type() == dods_array_c)
return static_cast<Array*>(map_source);
315 D4Group::m_find_map_source_helper(
const string &path)
320 if (lpath[0] ==
'/') {
322 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
324 lpath = lpath.substr(1);
327 string::size_type pos = lpath.find(
'/');
328 if (pos == string::npos) {
334 string grp_name = lpath.substr(0, pos);
335 lpath = lpath.substr(pos + 1);
337 D4Group *grp = find_child_grp(grp_name);
338 return (grp == 0) ? 0: grp->
var(lpath);
342 D4Group::find_enum_def(
const string &path)
347 if (lpath[0] ==
'/') {
349 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
351 lpath = lpath.substr(1);
354 string::size_type pos = lpath.find(
'/');
355 if (pos == string::npos) {
357 return enum_defs()->find_enum_def(lpath);
361 string grp_name = lpath.substr(0, pos);
362 lpath = lpath.substr(pos + 1);
364 D4Group *grp = find_child_grp(grp_name);
365 return (grp == 0) ? 0: grp->
enum_defs()->find_enum_def(lpath);
381 if (lpath[0] ==
'/') {
383 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
385 lpath = lpath.substr(1);
388 string::size_type pos = lpath.find(
'/');
389 if (pos == string::npos) {
395 string grp_name = lpath.substr(0, pos);
396 lpath = lpath.substr(pos + 1);
398 D4Group *grp = find_child_grp(grp_name);
399 return (grp == 0) ? 0 : grp->
find_var(lpath);
417 size += (*v)->width(constrained);
420 size += (*v)->width(constrained);
427 groupsIter g = d_groups.begin();
428 while (g != d_groups.end())
429 size += (*g++)->request_size(constrained);
437 groupsIter g = d_groups.begin();
438 while (g != d_groups.end())
439 (*g++)->set_read_p(state);
447 groupsIter g = d_groups.begin();
448 while (g != d_groups.end())
449 (*g++)->set_send_p(state);
457 groupsIter g = d_groups.begin();
458 while (g != d_groups.end())
459 (*g++)->intern_data();
468 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
470 if ((*i)->send_p()) {
479 oss.setf(ios::hex, ios::basefield);
480 oss << setfill(
'0') << setw(8) << checksum.GetCrc32();
481 a->add_value(oss.str());
482 #if INCLUDE_SOURCE_BYTE_ORDER 483 if (um.is_source_big_endian())
484 a->add_value(
"source:big-endian");
486 a->add_value(
"source:little-endian");
488 (*i)->attributes()->add_attribute_nocopy(a);
489 DBG(cerr <<
"CRC32: " << oss.str() <<
" for " << (*i)->name() << endl);
521 groupsIter g = d_groups.begin();
522 while (g != d_groups.end())
523 (*g++)->serialize(m, dmr, filter);
532 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
534 if ((*i)->send_p()) {
537 DBG(cerr <<
"Serializing variable " << (*i)->type_name() <<
" " << (*i)->name() << endl);
538 (*i)->serialize(m, dmr, filter);
540 DBG(cerr <<
"Wrote CRC32: " << m.
get_checksum() <<
" for " << (*i)->name() << endl);
548 groupsIter g = d_groups.begin();
549 while (g != d_groups.end()) {
550 DBG(cerr <<
"Deserializing group " << (*g)->name() << endl);
555 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
556 DBG(cerr <<
"Deserializing variable " << (*i)->type_name() <<
" " << (*i)->name() << endl);
557 (*i)->deserialize(um, dmr);
560 string crc = um.get_checksum_str();
562 #if INCLUDE_SOURCE_BYTE_ORDER 564 a->add_value(
"source:big-endian");
566 a->add_value(
"source:little-endian");
568 DBG(cerr <<
"Read CRC32: " << crc <<
" for " << (*i)->name() << endl);
569 (*i)->attributes()->add_attribute_nocopy(a);
576 if (!
name().empty() &&
name() !=
"/") {
580 if (constrained && !
send_p())
583 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
type_name().c_str()) < 0)
586 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
587 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
591 if (!
dims()->empty())
592 dims()->print_dap4(xml, constrained);
596 enum_defs()->print_dap4(xml, constrained);
607 groupsIter g = d_groups.begin();
608 while (g != d_groups.end())
609 (*g++)->print_dap4(xml, constrained);
611 if (!
name().empty() &&
name() !=
"/") {
612 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
665 DBG( cerr << __func__ <<
"() - BEGIN ("<<
name() <<
")" << endl);
667 vector<BaseType *> *results =
new vector<BaseType *>();
680 bool is_root = (
name() ==
"/");
683 assert(
name() ==
"/");
684 for (AttrTable::Attr_iter i = group_attrs->
attr_begin(), e = group_attrs->
attr_end(); i != e; ++i) {
685 if ((*i)->type == Attr_container) {
696 group_attrs = parent_attr_table;
701 vector<BaseType *> dropped_vars;
704 DBG( cerr << __func__ <<
"() - Processing member variable '" << (*i)->name() <<
705 "' root: " << (is_root?
"true":
"false") << endl);
707 vector<BaseType *> *new_vars = (*i)->transform_to_dap2(group_attrs);
710 for (vector<BaseType*>::iterator vi = new_vars->begin(), ve = new_vars->end(); vi != ve; vi++) {
711 string new_name = (is_root ?
"" :
FQN()) + (*vi)->name();
712 (*vi)->set_name(new_name);
713 (*vi)->set_parent(NULL);
714 results->push_back((*vi));
718 DBG( cerr << __func__ <<
"() - Added member variable '" << (*i)->name() <<
"' " <<
719 "to results vector. root: "<< (is_root?
"true":
"false") << endl);
725 DBG( cerr << __func__ <<
"() - Dropping member variable " << (*i)->name() <<
726 " root: " << (is_root?
"true":
"false") << endl);
728 dropped_vars.push_back(*i);
733 DBG( cerr << __func__ <<
"() - Processing " << dropped_vars.size() <<
" Dropped Variable(s)" << endl);
735 AttrTable *dv_attr_table = make_dropped_vars_attr_table(&dropped_vars);
741 for (D4Group::groupsIter gi =
grp_begin(), ge =
grp_end(); gi != ge; ++gi) {
742 vector<BaseType *> *d2_vars = (*gi)->transform_to_dap2(group_attrs);
744 for (vector<BaseType *>::iterator i = d2_vars->begin(), e = d2_vars->end(); i != e; ++i) {
745 results->push_back(*i);
virtual bool read_p()
Has this variable been read?
virtual string name() const
Returns the name of the class instance.
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.
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)
virtual void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter=false)
Serialize a Group.
top level DAP object to house generic methods
A class for software fault reporting.
void transform_attrs_to_dap2(AttrTable *d2_attr_table)
Copy the attributes from this D4Attributes object to a DAP2 AttrTable.
Holds a DAP4 enumeration.
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)
Transform the D4Group's variables to DAP2 variables.
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)
virtual string dataset() const
Returns the name of the dataset used to create this instance.
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.