54 Array::_duplicate(
const Array &a)
72 Array::update_length(
int)
75 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
76 length *= (*i).c_size > 0 ? (*i).c_size : 1;
133 DBG(cerr <<
"Entering ~Array (" <<
this <<
")" << endl);
134 DBG(cerr <<
"Exiting ~Array" << endl);
140 return new Array(*
this);
149 dynamic_cast<Vector &
>(*this) = rhs;
265 _shape.insert(_shape.begin(), d);
281 for (
Dim_iter i = _shape.begin(); i != _shape.end(); i++) {
283 (*i).stop = (*i).size - 1;
285 (*i).c_size = (*i).size;
309 static const char *array_sss = \
310 "Invalid constraint parameters: At least one of the start, stride or stop \n\
311 specified do not match the array variable.";
341 if (start >= d.
size || stop >= d.
size || stride > d.
size || stride <= 0)
344 if (((stop - start) / stride + 1) > d.
size)
351 d.
c_size = (stop - start) / stride + 1;
353 DBG(cerr <<
"add_constraint: c_size = " << d.
c_size << endl);
362 return _shape.begin() ;
369 return _shape.end() ;
384 unsigned int dim = 0;
385 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
414 if (!_shape.empty()) {
445 return (!_shape.empty()) ? (*i).start : 0;
469 return (!_shape.empty()) ? (*i).stop : 0;
494 return (!_shape.empty()) ? (*i).stride : 0;
517 "*This* array has no dimensions.");
535 for (
Dim_iter i = _shape.begin(); i != _shape.end(); i++) {
538 return length *
var()->
width(
false);
563 bool constraint_info,
bool constrained)
565 if (constrained && !
send_p())
569 var()->
print_decl(out, space,
false, constraint_info, constrained);
571 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
573 if ((*i).name !=
"") {
574 fprintf(out,
"%s = ",
id2www((*i).name).c_str()) ;
577 fprintf(out,
"%d]", (*i).c_size) ;
580 fprintf(out,
"%d]", (*i).size) ;
585 fprintf(out,
";\n") ;
609 bool constraint_info,
bool constrained)
611 if (constrained && !
send_p())
615 var()->
print_decl(out, space,
false, constraint_info, constrained);
617 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
619 if ((*i).name !=
"") {
620 out <<
id2www((*i).name) <<
" = " ;
623 out << (*i).c_size <<
"]" ;
626 out << (*i).size <<
"]" ;
675 class PrintArrayDim :
public unary_function<Array::dimension&, void>
681 PrintArrayDim(FILE *o,
string s,
bool c)
682 : d_out(o), d_space(s), d_constrained(c)
685 void operator()(Array::dimension &d)
687 int size = d_constrained ? d.c_size : d.size;
689 fprintf(d_out,
"%s<dimension size=\"%d\"/>\n", d_space.c_str(),
692 fprintf(d_out,
"%s<dimension name=\"%s\" size=\"%d\"/>\n",
693 d_space.c_str(),
id2xml(d.name).c_str(), size);
703 if (constrained && !
send_p())
706 fprintf(out,
"%s<%s", space.c_str(), tag.c_str());
708 fprintf(out,
" name=\"%s\"",
id2xml(
name()).c_str());
709 fprintf(out ,
">\n");
714 string tmp_name = btp->
name();
716 btp->
print_xml(out, space +
" ", constrained);
720 PrintArrayDim(out, space +
" ", constrained));
722 fprintf(out,
"%s</%s>\n", space.c_str(), tag.c_str());
726 class PrintArrayDimStrm :
public unary_function<Array::dimension&, void>
732 PrintArrayDimStrm(ostream &o,
string s,
bool c)
733 : d_out(o), d_space(s), d_constrained(c)
736 void operator()(Array::dimension &d)
738 int size = d_constrained ? d.c_size : d.size;
740 d_out << d_space <<
"<dimension size=\"" << size <<
"\"/>\n" ;
742 d_out << d_space <<
"<dimension name=\"" <<
id2xml(d.name)
743 <<
"\" size=\"" << size <<
"\"/>\n" ;
753 if (constrained && !
send_p())
756 out << space <<
"<" << tag;
764 string tmp_name = btp->
name();
766 btp->
print_xml(out, space +
" ", constrained);
769 for_each(
dim_begin(),
dim_end(), PrintArrayDimStrm(out, space +
" ", constrained));
771 out << space <<
"</" << tag <<
">\n";
786 class PrintArrayDimXMLWriter :
public unary_function<Array::dimension&, void>
791 PrintArrayDimXMLWriter(
XMLWriter &xml,
bool c) : xml(xml), d_constrained(c) {}
793 void operator()(Array::dimension &d)
795 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"dimension") < 0)
796 throw InternalErr(__FILE__, __LINE__,
"Could not write dimension element");
799 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d.name.c_str()) < 0)
800 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
803 size << (d_constrained ? d.c_size : d.size);
804 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"size", (
const xmlChar*)size.str().c_str()) < 0)
805 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
807 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
808 throw InternalErr(__FILE__, __LINE__,
"Could not end dimension element");
815 if (constrained && !
send_p())
818 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar*)tag.c_str()) < 0)
819 throw InternalErr(__FILE__, __LINE__,
"Could not write " + tag +
" element");
822 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
823 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
828 string tmp_name = btp->
name();
835 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
836 throw InternalErr(__FILE__, __LINE__,
"Could not end " + tag +
" element");
853 unsigned int shape[])
857 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
874 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
875 index =
print_array(out, index, dims - 1, shape + 1);
878 index =
print_array(out, index, dims - 1, shape + 1);
899 unsigned int shape[])
903 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
920 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
921 index =
print_array(out, index, dims - 1, shape + 1);
924 index =
print_array(out, index, dims - 1, shape + 1);
943 fprintf(out,
" = ") ;
946 unsigned int *shape =
new unsigned int[_shape.size()];
947 unsigned int index = 0;
948 for (
Dim_iter i = _shape.begin(); i != _shape.end() && index < _shape.size(); i++)
953 delete [] shape; shape = 0;
956 fprintf(out,
";\n") ;
975 unsigned int *shape =
new unsigned int[
dimensions(
true)];
976 unsigned int index = 0;
982 delete [] shape; shape = 0;
1004 msg =
"An array variable must have dimensions";
1021 << (
void *)
this <<
")" << endl ;
1028 unsigned int dim_num = 0 ;
1029 for (; i != ie; i++) {
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
virtual void reset_constraint()
Reset constraint to select entire array.
virtual void add_constraint(Dim_iter i, int start, int stride, int stop)
Adds a constraint to an Array dimension.
virtual bool check_semantics(string &msg, bool all=false)
Check semantic features of the Array.
virtual void print_xml_core(FILE *out, string space, bool constrained, string tag)
virtual void add_var_nocopy(BaseType *v, Part p=nil)
virtual void print_decl(FILE *out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false)
Print an ASCII representation of the variable structure.
virtual unsigned int dimensions(bool constrained=false)
Return the total number of dimensions in the array.
virtual void print_xml(FILE *out, string space=" ", bool constrained=false)
Part
Names the parts of multi-section constructor data types.
void add_var(BaseType *v, Part p=nil)
Add the BaseType pointer to this constructor type instance.
virtual void set_name(const string &n)
Sets the name of the class instance.
int stop
The constraint end index.
Holds a one-dimensional collection of DAP2 data types.
virtual void dump(ostream &strm) const
dumps information about this object
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
virtual int length() const
std::vector< dimension >::const_iterator Dim_citer
virtual void print_xml(FILE *out, string pad=" ", bool constrained=false)
int start
The constraint start index.
string id2xml(string in, const string ¬_allowed)
Array & operator=(const Array &rhs)
virtual void add_var(BaseType *v, Part p=nil)
Add the BaseType pointer to this constructor type instance.
virtual unsigned int width()=0
Returns the size of the class instance data.
void print_xml_writer(XMLWriter &xml)
Type type() const
Returns the type of the class instance.
void _duplicate(const Array &a)
A class for software fault reporting.
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
xmlTextWriterPtr get_writer()
virtual void print_as_map_xml(ostream &out, string space=" ", bool constrained=false)
virtual int dimension_size(Dim_iter i, bool constrained=false)
Returns the size of the dimension.
void append_dim(int size, string name="")
Add a dimension of a given size.
std::vector< dimension >::iterator Dim_iter
virtual string dimension_name(Dim_iter i)
Returns the name of the specified dimension.
virtual BaseType * ptr_duplicate()
virtual int dimension_stride(Dim_iter i, bool constrained=false)
Returns the stride value of the constraint.
int stride
The constraint stride.
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.
int c_size
Size of dimension once constrained.
virtual void print_as_map_xml_writer(XMLWriter &xml, bool constrained)
void prepend_dim(int size, const string &name="")
string name() const
Returns the name of the class instance.
virtual void print_xml(ostream &out, string space=" ", bool constrained=false)
Array(const string &n, BaseType *v)
Array constructor.
string www2id(const string &in, const string &escape, const string &except)
virtual int dimension_stop(Dim_iter i, bool constrained=false)
Return the stop index of the constraint.
virtual void dump(ostream &strm) const
dumps information about this object
static ostream & LMarg(ostream &strm)
virtual int dimension_start(Dim_iter i, bool constrained=false)
Return the start index of a dimension.
virtual AttrTable & get_attr_table()
virtual ~Array()
The Array destructor.
int size
The unconstrained dimension size.
string name
The name of this dimension.
The basic data type for the DODS DAP types.
void add_var_nocopy(BaseType *v, Part p=nil)
virtual void update_length(int size)
virtual void print_xml_writer_core(XMLWriter &out, bool constrained, string tag)
virtual void set_length(int l)
virtual unsigned int width()
Returns the width of the data, in bytes.
A class for error processing.
unsigned int print_array(FILE *out, unsigned int index, unsigned int dims, unsigned int shape[])
Print the value given the current constraint.
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?
string id2www(string in, const string &allowable)
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)=0
Prints the value of the variable.
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.