43#include "D4Attributes.h"
44#include "D4Dimensions.h"
48#include "D4StreamMarshaller.h"
49#include "D4StreamUnMarshaller.h"
58#undef INCLUDE_SOURCE_BYTE_ORDER
62void 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())
166D4Group::operator=(
const D4Group &rhs)
170 Constructor::operator=(rhs);
189D4Group::find_child_grp(
const string &grp_name)
192 [grp_name](
const D4Group *g) {
return g->name() == grp_name; });
193 return (g ==
grp_end()) ? 0: *g;
198D4Group::find_first_var_that_uses_dimension(D4Dimension *dim)
211 if ((*i)->send_p() && (*i)->type() == dods_array_c) {
212 Array *a =
static_cast<Array*
>(*i);
213 for (
Array::Dim_iter di = a->dim_begin(), de = a->dim_end(); di != de; ++di) {
214 if (a->dimension_D4dim(di) == dim)
221 BaseType *btp = (*i)->find_first_var_that_uses_dimension(dim);
229D4Group::find_first_var_that_uses_enumeration(D4EnumDef *enum_def)
242 if ((*i)->send_p() && (*i)->type() == dods_enum_c) {
243 D4Enum *e =
static_cast<D4Enum*
>(*i);
244 if (e->enumeration() == enum_def)
250 BaseType *btp = (*i)->find_first_var_that_uses_enumeration(enum_def);
272 if (lpath[0] ==
'/') {
274 throw InternalErr(__FILE__, __LINE__,
"Lookup of a FQN starting in non-root group.");
276 lpath = lpath.substr(1);
279 string::size_type pos = lpath.find(
'/');
280 if (pos == string::npos) {
282 return dims()->find_dim(lpath);
286 string grp_name = lpath.substr(0, pos);
287 lpath = lpath.substr(pos + 1);
289 D4Group *grp = find_child_grp(grp_name);
290 return (grp == 0) ? 0: grp->find_dim(lpath);
301 BaseType *map_source = m_find_map_source_helper(path);
304 if (map_source && map_source->type() == dods_array_c)
return static_cast<Array*
>(map_source);
315D4Group::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);
342D4Group::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())
454 size += (*v)->width(constrained);
457 size += (*v)->width(constrained);
462 groupsIter g = d_groups.begin();
463 while (g != d_groups.end())
473 groupsIter g = d_groups.begin();
474 while (g != d_groups.end())
483 groupsIter g = d_groups.begin();
484 while (g != d_groups.end())
493 groupsIter g = d_groups.begin();
494 while (g != d_groups.end())
504 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
506 if ((*i)->send_p()) {
515 oss.setf(ios::hex, ios::basefield);
516 oss << setfill(
'0') << setw(8) << checksum.GetCrc32();
517 a->add_value(oss.str());
518#if INCLUDE_SOURCE_BYTE_ORDER
519 if (um.is_source_big_endian())
520 a->add_value(
"source:big-endian");
522 a->add_value(
"source:little-endian");
524 (*i)->attributes()->add_attribute_nocopy(a);
525 DBG(cerr <<
"CRC32: " << oss.str() <<
" for " << (*i)->name() << endl);
557 groupsIter g = d_groups.begin();
558 while (g != d_groups.end())
568 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
570 if ((*i)->send_p()) {
573 DBG(cerr <<
"Serializing variable " << (*i)->type_name() <<
" " << (*i)->name() << endl);
574 (*i)->serialize(m, dmr, filter);
576 DBG(cerr <<
"Wrote CRC32: " << m.get_checksum() <<
" for " << (*i)->name() << endl);
584 groupsIter g = d_groups.begin();
585 while (g != d_groups.end()) {
586 DBG(cerr <<
"Deserializing group " << (*g)->name() << endl);
591 for (Vars_iter i = d_vars.begin(); i != d_vars.end(); i++) {
592 DBG(cerr <<
"Deserializing variable " << (*i)->type_name() <<
" " << (*i)->name() << endl);
593 (*i)->deserialize(um, dmr);
596 string crc = um.get_checksum_str();
598#if INCLUDE_SOURCE_BYTE_ORDER
599 if (um.is_source_big_endian())
600 a->add_value(
"source:big-endian");
602 a->add_value(
"source:little-endian");
604 DBG(cerr <<
"Read CRC32: " << crc <<
" for " << (*i)->name() << endl);
605 (*i)->attributes()->add_attribute_nocopy(a);
612 if (!
name().empty() &&
name() !=
"/") {
616 if (constrained && !
send_p())
619 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
type_name().c_str()) < 0)
622 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
623 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
627 if (!
dims()->empty())
628 dims()->print_dap4(xml, constrained);
632 enum_defs()->print_dap4(xml, constrained);
643 groupsIter g = d_groups.begin();
644 while (g != d_groups.end())
647 if (!
name().empty() &&
name() !=
"/") {
648 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
701 DBG( cerr << __func__ <<
"() - BEGIN ("<<
name() <<
")" << endl);
703 vector<BaseType *> *results =
new vector<BaseType *>();
710 attributes()->transform_attrs_to_dap2(group_attrs);
711 group_attrs->set_name(
name());
716 bool is_root = (
name() ==
"/");
719 assert(
name() ==
"/");
720 for (AttrTable::Attr_iter i = group_attrs->attr_begin(), e = group_attrs->attr_end(); i != e; ++i) {
721 if ((*i)->type == Attr_container) {
725 parent_attr_table->append_container(at, at->get_name());
728 parent_attr_table->append_attr((*i)->name,
AttrType_to_String((*i)->type), (*i)->attr);
732 group_attrs = parent_attr_table;
737 vector<BaseType *> dropped_vars;
740 DBG( cerr << __func__ <<
"() - Processing member variable '" << (*i)->name() <<
741 "' root: " << (is_root?
"true":
"false") << endl);
743 vector<BaseType *> *new_vars = (*i)->transform_to_dap2(group_attrs);
746 for (vector<BaseType*>::iterator vi = new_vars->begin(), ve = new_vars->end(); vi != ve; vi++) {
747 string new_name = (is_root ?
"" :
FQN()) + (*vi)->name();
748 (*vi)->set_name(new_name);
749 (*vi)->set_parent(NULL);
750 results->push_back((*vi));
754 DBG( cerr << __func__ <<
"() - Added member variable '" << (*i)->name() <<
"' " <<
755 "to results vector. root: "<< (is_root?
"true":
"false") << endl);
761 DBG( cerr << __func__ <<
"() - Dropping member variable " << (*i)->name() <<
762 " root: " << (is_root?
"true":
"false") << endl);
764 dropped_vars.push_back(*i);
769 DBG( cerr << __func__ <<
"() - Processing " << dropped_vars.size() <<
" Dropped Variable(s)" << endl);
771 AttrTable *dv_attr_table = make_dropped_vars_attr_table(&dropped_vars);
773 group_attrs->append_container(dv_attr_table, dv_attr_table->get_name());
777 for (D4Group::groupsIter gi =
grp_begin(), ge =
grp_end(); gi != ge; ++gi) {
778 vector<BaseType *> *d2_vars = (*gi)->transform_to_dap2(group_attrs);
780 for (vector<BaseType *>::iterator i = d2_vars->begin(), e = d2_vars->end(); i != e; ++i) {
781 results->push_back(*i);
788 group_attrs->set_name(
name());
789 parent_attr_table->append_container(group_attrs, group_attrs->get_name());
A multidimensional array of identical data types.
std::vector< dimension >::iterator Dim_iter
Contains the attributes for a dataset.
The basic data type for the DODS DAP types.
virtual string type_name() const
Returns the type of the class instance as a string.
virtual string name() const
Returns the name of the class instance.
virtual BaseType * get_parent() const
virtual bool read_p()
Has this variable been read?
virtual D4Attributes * attributes()
virtual bool send_p()
Should this variable be sent?
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
BaseType * var(const string &name, bool exact_match=true, btp_stack *s=nullptr) override
btp_stack no longer needed; use back pointers (BaseType::get_parent())
void set_read_p(bool state) override
Set the 'read_p' property for the Constructor and its members.
void set_send_p(bool state) override
bool read() override
Read the elements of Constructor marked for transmission.
D4Dimension * find_dim(const string &path)
Find the dimension using a path. Using the DAP4 name syntax, lookup a dimension. The dimension must b...
Array * find_map_source(const string &path)
Given a path to an Array that is also a Map, get that Array.
virtual void intern_data()
Read data into this variable.
virtual void set_read_p(bool state)
Set the 'read_p' property for the Constructor and its members.
BaseType * find_var(const string &name)
virtual std::string FQN() const
groupsIter grp_begin()
Get an iterator to the start of the values.
virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr)
virtual void set_send_p(bool state)
uint64_t request_size_kb(bool constrained)
Get the estimated size of a response in kilobytes. This method looks at the variables in the DDS and ...
groupsIter grp_end()
Get an iterator to the end of the values.
D4Dimensions * dims()
Get the dimensions defined for this Group.
virtual BaseType * ptr_duplicate()
virtual std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table)
Transform the D4Group's variables to DAP2 variables.
D4EnumDefs * enum_defs()
Get the enumerations defined for this Group.
long request_size(bool constrained)
D4Group(const string &name)
void print_dap4(XMLWriter &xml, bool constrained=false)
virtual void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter=false)
Serialize a Group.
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
Read data from the stream made by D4StreamMarshaller.
A class for software fault reporting.
top level DAP object to house generic methods
string AttrType_to_String(const AttrType at)