46#include "InternalErr.h"
48#include "XDRStreamMarshaller.h"
55#include "D4Attributes.h"
64Grid::m_duplicate(
const Grid &s)
66 d_is_array_set = s.d_is_array_set;
78Grid::Grid(
const string &n) : Constructor(n, dods_grid_c), d_is_array_set(false)
93 : Constructor(n, d, dods_grid_c), d_is_array_set(false)
110 return new Grid(*
this);
114Grid::operator=(
const Grid &rhs)
118 Constructor::operator=(rhs);
129 DBG(cerr << __func__ <<
"() - BEGIN (name:"<<
name() <<
131 ")(root:'"<< root->
name()<<
"':"<<(
void*)root <<
132 ")(container:'"<< container->
name()<<
"':"<< (
void *) container<<
")"
135 vector<Array*> d4_map_arrays;
144 DBG(cerr << __func__ <<
"() - Processing Map Array: '"<< (*i)->name() <<
"' ("<< (
void *)(*i)<<
")" << endl;);
150 Array *the_map_array;
151 Array *container_map_array =
static_cast<Array*
>(container->
var((*i)->name()));
152 if(!container_map_array){
153 DBG(cerr << __func__ <<
"() - No Map Array '" << (*i)->name() <<
"' present in the current DAP4 container ("<<container->
name()<<
":"<<(
void*)container<<
"). Let's fix that..." << endl;);
155 Array *root_map_array =
static_cast<Array*
>(root->
var((*i)->name()));
156 if (!root_map_array) {
158 DBG(cerr << __func__ <<
"() - No Map Array '" << (*i)->name() <<
"' present in the root Group ("<<root->
name()<<
":"<<(
void*)root<<
"). Let's fix that..." << endl;);
160 (*i)->transform_to_dap4(root, container);
162 the_map_array =
static_cast<Array*
>(container->
var((*i)->name()));
163 DBG(cerr << __func__ <<
"() - Transformed array '"<< the_map_array->
name() <<
164 "' to DAP4 Array (" << (
void *) the_map_array <<
") added to container: '"<<
165 container->
name() <<
"'" << endl;);
168 the_map_array = root_map_array;
169 DBG(cerr << __func__ <<
"() - Located Map Array '" << the_map_array->
name() <<
"' (" <<
170 (
void *) the_map_array <<
") present in the root group ("<<root->
name()<<
":"<<(
void*)root <<
175 the_map_array = container_map_array;
176 DBG(cerr << __func__ <<
"() - Located Map Array '" << the_map_array->
name() <<
"' (" <<
177 (
void *) the_map_array <<
") present in the current DAP4 container ("<<container->
name( )<<
":"<<
178 (
void*)container<<
")" << endl;);
181 d4_map_arrays.push_back(the_map_array);
189 DBG(cerr << __func__ <<
"() - Transformed and added DAP4 coverage Array '"<< coverage->
name() <<
190 "' to parent container: '" << container->
name() <<
"'" << endl;);
194 DBG(cerr << __func__ <<
"() - " <<
"Coverage Array '"<< coverage->
name() <<
"' attributes: " << endl;
197 cerr << xmlw.get_doc() << endl;);
202 for( ; d4aItr!=end ; d4aItr++){
203 Array *the_map_array = *d4aItr;
209 D4Map *d4_map =
new D4Map(the_map_array->
FQN(), the_map_array);
210 coverage->maps()->
add_map(d4_map);
214 DBG(cerr << __func__ <<
"() - Added DAP4 Map Array: '"<< d4_map->name() <<
215 "' (" << (
void *) d4_map->
array() <<
") to coverage: '" << coverage->
name() <<
"'" << endl;);
218 DBG(cerr << __func__ <<
"() - END (grid:" <<
name() <<
")" << endl;);
249 throw InternalErr(__FILE__, __LINE__,
"Passing NULL pointer as variable to be added.");
252 throw Error(
string(
"A method usable only with DAP2 variables was called on a DAP4 variable (").append(
name()).append(
")."), __FILE__, __LINE__);
254 if (part == array && d_is_array_set) {
256 throw InternalErr(__FILE__, __LINE__,
"Error: Grid::add_var called with part==Array, but the array was already set!");
260 if (!
dynamic_cast<Array*
>(bt)) {
261 throw InternalErr(__FILE__, __LINE__,
"Grid::add_var(): object is not an Array!");
279 d_vars.push_back(bt_clone);
284 if (!d_is_array_set) {
292 d_vars.push_back(bt_clone);
318 throw InternalErr(__FILE__, __LINE__,
"Passing NULL pointer as variable to be added.");
321 throw Error(
string(
"A method usable only with DAP2 variables was called on a DAP4 variable (").append(
name()).append(
")."), __FILE__, __LINE__);
323 if (part == array && d_is_array_set) {
325 throw InternalErr(__FILE__, __LINE__,
"Error: Grid::add_var called with part==Array, but the array was already set!");
329 if (!
dynamic_cast<Array*
>(bt)) {
330 throw InternalErr(__FILE__, __LINE__,
"Grid::add_var(): object is not an Array!");
346 d_vars.push_back(bt);
351 if (!d_is_array_set) {
357 d_vars.push_back(bt);
380 throw InternalErr(__FILE__, __LINE__,
"Grid::set_array(): Cannot set to null!");
394 if (d_vars.size() == 0) {
395 d_vars.push_back(p_new_arr);
397 else if (!d_is_array_set) {
398 d_vars.insert(d_vars.begin(), p_new_arr);
403 d_vars[0] = p_new_arr;
406 d_is_array_set =
true;
409 d_array_var = p_new_arr;
446 throw InternalErr(__FILE__, __LINE__,
"Grid::add_map(): cannot have p_new_map null!");
453 d_vars.push_back(p_new_map);
491 return d_is_array_set ? *d_vars.begin() :
nullptr;
511 return d_is_array_set ? d_vars.begin() + 1: d_vars.begin();
527 return d_vars.rbegin();
535 return d_is_array_set ? d_vars.rend() - 1: d_vars.rend();
544 return d_is_array_set ? d_vars.begin() + 1 + i : d_vars.begin() + i;
571 if ((*i)->send_p()) {
577 comp = d_vars.size();
590 DBG( cerr << __func__ <<
"() - BEGIN "<<
type_name() <<
" " <<
name() <<
" (at_container:"<< at_container->
get_name() <<
":"<<(
void*)at_container<<
")" << endl;);
595 DBG( cerr << __func__ <<
"() - Found AttrTable ("<< at->
get_name() <<
":" << (
void*)at<<
")" << endl;);
596 at->set_is_global_attribute(
false);
614 dvat->set_is_global_attribute(
false);
619 (*map)->transfer_attributes(at);
628 if (at->is_global_attribute(at_p)) {
629 DBG( cerr << __func__ <<
"() - " <<
630 "Adding unclaimed Attribute ("<<
632 ") from AttrTable (" << at->
get_name() <<
":" << (
void*)at <<
")" <<
633 " to the variable " <<
type_name() <<
" " <<
name() << endl;);
645 DBG( cerr << __func__ <<
"() - No AttrTable named '"<<
name() <<
"' was found in at_container ("<<at_container->
get_name()<<
":" << (
void*)at<<
")" << endl;);
647 DBG( cerr << __func__ <<
"() - END "<<
type_name() <<
" " <<
name() <<
" (at_container:"<< at_container->
get_name() <<
":"<<(
void*)at_container<<
")" << endl;);
723 bool constraint_info,
bool constrained)
726 print_decl(oss, space, print_semi, constraint_info, constrained);
727 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
732 bool constraint_info,
bool constrained)
734 if (constrained && !
send_p())
739 out << space <<
"Structure {\n" ;
745 (*i)->print_decl(out, space +
" ",
true,
746 constraint_info, constrained);
756 out << space <<
" Array:\n" ;
760 out << space <<
" Maps:\n" ;
762 (*i)->print_decl(out, space +
" ",
true,
763 constraint_info, constrained);
769 if (constraint_info) {
771 out <<
": Send True";
773 out <<
": Send False";
790 fwrite(xml.get_doc(),
sizeof(
char), xml.get_doc_size(), out);
801 out << xml.get_doc();
805class PrintGridFieldXMLWriter :
public unary_function<BaseType *, void>
811 PrintGridFieldXMLWriter(
XMLWriter &x,
bool c,
const string &t =
"Map")
812 : d_xml(x), d_constrained(c), d_tag(t)
815 void operator()(BaseType *btp)
817 Array *a =
dynamic_cast<Array*
>(btp);
819 throw InternalErr(__FILE__, __LINE__,
"Expected an Array.");
820 a->print_xml_writer_core(d_xml, d_constrained, d_tag);
827 if (constrained && !
send_p())
831 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Structure") < 0)
832 throw InternalErr(__FILE__, __LINE__,
"Could not write Structure element");
835 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
836 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
843 PrintGridFieldXMLWriter(xml, constrained,
"Array"));
845 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
846 throw InternalErr(__FILE__, __LINE__,
"Could not end Structure element");
851 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Grid") < 0)
852 throw InternalErr(__FILE__, __LINE__,
"Could not write Grid element");
855 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
856 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
863 PrintGridFieldXMLWriter(xml, constrained,
"Map"));
865 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
866 throw InternalErr(__FILE__, __LINE__,
"Could not end Grid element");
875 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
897 if (pyg || !
send_p()) out <<
" Maps: ";
900 (*i)->print_val(out,
"",
false);
905 if (print_decl_p) out <<
";\n";
923 msg +=
"Null grid base array in `" +
name() +
"'\n";
929 msg +=
"Grid `" +
name() +
"'s' member `" +
get_array()->
name() +
"' must be an array\n";
937 msg +=
"The field variable `" + this->
name() +
"' must be an array of simple type elements (e.g., int32, String)\n";
942 if ((
unsigned)d_vars.size()-1 != av->
dimensions()) {
943 msg +=
"The number of map variables for grid `" + this->
name() +
"' does not match the number of dimensions of `";
944 msg += av->
name() +
"'\n";
948 const string array_var_name = av->
name();
955 if (array_var_name == mv->
name()) {
956 msg +=
"Grid map variable `" + mv->
name() +
"' conflicts with the grid array name in grid `" +
name() +
"'\n";
960 if (mv->
type() != dods_array_c) {
961 msg +=
"Grid map variable `" + mv->
name() +
"' is not an array\n";
969 msg +=
"The field variable `" + this->
name() +
"' must be an array of simple type elements (e.g., int32, String)\n";
975 msg +=
"Grid map variable `" + mv_a->
name() +
"' must be only one dimension\n";
982 if (mv_a_size != av_size) {
983 msg +=
"Grid map variable `" + mv_a->
name() +
"'s' size does not match the size of array variable '";
984 msg +=
get_array()->
name() +
"'s' cooresponding dimension\n";
993 if (!(*mvi)->check_semantics(msg,
true)) {
1013 strm << DapIndent::LMarg <<
"Grid::dump - ("
1014 << (
void *)
this <<
")" << endl ;
1015 DapIndent::Indent() ;
1018 DapIndent::UnIndent() ;
A multidimensional array of identical data types.
virtual int dimension_start(Dim_iter i, bool constrained=false)
Return the start index of a dimension.
virtual void clear_constraint()
Clears the projection; add each projected dimension explicitly using add_constraint.
virtual int dimension_stop(Dim_iter i, bool constrained=false)
Return the stop index of the constraint.
void print_decl(ostream &out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false) override
Prints a DDS entry for the Array.
void print_val(ostream &out, string space="", bool print_decl_p=true) override
Prints the value of the variable.
BaseType * ptr_duplicate() override
std::vector< dimension >::iterator Dim_iter
virtual int dimension_size(Dim_iter i, bool constrained=false)
Returns the size of the dimension.
void print_xml_writer(XMLWriter &xml, bool constrained=false) override
virtual unsigned int dimensions(bool constrained=false)
Return the total number of dimensions in the array.
virtual int dimension_stride(Dim_iter i, bool constrained=false)
Returns the stride value of the constraint.
Contains the attributes for a dataset.
virtual AttrTable * append_container(const string &name)
Add a container to the attribute table.
virtual AttrTable * get_attr_table(const string &name)
Get an attribute container.
virtual Attr_iter attr_end()
virtual string get_type(const string &name)
Get the type name of an attribute within this attribute table.
virtual vector< string > * get_attr_vector(const string &name)
Get a vector-valued attribute.
virtual unsigned int append_attr(const string &name, const string &type, const string &value)
Add an attribute to the table.
virtual Attr_iter attr_begin()
void print_dap4(XMLWriter &xml)
virtual string get_name() const
Get the name of this attribute table.
void print_xml_writer(XMLWriter &xml)
virtual AttrType get_attr_type(const string &name)
Get the type of an attribute.
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 AttrTable & get_attr_table()
virtual string name() const
Returns the name of the class instance.
virtual void set_parent(BaseType *parent)
virtual D4Attributes * attributes()
virtual std::string FQN() const
virtual bool send_p()
Should this variable be sent?
virtual bool is_simple_type() const
Returns true if the instance is a numeric, string or URL type variable.
virtual BaseType * ptr_duplicate()=0
virtual void transform_to_dap4(D4Group *root, Constructor *container)
DAP2 to DAP4 transform.
virtual void transfer_attributes(AttrTable *at)
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
virtual Type type() const
Returns the type of the class instance.
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 dump(ostream &strm) const override
dumps information about this object
void transform_to_dap4(AttrTable &at)
copy attributes from DAP2 to DAP4
Array * array(D4Group *root)
This will always return the correct pointer for a valid data set.
A class for error processing.
Holds the Grid data type.
virtual BaseType * ptr_duplicate()
BaseType * array_var()
Returns the Grid Array.
virtual void transform_to_dap4(D4Group *root, Constructor *container)
DAP2 to DAP4 transform.
virtual void print_xml(ostream &out, string space=" ", bool constrained=false)
Map_iter map_begin()
Returns an iterator referencing the first Map vector.
Map_iter get_map_iter(int i)
virtual void set_array(Array *p_new_arr)
virtual void clear_constraint()
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
virtual void print_decl(ostream &out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false)
Print an ASCII representation of the variable structure.
virtual Array * prepend_map(Array *p_new_map, bool add_copy)
Grid(const string &n)
The Grid constructor.
Array * get_array()
Returns the Grid Array. This method returns the array using an Array*, so no cast is required.
virtual void transfer_attributes(AttrTable *at_container)
virtual bool projection_yields_grid()
virtual void dump(ostream &strm) const
dumps information about this object
virtual Array * add_map(Array *p_new_map, bool add_copy)
virtual int components(bool constrained=false)
Returns the number of components in the Grid object.
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
virtual bool check_semantics(string &msg, bool all=false)
Return true if this Grid is well formed.
virtual void add_var(BaseType *bt, Part part)
virtual void add_var_nocopy(BaseType *bt, Part part)
Map_riter map_rbegin()
Returns an iterator referencing the first Map vector.
virtual bool is_dap2_only_type()
A class for software fault reporting.
BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=nullptr) override
top level DAP object to house generic methods
Part
Names the parts of multi-section constructor data types.
string id2www(string in, const string &allowable)