48 #include "InternalErr.h" 50 #include "XDRStreamMarshaller.h" 53 #include "XMLWriter.h" 57 #include "D4Attributes.h" 59 #include "DapIndent.h" 66 Grid::m_duplicate(
const Grid &s)
74 d_is_array_set = s.d_is_array_set;
86 Grid::Grid(
const string &n) :
Constructor(n, dods_grid_c), d_is_array_set(false)
101 :
Constructor(n, d, dods_grid_c), d_is_array_set(false)
118 return new Grid(*
this);
122 Grid::operator=(
const Grid &rhs)
129 delete d_array_var; d_array_var = 0;
131 for (Map_iter i = d_map_vars.begin(); i != d_map_vars.end(); i++) {
150 DBG(cerr << __func__ <<
"() - BEGIN (name:"<<
name() <<
152 ")(root:'"<< root->
name()<<
"':"<<(
void*)root <<
153 ")(container:'"<< container->
name()<<
"':"<< (
void *) container<<
")" 156 vector<Array*> d4_map_arrays;
165 DBG(cerr << __func__ <<
"() - Processing Map Array: '"<< (*i)->name() <<
"' ("<< (
void *)(*i)<<
")" << endl;);
171 Array *the_map_array;;
172 Array *container_map_array =
static_cast<Array*
>(container->
var((*i)->name()));
173 if(!container_map_array){
174 DBG(cerr << __func__ <<
"() - No Map Array '" << (*i)->name() <<
"' present in the current DAP4 container ("<<container->
name()<<
":"<<(
void*)container<<
"). Let's fix that..." << endl;);
176 Array *root_map_array =
static_cast<Array*
>(root->
var((*i)->name()));
177 if (!root_map_array) {
179 DBG(cerr << __func__ <<
"() - No Map Array '" << (*i)->name() <<
"' present in the root Group ("<<root->
name()<<
":"<<(
void*)root<<
"). Let's fix that..." << endl;);
181 (*i)->transform_to_dap4(root, container);
183 the_map_array =
static_cast<Array*
>(container->
var((*i)->name()));
184 DBG(cerr << __func__ <<
"() - Transformed array '"<< the_map_array->name() <<
185 "' to DAP4 Array (" << (
void *) the_map_array <<
") added to container: '"<<
186 container->
name() <<
"'" << endl;);
189 the_map_array = root_map_array;
190 DBG(cerr << __func__ <<
"() - Located Map Array '" << the_map_array->name() <<
"' (" <<
191 (
void *) the_map_array <<
") present in the root group ("<<root->
name()<<
":"<<(
void*)root <<
196 the_map_array = container_map_array;
197 DBG(cerr << __func__ <<
"() - Located Map Array '" << the_map_array->name() <<
"' (" <<
198 (
void *) the_map_array <<
") present in the current DAP4 container ("<<container->
name( )<<
":"<<
199 (
void*)container<<
")" << endl;);
202 d4_map_arrays.push_back(the_map_array);
210 DBG(cerr << __func__ <<
"() - Transformed and added DAP4 coverage Array '"<< coverage->
name() <<
211 "' to parent container: '" << container->
name() <<
"'" << endl;);
215 DBG(cerr << __func__ <<
"() - " <<
"Coverage Array '"<< coverage->
name() <<
"' attributes: " << endl;
218 cerr << xmlw.get_doc() << endl;);
221 vector<Array*>::iterator d4aItr=d4_map_arrays.begin();
222 vector<Array*>::iterator end=d4_map_arrays.end();
223 for( ; d4aItr!=end ; d4aItr++){
224 Array *the_map_array = *d4aItr;
227 D4Map *d4_map =
new D4Map(the_map_array->
FQN(), the_map_array, coverage);
228 coverage->maps()->
add_map(d4_map);
232 DBG(cerr << __func__ <<
"() - Added DAP4 Map Array: '"<< d4_map->name() <<
233 "' (" << (
void *) d4_map->array() <<
") to coverage: '" << coverage->
name() <<
"'" << endl;);
236 DBG(cerr << __func__ <<
"() - END (grid:" <<
name() <<
")" << endl;);
267 throw InternalErr(__FILE__, __LINE__,
"Passing NULL pointer as variable to be added.");
269 if (part == array && d_is_array_set) {
271 throw InternalErr(__FILE__, __LINE__,
"Error: Grid::add_var called with part==Array, but the array was already set!");
275 if (!dynamic_cast<Array*>(bt)) {
276 throw InternalErr(__FILE__, __LINE__,
"Grid::add_var(): object is not an Array!");
287 set_array(static_cast<Array*>(bt_clone));
294 d_vars.push_back(bt_clone);
299 if (!d_is_array_set) {
302 set_array(static_cast<Array*>(bt_clone));
307 d_vars.push_back(bt_clone);
333 throw InternalErr(__FILE__, __LINE__,
"Passing NULL pointer as variable to be added.");
335 if (part == array && d_is_array_set) {
337 throw InternalErr(__FILE__, __LINE__,
"Error: Grid::add_var called with part==Array, but the array was already set!");
341 if (!dynamic_cast<Array*>(bt)) {
342 throw InternalErr(__FILE__, __LINE__,
"Grid::add_var(): object is not an Array!");
358 d_vars.push_back(bt);
363 if (!d_is_array_set) {
369 d_vars.push_back(bt);
392 throw InternalErr(__FILE__, __LINE__,
"Grid::set_array(): Cannot set to null!");
406 if (d_vars.size() == 0) {
407 d_vars.push_back(p_new_arr);
409 else if (!d_is_array_set) {
410 d_vars.insert(d_vars.begin(), p_new_arr);
415 d_vars[0] = p_new_arr;
418 d_is_array_set =
true;
421 d_array_var = p_new_arr;
458 throw InternalErr(__FILE__, __LINE__,
"Grid::add_map(): cannot have p_new_map null!");
465 d_vars.push_back(p_new_map);
507 cerr <<
"In array_var(), d_array_var holds a " << d_array_var->
type_name() << endl;
509 cerr <<
"In array_var(), d_array_var is null" << endl;
511 return d_is_array_set ? *d_vars.begin() : 0;
531 return d_is_array_set ? d_vars.begin() + 1: d_vars.begin();
548 return d_vars.rbegin();
556 return d_is_array_set ? d_vars.rend() - 1: d_vars.rend();
593 if ((*i)->send_p()) {
599 comp = d_vars.size();
612 DBG( cerr << __func__ <<
"() - BEGIN "<<
type_name() <<
" " <<
name() <<
" (at_container:"<< at_container->
get_name() <<
":"<<(
void*)at_container<<
")" << endl;);
617 DBG( cerr << __func__ <<
"() - Found AttrTable ("<< at->get_name() <<
":" << (
void*)at<<
")" << endl;);
618 at->set_is_global_attribute(
false);
636 dvat->set_is_global_attribute(
false);
641 (*map)->transfer_attributes(at);
648 AttrTable::Attr_iter at_p = at->attr_begin();
649 while (at_p != at->attr_end()) {
650 if (at->is_global_attribute(at_p)) {
651 DBG( cerr << __func__ <<
"() - " <<
652 "Adding unclaimed Attribute ("<<
653 at->get_type(at_p)<<
":" << at->get_name(at_p) <<
":" << (
void*)(*map)<<
654 ") from AttrTable (" << at->get_name() <<
":" << (
void*)at <<
")" <<
655 " to the variable " <<
type_name() <<
" " <<
name() << endl;);
657 if (at->get_attr_type(at_p) == Attr_container)
667 DBG( cerr << __func__ <<
"() - No AttrTable named '"<<
name() <<
"' was found in at_container ("<<at_container->
get_name()<<
":" << (
void*)at<<
")" << endl;);
669 DBG( cerr << __func__ <<
"() - END "<<
type_name() <<
" " <<
name() <<
" (at_container:"<< at_container->
get_name() <<
":"<<(
void*)at_container<<
")" << endl;);
745 bool constraint_info,
bool constrained)
748 print_decl(oss, space, print_semi, constraint_info, constrained);
749 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
754 bool constraint_info,
bool constrained)
756 if (constrained && !
send_p())
761 out << space <<
"Structure {\n" ;
767 (*i)->print_decl(out, space +
" ",
true,
768 constraint_info, constrained);
778 out << space <<
" Array:\n" ;
782 out << space <<
" Maps:\n" ;
784 (*i)->print_decl(out, space +
" ",
true,
785 constraint_info, constrained);
791 if (constraint_info) {
793 out <<
": Send True";
795 out <<
": Send False";
812 fwrite(xml.get_doc(),
sizeof(char), xml.get_doc_size(), out);
823 out << xml.get_doc();
827 class PrintGridFieldXMLWriter :
public unary_function<BaseType *, void>
833 PrintGridFieldXMLWriter(
XMLWriter &x,
bool c,
const string &t =
"Map")
834 : d_xml(x), d_constrained(c), d_tag(t)
841 throw InternalErr(__FILE__, __LINE__,
"Expected an Array.");
842 a->print_xml_writer_core(d_xml, d_constrained, d_tag);
849 if (constrained && !
send_p())
853 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Structure") < 0)
854 throw InternalErr(__FILE__, __LINE__,
"Could not write Structure element");
857 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
858 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
865 PrintGridFieldXMLWriter(xml, constrained,
"Array"));
867 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
868 throw InternalErr(__FILE__, __LINE__,
"Could not end Structure element");
873 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Grid") < 0)
874 throw InternalErr(__FILE__, __LINE__,
"Could not write Grid element");
877 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
878 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
885 PrintGridFieldXMLWriter(xml, constrained,
"Map"));
887 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
888 throw InternalErr(__FILE__, __LINE__,
"Could not end Grid element");
897 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
919 if (pyg || !
send_p()) out <<
" Maps: ";
922 (*i)->print_val(out,
"",
false);
927 if (print_decl_p) out <<
";\n";
945 msg +=
"Null grid base array in `" +
name() +
"'\n";
951 msg +=
"Grid `" +
name() +
"'s' member `" +
get_array()->
name() +
"' must be an array\n";
959 msg +=
"The field variable `" + this->
name() +
"' must be an array of simple type elements (e.g., int32, String)\n";
964 if ((
unsigned)d_vars.size()-1 != av->
dimensions()) {
965 msg +=
"The number of map variables for grid `" + this->
name() +
"' does not match the number of dimensions of `";
966 msg += av->
name() +
"'\n";
970 const string array_var_name = av->
name();
977 if (array_var_name == mv->
name()) {
978 msg +=
"Grid map variable `" + mv->
name() +
"' conflicts with the grid array name in grid `" +
name() +
"'\n";
982 if (mv->
type() != dods_array_c) {
983 msg +=
"Grid map variable `" + mv->
name() +
"' is not an array\n";
991 msg +=
"The field variable `" + this->
name() +
"' must be an array of simple type elements (e.g., int32, String)\n";
997 msg +=
"Grid map variable `" + mv_a->
name() +
"' must be only one dimension\n";
1004 if (mv_a_size != av_size) {
1005 msg +=
"Grid map variable `" + mv_a->
name() +
"'s' size does not match the size of array variable '";
1006 msg +=
get_array()->
name() +
"'s' cooresponding dimension\n";
1015 if (!(*mvi)->check_semantics(msg,
true)) {
1035 strm << DapIndent::LMarg <<
"Grid::dump - (" 1036 << (
void *)
this <<
")" << endl ;
1037 DapIndent::Indent() ;
1040 DapIndent::UnIndent() ;
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
virtual string name() const
Returns the name of the class instance.
virtual unsigned int dimensions(bool constrained=false)
Return the total number of dimensions in the array.
virtual Array * prepend_map(Array *p_new_map, bool add_copy)
virtual void add_var_nocopy(BaseType *bt, Part part)
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())
Part
Names the parts of multi-section constructor data types.
Contains the attributes for a dataset.
virtual void print_xml(ostream &out, string space=" ", bool constrained=false)
virtual string get_name() const
Get the name of this attribute table.
virtual void dump(ostream &strm) const
dumps information about this object
void print_xml_writer(XMLWriter &xml)
virtual bool is_simple_type() const
Returns true if the instance is a numeric, string or URL type variable.
virtual void set_parent(BaseType *parent)
top level DAP object to house generic methods
void print_dap4(XMLWriter &xml)
A class for software fault reporting.
virtual std::string FQN() const
virtual int components(bool constrained=false)
Returns the number of components in the Grid object.
Map_riter map_rbegin()
Returns an iterator referencing the first Map vector.
virtual void set_array(Array *p_new_arr)
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
virtual bool projection_yields_grid()
Map_iter map_begin()
Returns an iterator referencing the first Map vector.
virtual int dimension_size(Dim_iter i, bool constrained=false)
Returns the size of the dimension.
virtual BaseType * ptr_duplicate()
Map_iter get_map_iter(int i)
virtual void add_var(BaseType *bt, Part part)
virtual AttrTable * append_container(const string &name)
Add a container to the attribute table.
virtual void transfer_attributes(AttrTable *at_container)
virtual void clear_constraint()
virtual AttrTable * get_attr_table(const string &name)
Get an attribute container.
virtual Type type() const
Returns the type of the class instance.
std::vector< dimension >::iterator Dim_iter
virtual BaseType * ptr_duplicate()
virtual int dimension_stride(Dim_iter i, bool constrained=false)
Returns the stride value of the constraint.
Holds the Grid data type.
virtual void transform_to_dap4(D4Group *root, Constructor *container)
DAP2 to DAP4 transform.
virtual void print_decl(ostream &out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false)
Prints a DDS entry for the Array.
virtual D4Attributes * attributes()
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
virtual Array * add_map(Array *p_new_map, bool add_copy)
Array * get_array()
Returns the Grid Array. This method returns the array using an Array*, so no cast is required...
virtual void dump(ostream &strm) const
dumps information about this object
virtual bool is_dap2_only_type()
virtual BaseType * ptr_duplicate()=0
virtual int dimension_stop(Dim_iter i, bool constrained=false)
Return the stop index of the constraint.
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 int dimension_start(Dim_iter i, bool constrained=false)
Return the start index of a dimension.
virtual AttrTable & get_attr_table()
virtual unsigned int append_attr(const string &name, const string &type, const string &value)
Add an attribute to the table.
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 bool check_semantics(string &msg, bool all=false)
Return true if this Grid is well formed.
virtual void transform_to_dap4(D4Group *root, Constructor *container)
DAP2 to DAP4 transform.
BaseType * array_var()
Returns the Grid Array.
virtual void transfer_attributes(AttrTable *at)
void transform_to_dap4(AttrTable &at)
copy attributes from DAP2 to DAP4
A multidimensional array of identical data types.
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
virtual bool send_p()
Should this variable be sent?
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
Grid(const string &n)
The Grid constructor.
string id2www(string in, const string &allowable)
virtual void clear_constraint()
Clears the projection; add each projected dimension explicitly using add_constraint.
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.