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()) {
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())
158 D4Group::operator=(
const D4Group &rhs)
192 D4Group::find_child_grp(
const string &grp_name)
194 groupsIter g = find_if(
grp_begin(),
grp_end(), bind2nd(ptr_fun(name_eq), grp_name));
195 return (g ==
grp_end()) ? 0: *g;
200 D4Group::find_first_var_that_uses_dimension(
D4Dimension *dim)
213 if ((*i)->send_p() && (*i)->type() == dods_array_c) {
216 if (a->dimension_D4dim(di) == dim)
223 BaseType *btp = (*i)->find_first_var_that_uses_dimension(dim);
231 D4Group::find_first_var_that_uses_enumeration(
D4EnumDef *enum_def)
244 if ((*i)->send_p() && (*i)->type() == dods_enum_c) {
246 if (e->enumeration() == enum_def)
252 BaseType *btp = (*i)->find_first_var_that_uses_enumeration(enum_def);
274 if (lpath[0] ==
'/') {
276 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
278 lpath = lpath.substr(1);
281 string::size_type pos = lpath.find(
'/');
282 if (pos == string::npos) {
284 return dims()->find_dim(lpath);
288 string grp_name = lpath.substr(0, pos);
289 lpath = lpath.substr(pos + 1);
291 D4Group *grp = find_child_grp(grp_name);
292 return (grp == 0) ? 0: grp->
find_dim(lpath);
296 D4Group::find_map_source(
const string &path)
298 BaseType *map_source = m_find_map_source_helper(path);
301 if (map_source && map_source->
type() == dods_array_c)
return static_cast<Array*>(map_source);
307 D4Group::m_find_map_source_helper(
const string &path)
312 if (lpath[0] ==
'/') {
314 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
316 lpath = lpath.substr(1);
319 string::size_type pos = lpath.find(
'/');
320 if (pos == string::npos) {
326 string grp_name = lpath.substr(0, pos);
327 lpath = lpath.substr(pos + 1);
329 D4Group *grp = find_child_grp(grp_name);
330 return (grp == 0) ? 0: grp->
var(lpath);
334 D4Group::find_enum_def(
const string &path)
339 if (lpath[0] ==
'/') {
341 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
343 lpath = lpath.substr(1);
346 string::size_type pos = lpath.find(
'/');
347 if (pos == string::npos) {
349 return enum_defs()->find_enum_def(lpath);
353 string grp_name = lpath.substr(0, pos);
354 lpath = lpath.substr(pos + 1);
356 D4Group *grp = find_child_grp(grp_name);
357 return (grp == 0) ? 0: grp->
enum_defs()->find_enum_def(lpath);
373 if (lpath[0] ==
'/') {
375 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
377 lpath = lpath.substr(1);
380 string::size_type pos = lpath.find(
'/');
381 if (pos == string::npos) {
387 string grp_name = lpath.substr(0, pos);
388 lpath = lpath.substr(pos + 1);
390 D4Group *grp = find_child_grp(grp_name);
391 return (grp == 0) ? 0 : grp->
find_var(lpath);
409 size += (*v)->width(constrained);
412 size += (*v)->width(constrained);
419 groupsIter g = d_groups.begin();
420 while (g != d_groups.end())
421 size += (*g++)->request_size(constrained);
429 groupsIter g = d_groups.begin();
430 while (g != d_groups.end())
431 (*g++)->set_read_p(state);
439 groupsIter g = d_groups.begin();
440 while (g != d_groups.end())
441 (*g++)->set_send_p(state);
449 groupsIter g = d_groups.begin();
450 while (g != d_groups.end())
451 (*g++)->intern_data();
460 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
462 if ((*i)->send_p()) {
471 oss.setf(ios::hex, ios::basefield);
472 oss << setfill(
'0') << setw(8) << checksum.GetCrc32();
473 a->add_value(oss.str());
474 #if INCLUDE_SOURCE_BYTE_ORDER 475 if (um.is_source_big_endian())
476 a->add_value(
"source:big-endian");
478 a->add_value(
"source:little-endian");
480 (*i)->attributes()->add_attribute_nocopy(a);
481 DBG(cerr <<
"CRC32: " << oss.str() <<
" for " << (*i)->name() << endl);
513 groupsIter g = d_groups.begin();
514 while (g != d_groups.end())
515 (*g++)->serialize(m, dmr, filter);
524 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
526 if ((*i)->send_p()) {
529 (*i)->serialize(m, dmr, filter);
531 DBG(cerr <<
"Wrote CRC32: " << m.
get_checksum() <<
" for " << (*i)->name() << endl);
539 groupsIter g = d_groups.begin();
540 while (g != d_groups.end())
541 (*g++)->deserialize(um, dmr);
545 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
546 (*i)->deserialize(um, dmr);
549 string crc = um.get_checksum_str();
551 #if INCLUDE_SOURCE_BYTE_ORDER 553 a->add_value(
"source:big-endian");
555 a->add_value(
"source:little-endian");
557 DBG(cerr <<
"Read CRC32: " << crc <<
" for " << (*i)->name() << endl);
558 (*i)->attributes()->add_attribute_nocopy(a);
565 if (!
name().empty() &&
name() !=
"/") {
569 if (constrained && !
send_p())
572 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
type_name().c_str()) < 0)
575 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
576 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
580 if (!
dims()->empty())
581 dims()->print_dap4(xml, constrained);
585 enum_defs()->print_dap4(xml, constrained);
596 groupsIter g = d_groups.begin();
597 while (g != d_groups.end())
598 (*g++)->print_dap4(xml, constrained);
600 if (!
name().empty() &&
name() !=
"/") {
601 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
virtual bool read_p()
Has this variable been read?
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())
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...
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.
virtual Type type() const
Returns the type of the class instance.
A class for software fault reporting.
virtual string dataset() const
Returns the name of the dataset used to create this instance.
virtual string type_name() const
Returns the type of the class instance as a string.
Holds a DAP4 enumeration.
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
long request_size(bool constrained)
std::vector< dimension >::iterator Dim_iter
virtual BaseType * get_parent() const
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 string name() const
Returns the name of the class instance.
groupsIter grp_begin()
Get an iterator to the start of the values.
The basic data type for the DODS DAP types.
void print_dap4(XMLWriter &xml, bool constrained=false)
virtual string get_checksum()
virtual D4Group * ptr_duplicate()
virtual void put_checksum()
Write the checksum Write the checksum for the data sent since the last call to reset_checksum() to th...
virtual std::string FQN() const
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.