39 #include "XMLWriter.h" 40 #include "D4Attributes.h" 41 #include "D4Dimensions.h" 45 #include "D4StreamMarshaller.h" 46 #include "D4StreamUnMarshaller.h" 55 #undef INCLUDE_SOURCE_BYTE_ORDER 59 void D4Group::m_duplicate(
const D4Group &g)
61 DBG(cerr <<
"In D4Group::m_duplicate for " << g.name() << endl);
65 d_dims =
new D4Dimensions(*(g.d_dims));
66 d_dims->set_parent(
this);
74 Vars_citer vi = d_vars.begin();
75 while (vi != d_vars.end()) {
76 if ((*vi)->type() == dods_array_c)
77 static_cast<Array*>(*vi)->update_dimension_pointers(g.d_dims, d_dims);
84 Vars_citer vi = d_vars.begin();
85 while (vi != d_vars.end()) {
86 if ((*vi)->type() == dods_array_c)
87 static_cast<Array*>(*vi)->update_dimension_pointers(g.d_dims, d_dims);
93 if (g.d_enum_defs) d_enum_defs =
new D4EnumDefs(*g.d_enum_defs);
96 groupsCIter i = g.d_groups.begin();
97 while(i != g.d_groups.end()) {
103 DBG(cerr <<
"Exiting D4Group::m_duplicate" << endl);
117 :
Constructor(name, dods_group_c, true), d_dims(0), d_enum_defs(0)
131 :
Constructor(name, dataset, dods_group_c, true), d_dims(0), d_enum_defs(0)
137 DBG(cerr <<
"In D4Group::copy_ctor for " << rhs.
name() << endl);
146 groupsIter i = d_groups.begin();
147 while(i != d_groups.end())
163 D4Group::operator=(
const D4Group &rhs)
197 D4Group::find_child_grp(
const string &grp_name)
199 groupsIter g = find_if(
grp_begin(),
grp_end(), bind2nd(ptr_fun(name_eq), grp_name));
200 return (g ==
grp_end()) ? 0: *g;
205 D4Group::find_first_var_that_uses_dimension(
D4Dimension *dim)
218 if ((*i)->send_p() && (*i)->type() == dods_array_c) {
221 if (a->dimension_D4dim(di) == dim)
228 BaseType *btp = (*i)->find_first_var_that_uses_dimension(dim);
236 D4Group::find_first_var_that_uses_enumeration(
D4EnumDef *enum_def)
249 if ((*i)->send_p() && (*i)->type() == dods_enum_c) {
251 if (e->enumeration() == enum_def)
257 BaseType *btp = (*i)->find_first_var_that_uses_enumeration(enum_def);
279 if (lpath[0] ==
'/') {
281 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
283 lpath = lpath.substr(1);
286 string::size_type pos = lpath.find(
'/');
287 if (pos == string::npos) {
289 return dims()->find_dim(lpath);
293 string grp_name = lpath.substr(0, pos);
294 lpath = lpath.substr(pos + 1);
296 D4Group *grp = find_child_grp(grp_name);
297 return (grp == 0) ? 0: grp->
find_dim(lpath);
301 D4Group::find_map_source(
const string &path)
303 BaseType *map_source = m_find_map_source_helper(path);
306 if (map_source && map_source->
type() == dods_array_c)
return static_cast<Array*>(map_source);
312 D4Group::m_find_map_source_helper(
const string &path)
317 if (lpath[0] ==
'/') {
319 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
321 lpath = lpath.substr(1);
324 string::size_type pos = lpath.find(
'/');
325 if (pos == string::npos) {
331 string grp_name = lpath.substr(0, pos);
332 lpath = lpath.substr(pos + 1);
334 D4Group *grp = find_child_grp(grp_name);
335 return (grp == 0) ? 0: grp->
var(lpath);
339 D4Group::find_enum_def(
const string &path)
344 if (lpath[0] ==
'/') {
346 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
348 lpath = lpath.substr(1);
351 string::size_type pos = lpath.find(
'/');
352 if (pos == string::npos) {
354 return enum_defs()->find_enum_def(lpath);
358 string grp_name = lpath.substr(0, pos);
359 lpath = lpath.substr(pos + 1);
361 D4Group *grp = find_child_grp(grp_name);
362 return (grp == 0) ? 0: grp->
enum_defs()->find_enum_def(lpath);
378 if (lpath[0] ==
'/') {
380 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
382 lpath = lpath.substr(1);
385 string::size_type pos = lpath.find(
'/');
386 if (pos == string::npos) {
392 string grp_name = lpath.substr(0, pos);
393 lpath = lpath.substr(pos + 1);
395 D4Group *grp = find_child_grp(grp_name);
396 return (grp == 0) ? 0 : grp->
find_var(lpath);
414 size += (*v)->width(constrained);
417 size += (*v)->width(constrained);
424 groupsIter g = d_groups.begin();
425 while (g != d_groups.end())
426 size += (*g++)->request_size(constrained);
434 groupsIter g = d_groups.begin();
435 while (g != d_groups.end())
436 (*g++)->set_read_p(state);
444 groupsIter g = d_groups.begin();
445 while (g != d_groups.end())
446 (*g++)->set_send_p(state);
454 groupsIter g = d_groups.begin();
455 while (g != d_groups.end())
456 (*g++)->intern_data();
465 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
467 if ((*i)->send_p()) {
476 oss.setf(ios::hex, ios::basefield);
477 oss << setfill(
'0') << setw(8) << checksum.GetCrc32();
478 a->add_value(oss.str());
479 #if INCLUDE_SOURCE_BYTE_ORDER 480 if (um.is_source_big_endian())
481 a->add_value(
"source:big-endian");
483 a->add_value(
"source:little-endian");
485 (*i)->attributes()->add_attribute_nocopy(a);
486 DBG(cerr <<
"CRC32: " << oss.str() <<
" for " << (*i)->name() << endl);
518 groupsIter g = d_groups.begin();
519 while (g != d_groups.end())
520 (*g++)->serialize(m, dmr, filter);
529 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
531 if ((*i)->send_p()) {
534 DBG(cerr <<
"Serializing variable " << (*i)->type_name() <<
" " << (*i)->name() << endl);
535 (*i)->serialize(m, dmr, filter);
537 DBG(cerr <<
"Wrote CRC32: " << m.
get_checksum() <<
" for " << (*i)->name() << endl);
545 groupsIter g = d_groups.begin();
546 while (g != d_groups.end()) {
547 DBG(cerr <<
"Deserializing group " << (*g)->name() << endl);
552 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
553 DBG(cerr <<
"Deserializing variable " << (*i)->type_name() <<
" " << (*i)->name() << endl);
554 (*i)->deserialize(um, dmr);
557 string crc = um.get_checksum_str();
559 #if INCLUDE_SOURCE_BYTE_ORDER 561 a->add_value(
"source:big-endian");
563 a->add_value(
"source:little-endian");
565 DBG(cerr <<
"Read CRC32: " << crc <<
" for " << (*i)->name() << endl);
566 (*i)->attributes()->add_attribute_nocopy(a);
573 if (!
name().empty() &&
name() !=
"/") {
577 if (constrained && !
send_p())
580 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
type_name().c_str()) < 0)
583 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
584 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
588 if (!
dims()->empty())
589 dims()->print_dap4(xml, constrained);
593 enum_defs()->print_dap4(xml, constrained);
604 groupsIter g = d_groups.begin();
605 while (g != d_groups.end())
606 (*g++)->print_dap4(xml, constrained);
608 if (!
name().empty() &&
name() !=
"/") {
609 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
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 BaseType * var(const string &name, bool exact_match=true, btp_stack *s=0)
btp_stack no longer needed; use back pointers (BaseType::get_parent())
D4Dimension * find_dim(const string &path)
Find the dimension using a path. Using the DAP4 name syntax, lookup a dimension. The dimension must b...
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.
A class for software fault reporting.
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 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.
groupsIter grp_begin()
Get an iterator to the start of the values.
virtual BaseType * get_parent() const
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 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.