48 #include "InternalErr.h" 50 #include "XDRStreamMarshaller.h" 53 #include "XMLWriter.h" 57 #include "D4Attributes.h" 64 Grid::m_duplicate(
const Grid &s)
72 d_is_array_set = s.d_is_array_set;
84 Grid::Grid(
const string &n) :
Constructor(n, dods_grid_c), d_is_array_set(false)
99 :
Constructor(n, d, dods_grid_c), d_is_array_set(false)
116 return new Grid(*
this);
120 Grid::operator=(
const Grid &rhs)
127 delete d_array_var; d_array_var = 0;
129 for (Map_iter i = d_map_vars.begin(); i != d_map_vars.end(); i++) {
135 dynamic_cast<Constructor &
>(*this) = rhs;
148 DBG(cerr << __func__ <<
"() - BEGIN (name:"<<
name() <<
150 ")(root:'"<< root->
name()<<
"':"<<(
void*)root <<
151 ")(container:'"<< container->
name()<<
"':"<< (
void *) container<<
")" 154 vector<Array*> d4_map_arrays;
163 DBG(cerr << __func__ <<
"() - Processing Map Array: '"<< (*i)->name() <<
"' ("<< (
void *)(*i)<<
")" << endl;);
169 Array *the_map_array;;
170 Array *container_map_array =
static_cast<Array*
>(container->
var((*i)->name()));
171 if(!container_map_array){
172 DBG(cerr << __func__ <<
"() - No Map Array '" << (*i)->name() <<
"' present in the current DAP4 container ("<<container->
name()<<
":"<<(
void*)container<<
"). Let's fix that..." << endl;);
174 Array *root_map_array =
static_cast<Array*
>(root->
var((*i)->name()));
175 if (!root_map_array) {
177 DBG(cerr << __func__ <<
"() - No Map Array '" << (*i)->name() <<
"' present in the root Group ("<<root->
name()<<
":"<<(
void*)root<<
"). Let's fix that..." << endl;);
179 (*i)->transform_to_dap4(root, container);
181 the_map_array =
static_cast<Array*
>(container->
var((*i)->name()));
182 DBG(cerr << __func__ <<
"() - Transformed array '"<< the_map_array->name() <<
183 "' to DAP4 Array (" << (
void *) the_map_array <<
") added to container: '"<<
184 container->
name() <<
"'" << endl;);
187 the_map_array = root_map_array;
188 DBG(cerr << __func__ <<
"() - Located Map Array '" << the_map_array->name() <<
"' (" <<
189 (
void *) the_map_array <<
") present in the root group ("<<root->
name()<<
":"<<(
void*)root <<
194 the_map_array = container_map_array;
195 DBG(cerr << __func__ <<
"() - Located Map Array '" << the_map_array->name() <<
"' (" <<
196 (
void *) the_map_array <<
") present in the current DAP4 container ("<<container->
name( )<<
":"<<
197 (
void*)container<<
")" << endl;);
200 d4_map_arrays.push_back(the_map_array);
208 DBG(cerr << __func__ <<
"() - Transformed and added DAP4 coverage Array '"<< coverage->
name() <<
209 "' to parent container: '" << container->
name() <<
"'" << endl;);
213 DBG(cerr << __func__ <<
"() - " <<
"Coverage Array '"<< coverage->
name() <<
"' attributes: " << endl;
216 cerr << xmlw.get_doc() << endl;);
219 vector<Array*>::iterator d4aItr=d4_map_arrays.begin();
220 vector<Array*>::iterator end=d4_map_arrays.end();
221 for( ; d4aItr!=end ; d4aItr++){
222 Array *the_map_array = *d4aItr;
225 D4Map *d4_map =
new D4Map(the_map_array->
FQN(), the_map_array, coverage);
226 coverage->maps()->
add_map(d4_map);
230 DBG(cerr << __func__ <<
"() - Added DAP4 Map Array: '"<< d4_map->name() <<
231 "' (" << (
void *) d4_map->array() <<
") to coverage: '" << coverage->
name() <<
"'" << endl;);
234 DBG(cerr << __func__ <<
"() - END (grid:" <<
name() <<
")" << endl;);
265 throw InternalErr(__FILE__, __LINE__,
"Passing NULL pointer as variable to be added.");
267 if (part == array && d_is_array_set) {
269 throw InternalErr(__FILE__, __LINE__,
"Error: Grid::add_var called with part==Array, but the array was already set!");
273 if (!dynamic_cast<Array*>(bt)) {
274 throw InternalErr(__FILE__, __LINE__,
"Grid::add_var(): object is not an Array!");
285 set_array(static_cast<Array*>(bt_clone));
292 d_vars.push_back(bt_clone);
297 if (!d_is_array_set) {
300 set_array(static_cast<Array*>(bt_clone));
305 d_vars.push_back(bt_clone);
331 throw InternalErr(__FILE__, __LINE__,
"Passing NULL pointer as variable to be added.");
333 if (part == array && d_is_array_set) {
335 throw InternalErr(__FILE__, __LINE__,
"Error: Grid::add_var called with part==Array, but the array was already set!");
339 if (!dynamic_cast<Array*>(bt)) {
340 throw InternalErr(__FILE__, __LINE__,
"Grid::add_var(): object is not an Array!");
356 d_vars.push_back(bt);
361 if (!d_is_array_set) {
367 d_vars.push_back(bt);
390 throw InternalErr(__FILE__, __LINE__,
"Grid::set_array(): Cannot set to null!");
404 if (d_vars.size() == 0) {
405 d_vars.push_back(p_new_arr);
407 else if (!d_is_array_set) {
408 d_vars.insert(d_vars.begin(), p_new_arr);
413 d_vars[0] = p_new_arr;
416 d_is_array_set =
true;
419 d_array_var = p_new_arr;
456 throw InternalErr(__FILE__, __LINE__,
"Grid::add_map(): cannot have p_new_map null!");
463 d_vars.push_back(p_new_map);
505 cerr <<
"In array_var(), d_array_var holds a " << d_array_var->
type_name() << endl;
507 cerr <<
"In array_var(), d_array_var is null" << endl;
509 return d_is_array_set ? *d_vars.begin() : 0;
529 return d_is_array_set ? d_vars.begin() + 1: d_vars.begin();
546 return d_vars.rbegin();
554 return d_is_array_set ? d_vars.rend() - 1: d_vars.rend();
591 if ((*i)->send_p()) {
597 comp = d_vars.size();
605 DBG( cerr << __func__ <<
"() - BEGIN "<<
type_name() <<
" " <<
name() <<
" (at_container:"<< at_container->
get_name() <<
":"<<(
void*)at_container<<
")" << endl;);
610 DBG( cerr << __func__ <<
"() - Found AttrTable ("<< at->get_name() <<
":" << (
void*)at<<
")" << endl;);
611 at->set_is_global_attribute(
false);
626 dvat->set_is_global_attribute(
false);
631 DBG( cerr << __func__ <<
"() - Processing Map Array ("<< (*map)->name() <<
":" << (
void*)(*map)<<
")" << endl;);
632 (*map)->transfer_attributes(at);
639 AttrTable::Attr_iter at_p = at->attr_begin();
640 while (at_p != at->attr_end()) {
641 if (at->is_global_attribute(at_p)) {
642 DBG( cerr << __func__ <<
"() - " <<
643 "Adding unclaimed Attribute ("<<
644 at->get_type(at_p)<<
":" << at->get_name(at_p) <<
":" << (
void*)(*map)<<
645 ") from AttrTable (" << at->get_name() <<
":" << (
void*)at <<
")" <<
646 " to the variable " <<
type_name() <<
" " <<
name() << endl;);
648 if (at->get_attr_type(at_p) == Attr_container)
658 DBG( cerr << __func__ <<
"() - No AttrTable named '"<<
name() <<
"' was found in at_container ("<<at_container->
get_name()<<
":" << (
void*)at<<
")" << endl;);
660 DBG( cerr << __func__ <<
"() - END "<<
type_name() <<
" " <<
name() <<
" (at_container:"<< at_container->
get_name() <<
":"<<(
void*)at_container<<
")" << endl;);
736 bool constraint_info,
bool constrained)
739 print_decl(oss, space, print_semi, constraint_info, constrained);
740 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
745 bool constraint_info,
bool constrained)
747 if (constrained && !
send_p())
752 out << space <<
"Structure {\n" ;
758 (*i)->print_decl(out, space +
" ",
true,
759 constraint_info, constrained);
769 out << space <<
" Array:\n" ;
773 out << space <<
" Maps:\n" ;
775 (*i)->print_decl(out, space +
" ",
true,
776 constraint_info, constrained);
782 if (constraint_info) {
784 out <<
": Send True";
786 out <<
": Send False";
803 fwrite(xml.get_doc(),
sizeof(char), xml.get_doc_size(), out);
814 out << xml.get_doc();
818 class PrintGridFieldXMLWriter :
public unary_function<BaseType *, void>
824 PrintGridFieldXMLWriter(
XMLWriter &x,
bool c,
const string &t =
"Map")
825 : d_xml(x), d_constrained(c), d_tag(t)
828 void operator()(BaseType *btp)
830 Array *a =
dynamic_cast<Array*
>(btp);
832 throw InternalErr(__FILE__, __LINE__,
"Expected an Array.");
833 a->print_xml_writer_core(d_xml, d_constrained, d_tag);
840 if (constrained && !
send_p())
844 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Structure") < 0)
845 throw InternalErr(__FILE__, __LINE__,
"Could not write Structure element");
848 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
849 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
856 PrintGridFieldXMLWriter(xml, constrained,
"Array"));
858 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
859 throw InternalErr(__FILE__, __LINE__,
"Could not end Structure element");
864 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Grid") < 0)
865 throw InternalErr(__FILE__, __LINE__,
"Could not write Grid element");
868 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
869 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
876 PrintGridFieldXMLWriter(xml, constrained,
"Map"));
878 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
879 throw InternalErr(__FILE__, __LINE__,
"Could not end Grid element");
888 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
910 if (pyg || !
send_p()) out <<
" Maps: ";
913 (*i)->print_val(out,
"",
false);
918 if (print_decl_p) out <<
";\n";
936 msg +=
"Null grid base array in `" +
name() +
"'\n";
942 msg +=
"Grid `" +
name() +
"'s' member `" +
get_array()->
name() +
"' must be an array\n";
950 msg +=
"The field variable `" + this->
name() +
"' must be an array of simple type elements (e.g., int32, String)\n";
955 if ((
unsigned)d_vars.size()-1 != av->
dimensions()) {
956 msg +=
"The number of map variables for grid `" + this->
name() +
"' does not match the number of dimensions of `";
957 msg += av->
name() +
"'\n";
961 const string array_var_name = av->
name();
968 if (array_var_name == mv->
name()) {
969 msg +=
"Grid map variable `" + mv->
name() +
"' conflicts with the grid array name in grid `" +
name() +
"'\n";
973 if (mv->
type() != dods_array_c) {
974 msg +=
"Grid map variable `" + mv->
name() +
"' is not an array\n";
982 msg +=
"The field variable `" + this->
name() +
"' must be an array of simple type elements (e.g., int32, String)\n";
988 msg +=
"Grid map variable `" + mv_a->
name() +
"' must be only one dimension\n";
995 if (mv_a_size != av_size) {
996 msg +=
"Grid map variable `" + mv_a->
name() +
"'s' size does not match the size of array variable '";
997 msg +=
get_array()->
name() +
"'s' cooresponding dimension\n";
1006 if (!(*mvi)->check_semantics(msg,
true)) {
1026 strm << DapIndent::LMarg <<
"Grid::dump - (" 1027 << (
void *)
this <<
")" << endl ;
1028 DapIndent::Indent() ;
1031 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)
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.
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.