64 Array::dimension::dimension(
D4Dimension *d) : dim(d), use_sdim_for_slice(true) {
105 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
106 length *= (*i).c_size > 0 ? (*i).c_size : 1;
170 return new Array(*
this);
179 dynamic_cast<Vector &
>(*this) = rhs;
198 if (!(*d).name.empty()) {
216 else if (d4_dim->
size() != (
unsigned long) (*d).size) {
248 std::vector<dimension>::iterator i = _shape.begin(), e = _shape.end();
251 while (old_i != old_e) {
252 if ((*i).dim == *old_i) {
253 (*i).dim = new_dims->
find_dim((*old_i)->name());
368 _shape.insert(_shape.begin(), d);
378 _shape.insert(_shape.begin(), d);
402 for (
Dim_iter i = _shape.begin(); i != _shape.end(); i++) {
404 (*i).stop = (*i).size - 1;
406 (*i).c_size = (*i).size;
430 static const char *array_sss = \
431 "Invalid constraint parameters: At least one of the start, stride or stop \n\
432 specified do not match the array variable.";
468 if (start >= d.
size || stop >= d.
size || stride > d.
size || stride <= 0)
471 if (((stop - start) / stride + 1) > d.
size)
478 d.
c_size = (stop - start) / stride + 1;
480 DBG(cerr <<
"add_constraint: c_size = " << d.
c_size << endl);
506 return _shape.begin() ;
513 return _shape.end() ;
529 return _shape.size();
554 if (!_shape.empty()) {
585 return (!_shape.empty()) ? (*i).start : 0;
609 return (!_shape.empty()) ? (*i).stop : 0;
634 return (!_shape.empty()) ? (*i).stride : 0;
657 "*This* array has no dimensions.");
664 return (!_shape.empty()) ? (*i).dim : 0;
692 for (
Dim_iter i = _shape.begin(); i != _shape.end(); i++) {
695 return length *
var()->
width(
false);
700 class PrintD4ArrayDimXMLWriter:
public unary_function<Array::dimension&, void> {
707 PrintD4ArrayDimXMLWriter(XMLWriter &xml,
bool c) : xml(xml), d_constrained(c) { }
709 void operator()(Array::dimension &d)
715 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dim") < 0)
716 throw InternalErr(__FILE__, __LINE__,
"Could not write Dim element");
718 string name = (d.dim) ? d.dim->fully_qualified_name() : d.name;
721 if (!d_constrained && !name.empty()) {
722 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*) name.c_str())
723 < 0)
throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
725 else if (d.use_sdim_for_slice) {
726 assert(!name.empty());
727 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*) name.c_str())
728 < 0)
throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
732 size << (d_constrained ? d.c_size : d.size);
733 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"size",
734 (
const xmlChar*) size.str().c_str()) < 0)
735 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
738 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
739 throw InternalErr(__FILE__, __LINE__,
"Could not end Dim element");
743 class PrintD4ConstructorVarXMLWriter:
public unary_function<BaseType*, void> {
747 PrintD4ConstructorVarXMLWriter(XMLWriter &xml,
bool c) : xml(xml), d_constrained(c) { }
749 void operator()(BaseType *btp)
751 btp->print_dap4(xml, d_constrained);
755 class PrintD4MapXMLWriter:
public unary_function<D4Map*, void> {
759 PrintD4MapXMLWriter(XMLWriter &xml) : xml(xml) { }
761 void operator()(D4Map *m)
775 if (constrained && !
send_p())
return;
781 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
782 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
792 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar*)
"enum", (
const xmlChar*)path.c_str()) < 0)
793 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for enum");
798 for_each(c.
var_begin(), c.
var_end(), PrintD4ConstructorVarXMLWriter(xml, constrained));
803 for_each(
dim_begin(),
dim_end(), PrintD4ArrayDimXMLWriter(xml, constrained));
807 for_each(
maps()->map_begin(),
maps()->map_end(), PrintD4MapXMLWriter(xml));
809 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
832 bool constraint_info,
bool constrained)
835 print_decl(oss, space, print_semi, constraint_info, constrained);
836 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
858 bool constraint_info,
bool constrained)
860 if (constrained && !
send_p())
864 var()->
print_decl(out, space,
false, constraint_info, constrained);
866 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
868 if ((*i).name !=
"") {
869 out <<
id2www((*i).name) <<
" = " ;
872 out << (*i).c_size <<
"]" ;
875 out << (*i).size <<
"]" ;
962 class PrintArrayDimXMLWriter :
public unary_function<Array::dimension&, void>
967 PrintArrayDimXMLWriter(
XMLWriter &xml,
bool c) : xml(xml), d_constrained(c) {}
969 void operator()(Array::dimension &d)
971 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar*)
"dimension") < 0)
972 throw InternalErr(__FILE__, __LINE__,
"Could not write dimension element");
975 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d.name.c_str()) < 0)
976 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
979 size << (d_constrained ? d.c_size : d.size);
980 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar*)
"size", (
const xmlChar*)size.str().c_str()) < 0)
981 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
983 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
984 throw InternalErr(__FILE__, __LINE__,
"Could not end dimension element");
991 if (constrained && !
send_p())
994 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar*)tag.c_str()) < 0)
995 throw InternalErr(__FILE__, __LINE__,
"Could not write " + tag +
" element");
998 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
999 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1004 string tmp_name = btp->
name();
1009 for_each(
dim_begin(),
dim_end(), PrintArrayDimXMLWriter(xml, constrained));
1011 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
1012 throw InternalErr(__FILE__, __LINE__,
"Could not end " + tag +
" element");
1028 unsigned int shape[])
1031 unsigned int i =
print_array(oss, index, dims, shape);
1032 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
1048 unsigned int Array::print_array(ostream &out,
unsigned int index,
unsigned int dims,
unsigned int shape[])
1052 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
1069 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
1070 index =
print_array(out, index, dims - 1, shape + 1);
1073 index =
print_array(out, index, dims - 1, shape + 1);
1085 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
1102 unsigned int *shape =
new unsigned int[
dimensions(
true)];
1103 unsigned int index = 0;
1104 for (
Dim_iter i = _shape.begin(); i != _shape.end() && index <
dimensions(
true); ++i)
1109 delete [] shape; shape = 0;
1131 msg =
"An array variable must have dimensions";
1148 << (
void *)
this <<
")" << endl ;
1155 unsigned int dim_num = 0 ;
1156 for (; i != ie; i++) {
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
virtual void reset_constraint()
Reset constraint to select entire array.
void set_is_dap4(const bool v)
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)
vector< D4Dimension * >::iterator D4DimensionsIter
Iterator used for D4Dimensions.
virtual unsigned int width(bool constrained=false) const
How many bytes does this use Return the number of bytes of storage this variable uses. For scalar types, this is pretty simple (an int32 uses 4 bytes, etc.). For arrays and Constructors, it is a bit more complex. Note that a scalar String variable uses sizeof(String*) bytes, not the length of the string. In other words, the value returned is independent of the type. Also note width() of a String array returns the number of elements in the array times sizeof(String*). That is, each different array size is a different data type.
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.
Array(const string &n, BaseType *v, bool is_dap4=false)
Array constructor.
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.
D4EnumDefs * parent() const
virtual BaseType * prototype() const
void add_var(BaseType *v, Part p=nil)
Add the BaseType pointer to this constructor type instance.
unsigned long long c_start() const
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
unsigned long long c_stop() const
bool use_sdim_for_slice
Used to control printing the DMR in data responses.
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.
D4DimensionsIter dim_end()
Get an iterator to the end of the dimensions.
unsigned long long c_stride() const
void print_xml_writer(XMLWriter &xml)
void append_dim(int size, const string &name="")
Add a dimension of a given size.
virtual void update_length(int size=0)
Type type() const
Returns the type of the class instance.
D4DimensionsIter dim_begin()
Get an iterator to the start of the dimensions.
void _duplicate(const Array &a)
virtual D4Dimension * dimension_D4dim(Dim_iter i)
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)
string type_name() const
Returns the type of the class instance as a string.
Holds a DAP4 enumeration.
virtual int dimension_size(Dim_iter i, bool constrained=false)
Returns the size of the dimension.
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.
virtual bool is_constructor_type() const
Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable...
void add_dim_nocopy(D4Dimension *dim)
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 D4Attributes * attributes()
virtual void print_as_map_xml_writer(XMLWriter &xml, bool constrained)
virtual std::string FQN() const
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)
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 void print_dap4(XMLWriter &xml, bool constrained=false)
Print the DAP4 representation of an array.
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 print_xml_writer_core(XMLWriter &out, bool constrained, string tag)
virtual D4EnumDef * enumeration() const
virtual void set_length(int l)
void set_used_by_projected_var(bool state)
A class for error processing.
unsigned long size() const
void transform_to_dap4(AttrTable &at)
copy attributes from DAP2 to DAP4
virtual BaseType * transform_to_dap4(D4Group *root, Constructor *container)
DAP2 to DAP4 transform.
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?
D4Dimension * find_dim(const string &name)
string id2www(string in, const string &allowable)
virtual unsigned int width(bool constrained=false) const
Returns the width of the data, in bytes.
void print_dap4(XMLWriter &xml) const
unsigned int get_doc_size()
D4Dimensions * dims()
Get the dimensions defined for this Group.
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.