77#undef CLEAR_LOCAL_DATA
83static const unsigned char end_of_sequence = 0xA5;
84static const unsigned char start_of_instance = 0x5A;
89 DBG(cerr <<
"In Sequence::m_duplicate" << endl);
91 d_row_number = s.d_row_number;
92 d_starting_row_number = s.d_starting_row_number;
93 d_ending_row_number = s.d_ending_row_number;
94 d_row_stride = s.d_row_stride;
95 d_leaf_sequence = s.d_leaf_sequence;
96 d_unsent_data = s.d_unsent_data;
97 d_wrote_soi = s.d_wrote_soi;
98 d_top_most = s.d_top_most;
110 for (BaseTypeRow::iterator bt_row_iter = src_bt_row_ptr->begin(); bt_row_iter != src_bt_row_ptr->end();
112 BaseType *src_bt_ptr = *bt_row_iter;
114 dest_bt_row_ptr->push_back(dest_bt_ptr);
117 d_values.push_back(dest_bt_row_ptr);
123static void write_start_of_instance(Marshaller &m) { m.put_opaque((
char *)&start_of_instance, 1); }
126 unsigned char marker;
127 um.get_opaque((
char *)&marker, 1);
132static bool is_start_of_instance(
unsigned char marker) {
return (marker == start_of_instance); }
134static bool is_end_of_sequence(
unsigned char marker) {
return (marker == end_of_sequence); }
148 d_ending_row_number(-1), d_unsent_data(false), d_wrote_soi(false), d_leaf_sequence(false), d_top_most(false) {}
162 d_ending_row_number(-1), d_unsent_data(false), d_wrote_soi(false), d_leaf_sequence(false), d_top_most(false) {}
198static inline void delete_bt(
BaseType *bt_ptr) {
203static inline void delete_rows(
BaseTypeRow *bt_row_ptr) {
204 for_each(bt_row_ptr->begin(), bt_row_ptr->end(), delete_bt);
213 }
catch (
const std::exception &) {
219 if (!d_values.empty()) {
220 for_each(d_values.begin(), d_values.end(), delete_rows);
246 oss << (*i)->toString();
256 bool seq_found =
false;
272 linear = (*iter)->is_simple_type();
284 if (row >= d_values.size())
286 return d_values[row];
315 BaseTypeRow::iterator bt_row_iter = bt_row_ptr->begin();
316 BaseTypeRow::iterator bt_row_end = bt_row_ptr->end();
317 while (bt_row_iter != bt_row_end && (*bt_row_iter)->name() !=
name)
320 if (bt_row_iter == bt_row_end)
336 if (i >= bt_row_ptr->size())
339 return (*bt_row_ptr)[i];
437 DBG2(cerr <<
"Entering Sequence::read_row for " <<
name() <<
", row number " << row <<
", current row "
438 << d_row_number << endl);
439 if (row < d_row_number)
440 throw InternalErr(
"Trying to back up inside a sequence!");
442 if (row == d_row_number) {
443 DBG2(cerr <<
"Leaving Sequence::read_row for " <<
name() << endl);
448 while (!eof && d_row_number < row) {
470 DBG2(cerr <<
"Leaving Sequence::read_row for " <<
name() <<
" with eof: " << eof << endl);
481inline bool Sequence::is_end_of_rows(
int i) {
482 return ((d_ending_row_number == -1) ?
false : (i > d_ending_row_number));
562 DBG2(cerr <<
"Entering serialize_parent_part_one for " <<
name() << endl);
564 int i = (d_starting_row_number != -1) ? d_starting_row_number : 0;
570 bool status =
read_row(i, dds, eval,
false);
571 DBG2(cerr <<
"Sequence::serialize_parent_part_one::read_row() status: " << status << endl);
573 while (status && !is_end_of_rows(i)) {
591 (*iter)->serialize(eval, dds, m);
596 status =
read_row(i, dds, eval,
false);
597 DBG(cerr <<
"Sequence::serialize_parent_part_one::read_row() status: " << status << endl);
605 if (d_top_most || d_wrote_soi) {
606 DBG(cerr <<
"Writing End of Sequence marker" << endl);
607 write_end_of_sequence(m);
625 DBG(cerr <<
"Entering serialize_parent_part_two for " <<
name() << endl);
629 static_cast<Sequence &
>(*btp).serialize_parent_part_two(dds, eval, m);
632 DBG(cerr <<
"Writing Start of Instance marker" << endl);
634 write_start_of_instance(m);
639 DBG(cerr <<
"Sequence::serialize_parent_part_two(), serializing " << (*iter)->name() << endl);
641 DBG(cerr <<
"Send P is true, sending " << (*iter)->name() << endl);
642 (*iter)->serialize(eval, dds, m,
false);
646 d_unsent_data =
false;
653 DBG(cerr <<
"Entering Sequence::serialize_leaf for " <<
name() << endl);
654 int i = (d_starting_row_number != -1) ? d_starting_row_number : 0;
658 bool status =
read_row(i, dds, eval, ce_eval);
659 DBG(cerr <<
"Sequence::serialize_leaf::read_row() status: " << status << endl);
671 if (status && !is_end_of_rows(i)) {
674 static_cast<Sequence &
>(*btp).serialize_parent_part_two(dds, eval, m);
678 while (status && !is_end_of_rows(i)) {
681 DBG(cerr <<
"Writing Start of Instance marker" << endl);
683 write_start_of_instance(m);
687 DBG(cerr <<
"Sequence::serialize_leaf(), serializing " << (*iter)->name() << endl);
688 if ((*iter)->send_p()) {
689 DBG(cerr <<
"Send P is true, sending " << (*iter)->name() << endl);
690 (*iter)->serialize(eval, dds, m,
false);
696 status =
read_row(i, dds, eval, ce_eval);
697 DBG(cerr <<
"Sequence::serialize_leaf::read_row() status: " << status << endl);
702 if (d_wrote_soi || d_top_most) {
703 DBG(cerr <<
"Writing End of Sequence marker" << endl);
704 write_end_of_sequence(m);
733 DBG(cerr <<
"Sequence::intern_data - for " <<
name() << endl);
734 DBG2(cerr <<
" intern_data, values: " << &d_values << endl);
736 throw Error(
string(
"A method usable only with DAP2 variables was called on a DAP4 variable (")
746 sequence_values_stack.push(&d_values);
753 DBG(cerr <<
"Entering intern_data_private for " <<
name() << endl);
763 DBG(cerr <<
"Entering intern_data_parent_part_one for " <<
name() << endl);
771 bool status =
read_row(i, dds, eval,
false);
779 SequenceValues::size_type orig_stack_size = sequence_values_stack.size();
784 if ((*iter)->send_p()) {
785 switch ((*iter)->type()) {
787 static_cast<Sequence &
>(**iter).intern_data_private(eval, dds, sequence_values_stack);
791 (*iter)->intern_data(eval, dds);
799 status =
read_row(i, dds, eval,
false);
809 if (sequence_values_stack.size() > orig_stack_size) {
810 DBG2(cerr <<
" popping d_values (" << sequence_values_stack.top()
811 <<
") off stack; size: " << sequence_values_stack.size() << endl);
812 sequence_values_stack.pop();
815 DBG(cerr <<
"Leaving intern_data_parent_part_one for " <<
name() << endl);
820 DBG(cerr <<
"Entering intern_data_parent_part_two for " <<
name() << endl);
824 static_cast<Sequence &
>(*btp).intern_data_parent_part_two(dds, eval, sequence_values_stack);
827 DBG2(cerr <<
" stack size: " << sequence_values_stack.size() << endl);
829 DBG2(cerr <<
" using values = " << (
void *)values << endl);
838 row_data->push_back((*iter)->ptr_duplicate());
839 }
else if ((*iter)->send_p()) {
843 throw InternalErr(__FILE__, __LINE__,
"Expected a Sequence.");
845 row_data->push_back(tmp);
846 DBG2(cerr <<
" pushing d_values of " << tmp->
name() <<
" (" << &(tmp->d_values)
847 <<
") on stack; size: " << sequence_values_stack.size() << endl);
851 sequence_values_stack.push(&(tmp->d_values));
855 DBG2(cerr <<
" pushing values for " <<
name() <<
" to " << values << endl);
856 values->push_back(row_data);
860 DBG(cerr <<
"Leaving intern_data_parent_part_two for " <<
name() << endl);
865 DBG(cerr <<
"Entering intern_data_for_leaf for " <<
name() << endl);
869 DBG2(cerr <<
" reading row " << i << endl);
870 bool status =
read_row(i, dds, eval,
true);
871 DBG2(cerr <<
" status: " << status << endl);
880 static_cast<Sequence &
>(*btp).intern_data_parent_part_two(dds, eval, sequence_values_stack);
887 DBG2(cerr <<
" using values = " << values << endl);
895 if ((*iter)->send_p()) {
896 row_data->push_back((*iter)->ptr_duplicate());
900 DBG2(cerr <<
" pushing values for " <<
name() <<
" to " << values << endl);
902 values->push_back(row_data);
906 status =
read_row(i, dds, eval,
true);
909 DBG2(cerr <<
" popping d_values (" << sequence_values_stack.top()
910 <<
") off stack; size: " << sequence_values_stack.size() << endl);
911 sequence_values_stack.pop();
914 DBG(cerr <<
"Leaving intern_data_for_leaf for " <<
name() << endl);
941 if (!dd)
throw InternalErr(
"Expected argument 'dds' to be a DataDDS!");
943 DBG2(cerr <<
"Reading from server/protocol version: "
951 +
") indicates that this\nis an old server which may not correctly transmit Sequence variables.\nContact the server administrator.");
956 unsigned char marker = read_marker(um);
957 if (is_end_of_sequence(marker))
959 else if (is_start_of_instance(marker)) {
961 DBG2(cerr <<
"Reading row " << d_row_number <<
" of " <<
name() << endl);
967 DBG2(cerr <<
"Deserialized " << bt_ptr->
name() <<
" (" << bt_ptr <<
") = ");
969 bt_row_ptr->push_back(bt_ptr);
972 d_values.push_back(bt_row_ptr);
974 throw Error(
"I could not read the expected Sequence data stream marker!");
1032 d_starting_row_number = start;
1033 d_row_stride = stride;
1034 d_ending_row_number = stop;
1040 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
1045 out <<
"\n" << space << row <<
": ";
1059 while (j < elements && !bt_ptr) {
1070 while (j < elements) {
1087 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
1100 for (i = 0; i < rows; ++i) {
1149 bool has_child_sequence =
false;
1154 DBG2(cerr <<
"Processing sequence " <<
name() << endl);
1163 if (has_child_sequence)
1164 throw Error(
"This implementation does not support more than one nested sequence at a level. Contact "
1165 "the server administrator.");
1167 has_child_sequence =
true;
1168 static_cast<Sequence &
>(**iter).set_leaf_sequence(++lvl);
1174 if (!has_child_sequence)
1191 strm <<
DapIndent::LMarg <<
"Sequence::dump - (" << (
void *)
this <<
")" << endl;
1194 strm <<
DapIndent::LMarg <<
"# rows deserialized: " << d_row_number << endl;
1197 strm <<
DapIndent::LMarg <<
"starting row #: " << d_starting_row_number << endl;
1199 strm <<
DapIndent::LMarg <<
"ending row #: " << d_ending_row_number << endl;
1204 strm <<
DapIndent::LMarg <<
"is leaf sequence? " << d_leaf_sequence << endl;
1205 strm <<
DapIndent::LMarg <<
"top most in hierarchy? " << d_top_most << endl;
#define malformed_expr
(400)
The basic data type for the DODS DAP types.
virtual void intern_data()
Read data into this variable.
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
virtual string name() const
Returns the name of the class instance.
virtual BaseType * get_parent() const
virtual bool read_p()
Has this variable been read?
virtual string dataset() const
Returns the name of the dataset used to create this instance.
virtual string toString()
virtual bool is_dap4() const
virtual BaseType * ptr_duplicate()=0
virtual Type type() const
Returns the type of the class instance.
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Evaluate a constraint expression.
bool eval_selection(DDS &dds, const std::string &dataset)
Evaluate a boolean-valued constraint expression. This is main method for the evaluator and is called ...
int element_count(bool leaves=false) override
Count the members of constructor types.
void transform_to_dap4(D4Group *root, Constructor *dest) override
DAP2 to DAP4 transform.
void print_decl(ostream &out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false) override
Print an ASCII representation of the variable structure.
void set_read_p(bool state) override
Set the 'read_p' property for the Constructor and its members.
std::vector< BaseType * >::iterator Vars_iter
std::vector< BaseType * > d_vars
bool read() override
Read the elements of Constructor marked for transmission.
void add_var_nocopy(BaseType *bt, Part part=nil) override
Constructor & operator=(const Constructor &rhs)
Constructor(const string &name, const Type &type, bool is_dap4=false)
void dump(ostream &strm) const override
dumps information about this object
void set_length(int64_t count) override
static ostream & LMarg(ostream &strm)
int get_protocol_major() const
int get_protocol_minor() const
string get_protocol() const
A class for error processing.
A class for software fault reporting.
abstract base class used to marshal/serialize dap data objects
virtual void put_opaque(char *val, unsigned int len)=0
void m_duplicate(const Sequence &s)
virtual void transform_to_dap4(D4Group *root, Constructor *container)
virtual bool serialize_leaf(DDS &dds, ConstraintEvaluator &eval, Marshaller &m, bool ce_eval)
virtual SequenceValues value()
virtual string toString()
virtual void intern_data_for_leaf(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
virtual bool serialize_parent_part_one(DDS &dds, ConstraintEvaluator &eval, Marshaller &m)
virtual bool is_leaf_sequence()
virtual void dump(ostream &strm) const
dumps information about this object
virtual bool read_row(int row, DDS &dds, ConstraintEvaluator &eval, bool ce_eval=true)
virtual void set_leaf_sequence(int lvl=1)
Mark the Sequence which holds the leaf elements.
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.
virtual void print_one_row(ostream &out, int row, string space, bool print_row_num=false)
stack< SequenceValues * > sequence_values_stack_t
virtual void serialize_parent_part_two(DDS &dds, ConstraintEvaluator &eval, Marshaller &m)
Sequence & operator=(const Sequence &rhs)
Sequence(const string &n)
The Sequence constructor.
virtual SequenceValues & value_ref()
virtual void set_value(SequenceValues &values)
virtual BaseType * ptr_duplicate()
virtual bool is_linear()
Check to see whether this variable can be printed simply.
virtual BaseType * var_value(size_t row, const string &name)
Get the BaseType pointer to the named variable of a given row.
virtual void set_leaf_p(bool state)
virtual void clear_local_data()
virtual bool is_dap2_only_type()
virtual void print_val_by_rows(ostream &out, string space="", bool print_decl_p=true, bool print_row_numbers=true)
virtual void intern_data_parent_part_two(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
virtual void intern_data_private(ConstraintEvaluator &eval, DDS &dds, sequence_values_stack_t &sequence_values_stack)
bool get_unsent_data() const
Get the unsent data property.
int get_starting_row_number()
Get the starting row number.
void reset_row_number()
Rest the row number counter.
void set_unsent_data(bool usd)
Set the unsent data property.
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
virtual int length() const
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Deserialize (read from the network) the entire Sequence.
virtual int get_row_stride()
Get the row stride.
virtual int get_ending_row_number()
Get the ending row number.
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)
virtual int number_of_rows() const
Holds a structure (aggregate) type.
virtual void set_leaf_sequence(int level=1)
Traverse Structure, set Sequence leaf nodes.
abstract base class used to unmarshall/deserialize dap data objects
top level DAP object to house generic methods
vector< BaseType * > BaseTypeRow
vector< BaseTypeRow * > SequenceValues