81 static const unsigned char end_of_sequence = 0xA5;
82 static const unsigned char start_of_instance = 0x5A;
88 DBG(cerr <<
"In Sequence::m_duplicate" << endl);
90 d_row_number = s.d_row_number;
91 d_starting_row_number = s.d_starting_row_number;
92 d_ending_row_number = s.d_ending_row_number;
93 d_row_stride = s.d_row_stride;
94 d_leaf_sequence = s.d_leaf_sequence;
95 d_unsent_data = s.d_unsent_data;
96 d_wrote_soi = s.d_wrote_soi;
97 d_top_most = s.d_top_most;
102 for (vector<BaseTypeRow *>::iterator rows_iter = cs.d_values.begin(); rows_iter != cs.d_values.end(); rows_iter++) {
109 for (BaseTypeRow::iterator bt_row_iter = src_bt_row_ptr->begin(); bt_row_iter != src_bt_row_ptr->end();
111 BaseType *src_bt_ptr = *bt_row_iter;
113 dest_bt_row_ptr->push_back(dest_bt_ptr);
116 d_values.push_back(dest_bt_row_ptr);
120 static void write_end_of_sequence(
Marshaller &m)
125 static void write_start_of_instance(Marshaller &m)
127 m.put_opaque((
char *) &start_of_instance, 1);
130 static unsigned char read_marker(UnMarshaller &um)
132 unsigned char marker;
133 um.get_opaque((
char *) &marker, 1);
138 static bool is_start_of_instance(
unsigned char marker)
140 return (marker == start_of_instance);
143 static bool is_end_of_sequence(
unsigned char marker)
145 return (marker == end_of_sequence);
158 Sequence::Sequence(
const string &n) :
160 -1), d_unsent_data(false), d_wrote_soi(false), d_leaf_sequence(false), d_top_most(false)
176 -1), d_unsent_data(false), d_wrote_soi(false), d_leaf_sequence(false), d_top_most(false)
220 static inline void delete_bt(
BaseType *bt_ptr)
226 static inline void delete_rows(
BaseTypeRow *bt_row_ptr)
228 for_each(bt_row_ptr->begin(), bt_row_ptr->end(), delete_bt);
236 for_each(d_values.begin(), d_values.end(), delete_rows);
242 if (
this == &rhs)
return *
this;
266 oss << (*i)->toString();
277 bool seq_found =
false;
295 linear = (*iter)->is_simple_type();
309 if (row >= d_values.size())
return 0;
310 return d_values[row];
348 if (!bt_row_ptr)
return 0;
350 BaseTypeRow::iterator bt_row_iter = bt_row_ptr->begin();
351 BaseTypeRow::iterator bt_row_end = bt_row_ptr->end();
352 while (bt_row_iter != bt_row_end && (*bt_row_iter)->name() !=
name)
355 if (bt_row_iter == bt_row_end)
370 if (!bt_row_ptr)
return 0;
372 if (i >= bt_row_ptr->size())
return 0;
374 return (*bt_row_ptr)[i];
403 return d_values.size();
437 void Sequence::load_prototypes_with_values(
int row_number)
439 vector<BaseType*> *row = d_values.at(row_number);
447 if ((*i)->type() != row->at(pos)->var()->type())
448 throw InternalErr(__FILE__, __LINE__,
"Expected types to match when loading values for selection expression evaluation.");
451 switch ((*i)->type()) {
480 throw InternalErr(__FILE__, __LINE__,
"Expected a scalar type when loading values for selection expression evaluation.");
541 DBG2(cerr <<
"Entering Sequence::read_row for " <<
name() << endl);
542 if (row < d_row_number)
throw InternalErr(
"Trying to back up inside a sequence!");
544 DBG2(cerr <<
"read_row: row number " << row <<
", current row " << d_row_number << endl);
545 if (row == d_row_number) {
546 DBG2(cerr <<
"Leaving Sequence::read_row for " <<
name() << endl);
553 while (!eof && d_row_number < row) {
567 load_prototypes_with_values(d_row_number);
587 DBG2(cerr <<
"Leaving Sequence::read_row for " <<
name() <<
" with eof: " << eof << endl);
598 inline bool Sequence::is_end_of_rows(
int i)
600 return ((d_ending_row_number == -1) ?
false : (i > d_ending_row_number));
665 DBG2(cerr <<
"Entering Sequence::serialize for " <<
name() << endl);
680 DBG2(cerr <<
"Entering serialize_parent_part_one for " <<
name() << endl);
682 int i = (d_starting_row_number != -1) ? d_starting_row_number : 0;
688 bool status =
read_row(i, dds, eval,
false);
689 DBG2(cerr <<
"Sequence::serialize_parent_part_one::read_row() status: " << status << endl);
691 while (status && !is_end_of_rows(i)) {
708 if ((*iter)->send_p() && (*iter)->type() ==
dods_sequence_c) (*iter)->serialize(eval, dds, m);
713 status =
read_row(i, dds, eval,
false);
714 DBG(cerr <<
"Sequence::serialize_parent_part_one::read_row() status: " << status << endl);
722 if (d_top_most || d_wrote_soi) {
723 DBG(cerr <<
"Writing End of Sequence marker" << endl);
724 write_end_of_sequence(m);
743 DBG(cerr <<
"Entering serialize_parent_part_two for " <<
name() << endl);
746 if (btp && btp->
type() ==
dods_sequence_c) static_cast<Sequence&>(*btp).serialize_parent_part_two(dds, eval, m);
749 DBG(cerr <<
"Writing Start of Instance marker" << endl);
751 write_start_of_instance(m);
756 DBG(cerr <<
"Sequence::serialize_parent_part_two(), serializing "
757 << (*iter)->name() << endl);
759 DBG(cerr <<
"Send P is true, sending " << (*iter)->name() << endl);
760 (*iter)->serialize(eval, dds, m,
false);
764 d_unsent_data =
false;
772 DBG(cerr <<
"Entering Sequence::serialize_leaf for " <<
name() << endl);
773 int i = (d_starting_row_number != -1) ? d_starting_row_number : 0;
777 bool status =
read_row(i, dds, eval, ce_eval);
778 DBG(cerr <<
"Sequence::serialize_leaf::read_row() status: " << status << endl);
790 if (status && !is_end_of_rows(i)) {
792 if (btp && btp->
type() ==
dods_sequence_c) static_cast<Sequence&>(*btp).serialize_parent_part_two(dds, eval, m);
796 while (status && !is_end_of_rows(i)) {
799 DBG(cerr <<
"Writing Start of Instance marker" << endl);
801 write_start_of_instance(m);
805 DBG(cerr <<
"Sequence::serialize_leaf(), serializing "
806 << (*iter)->name() << endl);
807 if ((*iter)->send_p()) {
808 DBG(cerr <<
"Send P is true, sending " << (*iter)->name() << endl);
809 (*iter)->serialize(eval, dds, m,
false);
815 status =
read_row(i, dds, eval, ce_eval);
816 DBG(cerr <<
"Sequence::serialize_leaf::read_row() status: " << status << endl);
821 if (d_wrote_soi || d_top_most) {
822 DBG(cerr <<
"Writing End of Sequence marker" << endl);
823 write_end_of_sequence(m);
853 DBG(cerr <<
"Sequence::intern_data - for " <<
name() << endl);
DBG2(cerr <<
" intern_data, values: " << &d_values << endl);
860 DBG2(cerr <<
" pushing d_values of " <<
name() <<
" (" << &d_values
861 <<
") on stack; size: " << sequence_values_stack.size() << endl);
862 sequence_values_stack.push(&d_values);
869 DBG(cerr <<
"Entering intern_data_private for " <<
name() << endl);
880 DBG(cerr <<
"Entering intern_data_parent_part_one for " <<
name() << endl);
888 bool status =
read_row(i, dds, eval,
false);
896 SequenceValues::size_type orig_stack_size = sequence_values_stack.size();
901 if ((*iter)->send_p()) {
902 switch ((*iter)->type()) {
908 (*iter)->intern_data(eval, dds);
916 status =
read_row(i, dds, eval,
false);
926 if (sequence_values_stack.size() > orig_stack_size) {
927 DBG2(cerr <<
" popping d_values (" << sequence_values_stack.top()
928 <<
") off stack; size: " << sequence_values_stack.size() << endl);
929 sequence_values_stack.pop();
930 }
DBG(cerr <<
"Leaving intern_data_parent_part_one for " <<
name() << endl);
936 DBG(cerr <<
"Entering intern_data_parent_part_two for " <<
name() << endl);
943 DBG2(cerr <<
" stack size: " << sequence_values_stack.size() << endl);
945 DBG2(cerr <<
" using values = " << (
void *)values << endl);
954 row_data->push_back((*iter)->ptr_duplicate());
956 else if ((*iter)->send_p()) {
960 throw InternalErr(__FILE__, __LINE__,
"Expected a Sequence.");
962 row_data->push_back(tmp);
963 DBG2(cerr <<
" pushing d_values of " << tmp->
name()
964 <<
" (" << &(tmp->d_values)
965 <<
") on stack; size: " << sequence_values_stack.size()
970 sequence_values_stack.push(&(tmp->d_values));
974 DBG2(cerr <<
" pushing values for " <<
name()
975 <<
" to " << values << endl);
976 values->push_back(row_data);
978 }
DBG(cerr <<
"Leaving intern_data_parent_part_two for " <<
name() << endl);
983 DBG(cerr <<
"Entering intern_data_for_leaf for " <<
name() << endl);
987 DBG2(cerr <<
" reading row " << i << endl);
988 bool status =
read_row(i, dds, eval,
true);
1004 DBG2(cerr <<
" using values = " << values << endl);
1012 if ((*iter)->send_p()) {
1013 row_data->push_back((*iter)->ptr_duplicate());
1017 DBG2(cerr <<
" pushing values for " <<
name()
1018 <<
" to " << values << endl);
1020 values->push_back(row_data);
1024 status =
read_row(i, dds, eval,
true);
1027 DBG2(cerr <<
" popping d_values (" << sequence_values_stack.top()
1028 <<
") off stack; size: " << sequence_values_stack.size() << endl);
1029 sequence_values_stack.pop();
1030 }
DBG(cerr <<
"Leaving intern_data_for_leaf for " <<
name() << endl);
1056 if (!dd)
throw InternalErr(
"Expected argument 'dds' to be a DataDDS!");
1058 DBG2(cerr <<
"Reading from server/protocol version: "
1066 +
") indicates that this\nis an old server which may not correctly transmit Sequence variables.\nContact the server administrator.");
1071 unsigned char marker = read_marker(um);
1072 if (is_end_of_sequence(marker))
1074 else if (is_start_of_instance(marker)) {
1076 DBG2(cerr <<
"Reading row " << d_row_number <<
" of "
1083 DBG2(cerr <<
"Deserialized " << bt_ptr->
name() <<
" ("
1085 bt_row_ptr->push_back(bt_ptr);
1088 d_values.push_back(bt_row_ptr);
1091 throw Error(
"I could not read the expected Sequence data stream marker!");
1112 return d_starting_row_number;
1127 return d_row_stride;
1143 return d_ending_row_number;
1156 if (stop < start)
throw Error(
malformed_expr,
"Starting row number must precede the ending row number.");
1158 d_starting_row_number = start;
1159 d_row_stride = stride;
1160 d_ending_row_number = stop;
1167 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
1172 if (print_row_num) out <<
"\n" << space << row <<
": ";
1186 while (j < elements && !bt_ptr) {
1190 static_cast<Sequence*>(bt_ptr)->print_val_by_rows(out, space +
" ",
false, print_row_num);
1197 while (j < elements) {
1202 static_cast<Sequence*>(bt_ptr)->print_val_by_rows(out, space +
" ",
false, print_row_num);
1215 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
1229 for (i = 0; i < rows; ++i) {
1237 if (print_decl_p) out <<
";\n";
1252 d_leaf_sequence = state;
1257 return d_leaf_sequence;
1286 bool has_child_sequence =
false;
1288 if (lvl == 1) d_top_most =
true;
1290 DBG2(cerr <<
"Processing sequence " <<
name() << endl);
1299 if (has_child_sequence)
1301 "This implementation does not support more than one nested sequence at a level. Contact the server administrator.");
1303 has_child_sequence =
true;
1311 if (!has_child_sequence)
1329 strm <<
DapIndent::LMarg <<
"Sequence::dump - (" << (
void *)
this <<
")" << endl;
1332 strm <<
DapIndent::LMarg <<
"# rows deserialized: " << d_row_number << endl;
1335 strm <<
DapIndent::LMarg <<
"starting row #: " << d_starting_row_number << endl;
1337 strm <<
DapIndent::LMarg <<
"ending row #: " << d_ending_row_number << endl;
1342 strm <<
DapIndent::LMarg <<
"is leaf sequence? " << d_leaf_sequence << endl;
1343 strm <<
DapIndent::LMarg <<
"top most in hierarchy? " << d_top_most << endl;
Holds an Internet address (URL).
virtual bool read_p()
Has this variable been read?
virtual void intern_data(ConstraintEvaluator &eval, DDS &dds)
abstract base class used to unmarshall/deserialize dap data objects
virtual void dump(ostream &strm) const
dumps information about this object
void set_unsent_data(bool usd)
Set the unsent data property.
virtual bool set_value(dods_float64 val)
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
std::vector< BaseType * > d_vars
virtual bool read_row(int row, DDS &dds, ConstraintEvaluator &eval, bool ce_eval=true)
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Deserialize (read from the network) the entire Sequence.
std::vector< BaseType * >::iterator Vars_iter
virtual bool is_dap2_only_type()
Holds an unsigned 16-bit integer.
vector< BaseTypeRow * > SequenceValues
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
int get_protocol_minor() const
virtual bool serialize_leaf(DDS &dds, ConstraintEvaluator &eval, Marshaller &m, bool ce_eval)
BaseType * transform_to_dap4(D4Group *root, Constructor *dest)
DAP2 to DAP4 transform.
virtual void put_opaque(char *val, unsigned int len)=0
virtual BaseTypeRow * row_value(size_t row)
Get a whole row from the sequence.
virtual void set_row_number_constraint(int start, int stop, int stride=1)
Holds a structure (aggregate) type.
Type type() const
Returns the type of the class instance.
virtual string toString()
Holds a 32-bit floating point value.
virtual int element_count(bool leaves=false)
Count the members of constructor types.
virtual void print_val_by_rows(ostream &out, string space="", bool print_decl_p=true, bool print_row_numbers=true)
virtual void set_parent(BaseType *parent)
virtual void set_leaf_sequence(int level=1)
Traverse Structure, set Sequence leaf nodes.
A class for software fault reporting.
virtual void intern_data_private(ConstraintEvaluator &eval, DDS &dds, sequence_values_stack_t &sequence_values_stack)
string dataset() const
Returns the name of the dataset used to create this instance.
virtual bool set_value(dods_uint32 val)
virtual bool is_linear()
Check to see whether this variable can be printed simply.
virtual void intern_data_for_leaf(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
Holds character string data.
virtual int length() const
bool get_unsent_data()
Get the unsent data property.
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Holds a 16-bit signed integer value.
Sequence(const string &n)
The Sequence constructor.
virtual BaseType * get_parent() const
virtual void set_length(int count)
virtual bool read()
simple implementation of read that iterates through vars and calls read on them
virtual void set_leaf_sequence(int lvl=1)
Mark the Sequence which holds the leaf elements.
Sequence & operator=(const Sequence &rhs)
virtual bool set_value(dods_int16 val)
virtual bool set_value(const dods_byte value)
virtual void dump(ostream &strm) const
dumps information about this object
virtual bool set_value(const string &value)
vector< BaseType * > BaseTypeRow
virtual void serialize_parent_part_two(DDS &dds, ConstraintEvaluator &eval, Marshaller &m)
virtual bool set_value(dods_float32 f)
virtual bool is_leaf_sequence()
string name() const
Returns the name of the class instance.
virtual string toString()
virtual BaseType * ptr_duplicate()=0
int get_starting_row_number()
Get the starting row number.
virtual int number_of_rows() const
Evaluate a constraint expression.
virtual SequenceValues & value_ref()
virtual SequenceValues value()
void reset_row_number()
Rest the row number counter.
virtual void intern_data_parent_part_two(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
static ostream & LMarg(ostream &strm)
virtual bool set_value(dods_int32 i)
The basic data type for the DODS DAP types.
abstract base class used to marshal/serialize dap data objects
virtual BaseType * var_value(size_t row, const string &name)
Get the BaseType pointer to the named variable of a given row.
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 void print_one_row(ostream &out, int row, string space, bool print_row_num=false)
Holds a 64-bit (double precision) floating point value.
virtual void intern_data_parent_part_one(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
string get_protocol() const
bool eval_selection(DDS &dds, const std::string &dataset)
Evaluate a boolean-valued constraint expression. This is main method for the evaluator ans is called ...
virtual bool set_value(dods_uint16 val)
virtual bool serialize_parent_part_one(DDS &dds, ConstraintEvaluator &eval, Marshaller &m)
virtual void set_leaf_p(bool state)
stack< SequenceValues * > sequence_values_stack_t
void m_duplicate(const Sequence &s)
A class for error processing.
virtual BaseType * transform_to_dap4(D4Group *root, Constructor *container)
virtual int get_ending_row_number()
Get the ending row number.
Holds a 32-bit unsigned integer.
virtual BaseType * ptr_duplicate()
virtual int get_row_stride()
Get the row stride.
int get_protocol_major() const
virtual void set_value(SequenceValues &values)
Holds a 32-bit signed integer.
virtual void set_read_p(bool state)
Sets the value of the read_p property.