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;
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;);
200 vector<Array*>::iterator d4aItr=d4_map_arrays.begin();
201 vector<Array*>::iterator end=d4_map_arrays.end();
202 for( ; d4aItr!=end ; d4aItr++){
203 Array *the_map_array = *d4aItr;
206 D4Map *d4_map =
new D4Map(the_map_array->
FQN(), the_map_array, coverage);
207 coverage->maps()->
add_map(d4_map);
211 DBG(cerr << __func__ <<
"() - Added DAP4 Map Array: '"<< d4_map->name() <<
212 "' (" << (
void *) d4_map->array() <<
") to coverage: '" << coverage->
name() <<
"'" << endl;);
215 DBG(cerr << __func__ <<
"() - END (grid:" <<
name() <<
")" << endl;);
246 throw InternalErr(__FILE__, __LINE__,
"Passing NULL pointer as variable to be added.");
248 if (part == array && d_is_array_set) {
250 throw InternalErr(__FILE__, __LINE__,
"Error: Grid::add_var called with part==Array, but the array was already set!");
254 if (!
dynamic_cast<Array*
>(bt)) {
255 throw InternalErr(__FILE__, __LINE__,
"Grid::add_var(): object is not an Array!");
273 d_vars.push_back(bt_clone);
278 if (!d_is_array_set) {
286 d_vars.push_back(bt_clone);
312 throw InternalErr(__FILE__, __LINE__,
"Passing NULL pointer as variable to be added.");
314 if (part == array && d_is_array_set) {
316 throw InternalErr(__FILE__, __LINE__,
"Error: Grid::add_var called with part==Array, but the array was already set!");
320 if (!
dynamic_cast<Array*
>(bt)) {
321 throw InternalErr(__FILE__, __LINE__,
"Grid::add_var(): object is not an Array!");
337 d_vars.push_back(bt);
342 if (!d_is_array_set) {
348 d_vars.push_back(bt);
371 throw InternalErr(__FILE__, __LINE__,
"Grid::set_array(): Cannot set to null!");
385 if (d_vars.size() == 0) {
386 d_vars.push_back(p_new_arr);
388 else if (!d_is_array_set) {
389 d_vars.insert(d_vars.begin(), p_new_arr);
394 d_vars[0] = p_new_arr;
397 d_is_array_set =
true;
400 d_array_var = p_new_arr;
437 throw InternalErr(__FILE__, __LINE__,
"Grid::add_map(): cannot have p_new_map null!");
444 d_vars.push_back(p_new_map);
482 return d_is_array_set ? *d_vars.begin() :
nullptr;
502 return d_is_array_set ? d_vars.begin() + 1: d_vars.begin();
518 return d_vars.rbegin();
526 return d_is_array_set ? d_vars.rend() - 1: d_vars.rend();
535 return d_is_array_set ? d_vars.begin() + 1 + i : d_vars.begin() + i;
562 if ((*i)->send_p()) {
568 comp = d_vars.size();
581 DBG( cerr << __func__ <<
"() - BEGIN "<<
type_name() <<
" " <<
name() <<
" (at_container:"<< at_container->
get_name() <<
":"<<(
void*)at_container<<
")" << endl;);
586 DBG( cerr << __func__ <<
"() - Found AttrTable ("<< at->
get_name() <<
":" << (
void*)at<<
")" << endl;);
587 at->set_is_global_attribute(
false);
605 dvat->set_is_global_attribute(
false);
610 (*map)->transfer_attributes(at);
619 if (at->is_global_attribute(at_p)) {
620 DBG( cerr << __func__ <<
"() - " <<
621 "Adding unclaimed Attribute ("<<
623 ") from AttrTable (" << at->
get_name() <<
":" << (
void*)at <<
")" <<
624 " to the variable " <<
type_name() <<
" " <<
name() << endl;);
636 DBG( cerr << __func__ <<
"() - No AttrTable named '"<<
name() <<
"' was found in at_container ("<<at_container->
get_name()<<
":" << (
void*)at<<
")" << endl;);
638 DBG( cerr << __func__ <<
"() - END "<<
type_name() <<
" " <<
name() <<
" (at_container:"<< at_container->
get_name() <<
":"<<(
void*)at_container<<
")" << endl;);
714 bool constraint_info,
bool constrained)
717 print_decl(oss, space, print_semi, constraint_info, constrained);
718 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
723 bool constraint_info,
bool constrained)
725 if (constrained && !
send_p())
730 out << space <<
"Structure {\n" ;
736 (*i)->print_decl(out, space +
" ",
true,
737 constraint_info, constrained);
747 out << space <<
" Array:\n" ;
751 out << space <<
" Maps:\n" ;
753 (*i)->print_decl(out, space +
" ",
true,
754 constraint_info, constrained);
760 if (constraint_info) {
762 out <<
": Send True";
764 out <<
": Send False";
781 fwrite(xml.get_doc(),
sizeof(
char), xml.get_doc_size(), out);
792 out << xml.get_doc();
796class PrintGridFieldXMLWriter :
public unary_function<BaseType *, void>
802 PrintGridFieldXMLWriter(
XMLWriter &x,
bool c,
const string &t =
"Map")
803 : d_xml(x), d_constrained(c), d_tag(t)
806 void operator()(BaseType *btp)
808 Array *a =
dynamic_cast<Array*
>(btp);
810 throw InternalErr(__FILE__, __LINE__,
"Expected an Array.");
811 a->print_xml_writer_core(d_xml, d_constrained, d_tag);
818 if (constrained && !
send_p())
822 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Structure") < 0)
823 throw InternalErr(__FILE__, __LINE__,
"Could not write Structure element");
826 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
827 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
834 PrintGridFieldXMLWriter(xml, constrained,
"Array"));
836 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
837 throw InternalErr(__FILE__, __LINE__,
"Could not end Structure element");
842 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Grid") < 0)
843 throw InternalErr(__FILE__, __LINE__,
"Could not write Grid element");
846 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
847 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
854 PrintGridFieldXMLWriter(xml, constrained,
"Map"));
856 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
857 throw InternalErr(__FILE__, __LINE__,
"Could not end Grid element");
866 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
888 if (pyg || !
send_p()) out <<
" Maps: ";
891 (*i)->print_val(out,
"",
false);
896 if (print_decl_p) out <<
";\n";
914 msg +=
"Null grid base array in `" +
name() +
"'\n";
920 msg +=
"Grid `" +
name() +
"'s' member `" +
get_array()->
name() +
"' must be an array\n";
928 msg +=
"The field variable `" + this->
name() +
"' must be an array of simple type elements (e.g., int32, String)\n";
933 if ((
unsigned)d_vars.size()-1 != av->
dimensions()) {
934 msg +=
"The number of map variables for grid `" + this->
name() +
"' does not match the number of dimensions of `";
935 msg += av->
name() +
"'\n";
939 const string array_var_name = av->
name();
946 if (array_var_name == mv->
name()) {
947 msg +=
"Grid map variable `" + mv->
name() +
"' conflicts with the grid array name in grid `" +
name() +
"'\n";
951 if (mv->
type() != dods_array_c) {
952 msg +=
"Grid map variable `" + mv->
name() +
"' is not an array\n";
960 msg +=
"The field variable `" + this->
name() +
"' must be an array of simple type elements (e.g., int32, String)\n";
966 msg +=
"Grid map variable `" + mv_a->
name() +
"' must be only one dimension\n";
973 if (mv_a_size != av_size) {
974 msg +=
"Grid map variable `" + mv_a->
name() +
"'s' size does not match the size of array variable '";
975 msg +=
get_array()->
name() +
"'s' cooresponding dimension\n";
984 if (!(*mvi)->check_semantics(msg,
true)) {
1004 strm << DapIndent::LMarg <<
"Grid::dump - ("
1005 << (
void *)
this <<
")" << endl ;
1006 DapIndent::Indent() ;
1009 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 BaseType * ptr_duplicate()
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)
Prints a DDS entry for the Array.
std::vector< dimension >::iterator Dim_iter
virtual int dimension_size(Dim_iter i, bool constrained=false)
Returns the size of the dimension.
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
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
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.
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
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)