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;
184 if (v && v->is_dap4_only_type())
185 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 Array.");
210 if (v && v->is_dap4_only_type())
211 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 Array.");
283 _shape.insert(_shape.begin(), d);
307 for (
Dim_iter i = _shape.begin(); i != _shape.end(); i++) {
309 (*i).stop = (*i).size - 1;
311 (*i).c_size = (*i).size;
335 static const char *array_sss = \
336 "Invalid constraint parameters: At least one of the start, stride or stop \n\
337 specified do not match the array variable.";
372 if (start >= d.
size || stop >= d.
size || stride > d.
size || stride <= 0)
375 if (((stop - start) / stride + 1) > d.
size)
382 d.
c_size = (stop - start) / stride + 1;
384 DBG(cerr <<
"add_constraint: c_size = " << d.
c_size << endl);
393 return _shape.begin() ;
400 return _shape.end() ;
417 unsigned int dim = 0;
418 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
425 return _shape.end() - _shape.begin();
450 if (!_shape.empty()) {
481 return (!_shape.empty()) ? (*i).start : 0;
505 return (!_shape.empty()) ? (*i).stop : 0;
530 return (!_shape.empty()) ? (*i).stride : 0;
553 "*This* array has no dimensions.");
574 for (
Dim_iter i = _shape.begin(); i != _shape.end(); i++) {
577 return length *
var()->
width(
false);
600 bool constraint_info,
bool constrained)
603 print_decl(oss, space, print_semi, constraint_info, constrained);
604 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
626 bool constraint_info,
bool constrained)
628 if (constrained && !
send_p())
632 var()->
print_decl(out, space,
false, constraint_info, constrained);
634 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
636 if ((*i).name !=
"") {
637 out <<
id2www((*i).name) <<
" = " ;
640 out << (*i).c_size <<
"]" ;
643 out << (*i).size <<
"]" ;
730 class PrintArrayDimXMLWriter :
public unary_function<Array::dimension&, void>
735 PrintArrayDimXMLWriter(
XMLWriter &xml,
bool c) : xml(xml), d_constrained(c) {}
737 void operator()(Array::dimension &d)
739 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar*)
"dimension") < 0)
740 throw InternalErr(__FILE__, __LINE__,
"Could not write dimension element");
743 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d.name.c_str()) < 0)
744 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
747 size << (d_constrained ? d.c_size : d.size);
748 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar*)
"size", (
const xmlChar*)size.str().c_str()) < 0)
749 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
751 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
752 throw InternalErr(__FILE__, __LINE__,
"Could not end dimension element");
759 if (constrained && !
send_p())
762 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar*)tag.c_str()) < 0)
763 throw InternalErr(__FILE__, __LINE__,
"Could not write " + tag +
" element");
766 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
767 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
772 string tmp_name = btp->
name();
779 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
780 throw InternalErr(__FILE__, __LINE__,
"Could not end " + tag +
" element");
796 unsigned int shape[])
799 unsigned int i =
print_array(oss, index, dims, shape);
800 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
818 unsigned int shape[])
822 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
839 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
840 index =
print_array(out, index, dims - 1, shape + 1);
843 index =
print_array(out, index, dims - 1, shape + 1);
855 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
872 unsigned int *shape =
new unsigned int[
dimensions(
true)];
873 unsigned int index = 0;
879 delete [] shape; shape = 0;
901 msg =
"An array variable must have dimensions";
918 << (
void *)
this <<
")" << endl ;
925 unsigned int dim_num = 0 ;
926 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.
xmlTextWriterPtr get_writer()
virtual unsigned int dimensions(bool constrained=false)
Return the total number of dimensions in the array.
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
int start
The constraint start index.
Array & operator=(const Array &rhs)
virtual void add_var(BaseType *v, Part p=nil)
Add the BaseType pointer to this constructor type instance.
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)
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.
virtual unsigned int width(bool constrained=false)
Returns the width of the data, in bytes.
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 unsigned int width(bool constrained=false)
virtual void print_xml_writer_core(XMLWriter &out, bool constrained, string tag)
virtual void set_length(int l)
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)
unsigned int get_doc_size()
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.