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()) {
102 DBG(cerr <<
"Exiting D4Group::m_duplicate" << endl);
116 :
Constructor(name, dods_group_c, true), d_dims(0), d_enum_defs(0)
130 :
Constructor(name, dataset, dods_group_c, true), d_dims(0), d_enum_defs(0)
136 DBG(cerr <<
"In D4Group::copy_ctor for " << rhs.
name() << endl);
145 groupsIter i = d_groups.begin();
146 while(i != d_groups.end())
157 D4Group::operator=(
const D4Group &rhs)
191 D4Group::find_child_grp(
const string &grp_name)
193 groupsIter g = find_if(
grp_begin(),
grp_end(), bind2nd(ptr_fun(name_eq), grp_name));
194 return (g ==
grp_end()) ? 0: *g;
199 D4Group::find_first_var_that_uses_dimension(
D4Dimension *dim)
212 if ((*i)->send_p() && (*i)->type() == dods_array_c) {
215 if (a->dimension_D4dim(di) == dim)
222 BaseType *btp = (*i)->find_first_var_that_uses_dimension(dim);
230 D4Group::find_first_var_that_uses_enumeration(
D4EnumDef *enum_def)
243 if ((*i)->send_p() && (*i)->type() == dods_enum_c) {
245 if (e->enumeration() == enum_def)
251 BaseType *btp = (*i)->find_first_var_that_uses_enumeration(enum_def);
273 if (lpath[0] ==
'/') {
275 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
277 lpath = lpath.substr(1);
280 string::size_type pos = lpath.find(
'/');
281 if (pos == string::npos) {
283 return dims()->find_dim(lpath);
287 string grp_name = lpath.substr(0, pos);
288 lpath = lpath.substr(pos + 1);
290 D4Group *grp = find_child_grp(grp_name);
291 return (grp == 0) ? 0: grp->
find_dim(lpath);
295 D4Group::find_map_source(
const string &path)
297 BaseType *map_source = m_find_map_source_helper(path);
300 if (map_source && map_source->
type() == dods_array_c)
return static_cast<Array*>(map_source);
306 D4Group::m_find_map_source_helper(
const string &path)
311 if (lpath[0] ==
'/') {
313 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
315 lpath = lpath.substr(1);
318 string::size_type pos = lpath.find(
'/');
319 if (pos == string::npos) {
325 string grp_name = lpath.substr(0, pos);
326 lpath = lpath.substr(pos + 1);
328 D4Group *grp = find_child_grp(grp_name);
329 return (grp == 0) ? 0: grp->
var(lpath);
333 D4Group::find_enum_def(
const string &path)
338 if (lpath[0] ==
'/') {
340 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
342 lpath = lpath.substr(1);
345 string::size_type pos = lpath.find(
'/');
346 if (pos == string::npos) {
348 return enum_defs()->find_enum_def(lpath);
352 string grp_name = lpath.substr(0, pos);
353 lpath = lpath.substr(pos + 1);
355 D4Group *grp = find_child_grp(grp_name);
356 return (grp == 0) ? 0: grp->
enum_defs()->find_enum_def(lpath);
372 if (lpath[0] ==
'/') {
374 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
376 lpath = lpath.substr(1);
379 string::size_type pos = lpath.find(
'/');
380 if (pos == string::npos) {
386 string grp_name = lpath.substr(0, pos);
387 lpath = lpath.substr(pos + 1);
389 D4Group *grp = find_child_grp(grp_name);
390 return (grp == 0) ? 0 : grp->
find_var(lpath);
408 size += (*v)->width(constrained);
411 size += (*v)->width(constrained);
418 groupsIter g = d_groups.begin();
419 while (g != d_groups.end())
420 size += (*g++)->request_size(constrained);
428 groupsIter g = d_groups.begin();
429 while (g != d_groups.end())
430 (*g++)->set_read_p(state);
438 groupsIter g = d_groups.begin();
439 while (g != d_groups.end())
440 (*g++)->set_send_p(state);
448 groupsIter g = d_groups.begin();
449 while (g != d_groups.end())
450 (*g++)->intern_data();
459 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
461 if ((*i)->send_p()) {
470 oss.setf(ios::hex, ios::basefield);
471 oss << setfill(
'0') << setw(8) << checksum.GetCrc32();
472 a->add_value(oss.str());
473 #if INCLUDE_SOURCE_BYTE_ORDER 474 if (um.is_source_big_endian())
475 a->add_value(
"source:big-endian");
477 a->add_value(
"source:little-endian");
479 (*i)->attributes()->add_attribute_nocopy(a);
480 DBG(cerr <<
"CRC32: " << oss.str() <<
" for " << (*i)->name() << endl);
512 groupsIter g = d_groups.begin();
513 while (g != d_groups.end())
514 (*g++)->serialize(m, dmr, filter);
523 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
525 if ((*i)->send_p()) {
528 DBG(cerr <<
"Serializing variable " << (*i)->type_name() <<
" " << (*i)->name() << endl);
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 DBG(cerr <<
"Deserializing group " << (*g)->name() << endl);
546 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
547 DBG(cerr <<
"Deserializing variable " << (*i)->type_name() <<
" " << (*i)->name() << endl);
548 (*i)->deserialize(um, dmr);
551 string crc = um.get_checksum_str();
553 #if INCLUDE_SOURCE_BYTE_ORDER 555 a->add_value(
"source:big-endian");
557 a->add_value(
"source:little-endian");
559 DBG(cerr <<
"Read CRC32: " << crc <<
" for " << (*i)->name() << endl);
560 (*i)->attributes()->add_attribute_nocopy(a);
567 if (!
name().empty() &&
name() !=
"/") {
571 if (constrained && !
send_p())
574 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
type_name().c_str()) < 0)
577 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
578 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
582 if (!
dims()->empty())
583 dims()->print_dap4(xml, constrained);
587 enum_defs()->print_dap4(xml, constrained);
598 groupsIter g = d_groups.begin();
599 while (g != d_groups.end())
600 (*g++)->print_dap4(xml, constrained);
602 if (!
name().empty() &&
name() !=
"/") {
603 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.
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 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...
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.