73 static const unsigned char end_of_sequence = 0xA5;
74 static const unsigned char start_of_instance = 0x5A;
79 Sequence::_duplicate(
const Sequence &s)
81 d_row_number = s.d_row_number;
82 d_starting_row_number = s.d_starting_row_number;
83 d_ending_row_number = s.d_ending_row_number;
84 d_row_stride = s.d_row_stride;
85 d_leaf_sequence = s.d_leaf_sequence;
86 d_unsent_data = s.d_unsent_data;
87 d_wrote_soi = s.d_wrote_soi;
88 d_top_most = s.d_top_most;
90 Sequence &cs =
const_cast<Sequence &
>(s);
93 for (Vars_iter i = cs.var_begin(); i != cs.var_end(); i++) {
98 for (vector<BaseTypeRow *>::iterator rows_iter = cs.d_values.begin();
99 rows_iter != cs.d_values.end();
107 for (BaseTypeRow::iterator bt_row_iter = src_bt_row_ptr->begin();
108 bt_row_iter != src_bt_row_ptr->end();
110 BaseType *src_bt_ptr = *bt_row_iter;
111 BaseType *dest_bt_ptr = src_bt_ptr->ptr_duplicate();
112 dest_bt_row_ptr->push_back(dest_bt_ptr);
115 d_values.push_back(dest_bt_row_ptr);
120 write_end_of_sequence(Marshaller &m)
122 m.put_opaque( (
char *)&end_of_sequence, 1 ) ;
126 write_start_of_instance(Marshaller &m)
128 m.put_opaque( (
char *)&start_of_instance, 1 ) ;
132 read_marker(UnMarshaller &um)
134 unsigned char marker;
135 um.get_opaque( (
char *)&marker, 1 ) ;
141 is_start_of_instance(
unsigned char marker)
143 return (marker == start_of_instance);
147 is_end_of_sequence(
unsigned char marker)
149 return (marker == end_of_sequence);
163 d_row_number(-1), d_starting_row_number(-1),
164 d_row_stride(1), d_ending_row_number(-1),
165 d_unsent_data(false), d_wrote_soi(false),
166 d_leaf_sequence(false), d_top_most(false)
181 d_row_number(-1), d_starting_row_number(-1),
182 d_row_stride(1), d_ending_row_number(-1),
183 d_unsent_data(false), d_wrote_soi(false),
184 d_leaf_sequence(false), d_top_most(false)
202 DBG2(cerr <<
"In delete_bt: " << bt_ptr << endl);
203 delete bt_ptr; bt_ptr = 0;
209 DBG2(cerr <<
"In delete_rows: " << bt_row_ptr << endl);
211 for_each(bt_row_ptr->begin(), bt_row_ptr->end(), delete_bt);
213 delete bt_row_ptr; bt_row_ptr = 0;
218 DBG2(cerr <<
"Entering Sequence::~Sequence" << endl);
221 delete btp ; btp = 0;
224 for_each(d_values.begin(), d_values.end(), delete_rows);
225 DBG2(cerr <<
"exiting Sequence::~Sequence" << endl);
249 oss << (*i)->toString();
265 i += (*iter)->element_count(
true);
275 bool seq_found =
false;
293 linear = (*iter)->is_simple_type();
304 (*i)->set_send_p(state);
314 (*i)->set_read_p(state);
324 (*i)->set_in_selection(state);
344 "Cannot add variable: NULL pointer");
350 _vars.push_back(bt_copy);
359 BaseType *btp = m_exact_match(name, &s);
363 return m_leaf_match(name, &s);
372 return m_exact_match(n, s);
374 return m_leaf_match(n, s);
381 if ((*i)->name() ==
name) {
383 s->push(static_cast<BaseType *>(
this));
386 if ((*i)->is_constructor_type()) {
390 s->push(static_cast<BaseType *>(
this));
400 Sequence::m_exact_match(
const string &name,
btp_stack *s)
403 if ((*i)->name() ==
name) {
405 s->push(static_cast<BaseType *>(
this));
410 string::size_type dot_pos = name.find(
".");
411 if (dot_pos != string::npos) {
412 string aggregate = name.substr(0, dot_pos);
413 string field = name.substr(dot_pos + 1);
418 s->push(static_cast<BaseType *>(
this));
419 return agg_ptr->
var(field,
true, s);
435 if (row >= d_values.size())
437 return d_values[row];
472 BaseTypeRow::iterator bt_row_iter = bt_row_ptr->begin();
473 BaseTypeRow::iterator bt_row_end = bt_row_ptr->end();
474 while (bt_row_iter != bt_row_end && (*bt_row_iter)->name() !=
name)
477 if (bt_row_iter == bt_row_end)
495 if (i >= bt_row_ptr->size())
498 return (*bt_row_ptr)[i];
541 return d_values.size();
609 DBG2(cerr <<
"Entering Sequence::read_row for " <<
name() << endl);
610 if (row < d_row_number)
611 throw InternalErr(
"Trying to back up inside a sequence!");
613 DBG2(cerr <<
"read_row: row number " << row
614 <<
", current row " << d_row_number << endl);
615 if (row == d_row_number)
617 DBG2(cerr <<
"Leaving Sequence::read_row for " <<
name() << endl);
624 while (!eof && d_row_number < row) {
626 eof = (
read() ==
false);
647 DBG2(cerr <<
"Leaving Sequence::read_row for " <<
name()
648 <<
" with " << (eof == 0) << endl);
660 Sequence::is_end_of_rows(
int i)
662 return ((d_ending_row_number == -1) ?
false : (i > d_ending_row_number));
729 DBG2(cerr <<
"Entering Sequence::serialize for " <<
name() << endl);
746 DBG2(cerr <<
"Entering serialize_parent_part_one for " <<
name() << endl);
748 int i = (d_starting_row_number != -1) ? d_starting_row_number : 0;
754 bool status =
read_row(i, dds, eval,
false);
755 DBG2(cerr <<
"Sequence::serialize_parent_part_one::read_row() status: " << status << endl);
757 while (status && !is_end_of_rows(i)) {
775 (*iter)->serialize(eval, dds, m);
780 status =
read_row(i, dds, eval,
false);
781 DBG(cerr <<
"Sequence::serialize_parent_part_one::read_row() status: " << status << endl);
789 if (d_top_most || d_wrote_soi) {
790 DBG(cerr <<
"Writing End of Sequence marker" << endl);
791 write_end_of_sequence(m);
812 DBG(cerr <<
"Entering serialize_parent_part_two for " <<
name() << endl);
816 dynamic_cast<Sequence&>(*btp).serialize_parent_part_two(dds, eval, m);
819 DBG(cerr <<
"Writing Start of Instance marker" << endl);
821 write_start_of_instance(m);
826 DBG(cerr <<
"Sequence::serialize_parent_part_two(), serializing " 827 << (*iter)->name() << endl);
829 DBG(cerr <<
"Send P is true, sending " << (*iter)->name() << endl);
830 (*iter)->serialize(eval, dds, m,
false);
834 d_unsent_data =
false;
844 DBG(cerr <<
"Entering Sequence::serialize_leaf for " <<
name() << endl);
845 int i = (d_starting_row_number != -1) ? d_starting_row_number : 0;
849 bool status =
read_row(i, dds, eval, ce_eval);
850 DBG(cerr <<
"Sequence::serialize_leaf::read_row() status: " << status << endl);
864 if (status && !is_end_of_rows(i)) {
867 dynamic_cast<Sequence&>(*btp).serialize_parent_part_two(dds,
872 while (status && !is_end_of_rows(i)) {
875 DBG(cerr <<
"Writing Start of Instance marker" << endl);
877 write_start_of_instance(m);
881 DBG(cerr <<
"Sequence::serialize_leaf(), serializing " 882 << (*iter)->name() << endl);
883 if ((*iter)->send_p()) {
884 DBG(cerr <<
"Send P is true, sending " << (*iter)->name() << endl);
885 (*iter)->serialize(eval, dds, m,
false);
891 status =
read_row(i, dds, eval, ce_eval);
892 DBG(cerr <<
"Sequence::serialize_leaf::read_row() status: " << status << endl);
897 if (d_wrote_soi || d_top_most) {
898 DBG(cerr <<
"Writing End of Sequence marker" << endl);
899 write_end_of_sequence(m);
930 DBG(cerr <<
"Sequence::intern_data - for " <<
name() << endl);
931 DBG2(cerr <<
" intern_data, values: " << &d_values << endl);
938 DBG2(cerr <<
" pushing d_values of " <<
name() <<
" (" << &d_values
939 <<
") on stack; size: " << sequence_values_stack.size() << endl);
940 sequence_values_stack.push(&d_values);
950 DBG(cerr <<
"Entering intern_data_private for " <<
name() << endl);
962 sequence_values_stack)
964 DBG(cerr <<
"Entering intern_data_parent_part_one for " <<
name() << endl);
972 bool status =
read_row(i, dds, eval,
false);
980 SequenceValues::size_type orig_stack_size = sequence_values_stack.size() ;
988 if ((*iter)->send_p()) {
989 switch ((*iter)->type()) {
992 eval, dds, sequence_values_stack);
996 (*iter)->intern_data(eval, dds);
1004 status =
read_row(i, dds, eval,
false);
1014 if( sequence_values_stack.size() > orig_stack_size )
1016 DBG2(cerr <<
" popping d_values (" << sequence_values_stack.top()
1017 <<
") off stack; size: " << sequence_values_stack.size() << endl);
1018 sequence_values_stack.pop();
1020 DBG(cerr <<
"Leaving intern_data_parent_part_one for " <<
name() << endl);
1028 DBG(cerr <<
"Entering intern_data_parent_part_two for " <<
name() << endl);
1033 dds, eval, sequence_values_stack);
1036 DBG2(cerr <<
" stack size: " << sequence_values_stack.size() << endl);
1038 DBG2(cerr <<
" using values = " << (
void *)values << endl);
1047 row_data->push_back((*iter)->ptr_duplicate());
1049 else if ((*iter)->send_p()) {
1052 throw InternalErr(__FILE__, __LINE__,
"Expected a Sequence.");
1053 row_data->push_back(tmp);
1054 DBG2(cerr <<
" pushing d_values of " << tmp->
name()
1055 <<
" (" << &(tmp->d_values)
1056 <<
") on stack; size: " << sequence_values_stack.size()
1061 sequence_values_stack.push(&(tmp->d_values));
1065 DBG2(cerr <<
" pushing values for " <<
name()
1066 <<
" to " << values << endl);
1067 values->push_back(row_data);
1070 DBG(cerr <<
"Leaving intern_data_parent_part_two for " <<
name() << endl);
1078 DBG(cerr <<
"Entering intern_data_for_leaf for " <<
name() << endl);
1082 DBG2(cerr <<
" reading row " << i << endl);
1083 bool status =
read_row(i, dds, eval,
true);
1084 DBG2(cerr <<
" status: " << status << endl);
1094 dds, eval, sequence_values_stack);
1101 DBG2(cerr <<
" using values = " << values << endl);
1110 if ((*iter)->send_p()) {
1111 row_data->push_back((*iter)->ptr_duplicate());
1115 DBG2(cerr <<
" pushing values for " <<
name()
1116 <<
" to " << values << endl);
1118 values->push_back(row_data);
1122 status =
read_row(i, dds, eval,
true);
1125 DBG2(cerr <<
" popping d_values (" << sequence_values_stack.top()
1126 <<
") off stack; size: " << sequence_values_stack.size() << endl);
1127 sequence_values_stack.pop();
1129 DBG(cerr <<
"Leaving intern_data_for_leaf for " <<
name() << endl);
1157 throw InternalErr(
"Expected argument 'dds' to be a DataDDS!");
1159 DBG2(cerr <<
"Reading from server/protocol version: " 1166 +
") indicates that this\nis an old server which may not correctly transmit Sequence variables.\nContact the server administrator.");
1171 unsigned char marker = read_marker(um);
1172 if (is_end_of_sequence(marker))
1174 else if (is_start_of_instance(marker)) {
1176 DBG2(cerr <<
"Reading row " << d_row_number <<
" of " 1183 DBG2(cerr <<
"Deserialized " << bt_ptr->
name() <<
" (" 1184 << bt_ptr <<
") = ");
1186 bt_row_ptr->push_back(bt_ptr);
1189 d_values.push_back(bt_row_ptr);
1192 throw Error(
"I could not read the expected Sequence data stream marker!");
1214 return d_starting_row_number;
1230 return d_row_stride;
1247 return d_ending_row_number;
1264 d_starting_row_number = start;
1265 d_row_stride = stride;
1266 d_ending_row_number = stop;
1274 throw InternalErr(__FILE__, __LINE__,
"Never use this method; see the programmer's guide documentation.");
1285 throw InternalErr(__FILE__, __LINE__,
"Use Sequence::var_value() or Sequence::row_value() in place of Sequence::buf2val()");
1295 fprintf(out,
"\n%s%d: ", space.c_str(), row) ;
1297 fprintf(out,
"{ ") ;
1303 for (j = 0; j < elements; ++j) {
1307 dynamic_cast<Sequence*>(bt_ptr)->print_val_by_rows
1308 (out, space +
" ",
false, print_row_num);
1311 fprintf(out,
", ") ;
1319 dynamic_cast<Sequence*>(bt_ptr)->print_val_by_rows
1320 (out, space +
" ",
false, print_row_num);
1325 fprintf(out,
" }") ;
1334 out <<
"\n" << space << row <<
": " ;
1348 while (j < elements && !bt_ptr) {
1352 dynamic_cast<Sequence*>(bt_ptr)->print_val_by_rows
1353 (out, space +
" ",
false, print_row_num);
1360 while (j < elements) {
1365 dynamic_cast<Sequence*>(bt_ptr)->print_val_by_rows
1366 (out, space +
" ",
false, print_row_num);
1378 bool print_row_numbers)
1382 fprintf(out,
" = ") ;
1385 fprintf(out,
"{ ") ;
1389 for (i = 0; i < rows; ++i) {
1391 fprintf(out,
", ") ;
1395 fprintf(out,
" }") ;
1398 fprintf(out,
";\n") ;
1404 bool print_row_numbers)
1415 for (i = 0; i < rows; ++i) {
1453 if (!(*i)->check_semantics(msg,
true)) {
1464 d_leaf_sequence = state;
1470 return d_leaf_sequence;
1500 bool has_child_sequence =
false;
1502 if (lvl == 1) d_top_most =
true;
1504 DBG2(cerr <<
"Processing sequence " <<
name() << endl);
1513 if (has_child_sequence)
1514 throw Error(
"This implementation does not support more than one nested sequence at a level. Contact the server administrator.");
1516 has_child_sequence =
true;
1524 if (!has_child_sequence)
1544 << (
void *)
this <<
")" << endl ;
virtual bool read()
Read data into a local buffer.
int get_protocol_minor() const
virtual bool read_p()
Has this variable been read?
string name() const
Returns the name of the class instance.
virtual void intern_data(ConstraintEvaluator &eval, DDS &dds)
abstract base class used to unmarshall/deserialize dap data objects
Part
Names the parts of multi-section constructor data types.
string get_protocol() const
bool unique_names(vector< BaseType *> l, const string &var_name, const string &type_name, string &msg)
void set_unsent_data(bool usd)
Set the unsent data property.
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)=0
Receive data from the net.
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 * > _vars
std::vector< BaseType * >::iterator Vars_iter
virtual int element_count(bool leaves=false)
Count the members of constructor types.
virtual BaseType * get_parent()
vector< BaseTypeRow * > SequenceValues
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
virtual bool serialize_leaf(DDS &dds, ConstraintEvaluator &eval, Marshaller &m, bool ce_eval)
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.
virtual string toString()
virtual void set_in_selection(bool state)
virtual void print_val_by_rows(ostream &out, string space="", bool print_decl_p=true, bool print_row_numbers=true)
stack< BaseType * > btp_stack
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)
bool eval_selection(DDS &dds, const string &dataset)
Evaluate a boolean-valued constraint expression. This is main method for the evaluator ans is called ...
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)
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
Returns a pointer to a member of a constructor class.
bool get_unsent_data()
Get the unsent data property.
virtual void set_send_p(bool state)
Sequence(const string &n)
The Sequence constructor.
Type type() const
Returns the type of the class instance.
virtual void set_leaf_sequence(int lvl=1)
Mark the Sequence which holds the leaf elements.
Sequence & operator=(const Sequence &rhs)
virtual void set_read_p(bool state)
Sets the value of the read_p property.
virtual unsigned int buf2val(void **val)
virtual void set_in_selection(bool state)
vector< BaseType * > BaseTypeRow
virtual void serialize_parent_part_two(DDS &dds, ConstraintEvaluator &eval, Marshaller &m)
virtual void dump(ostream &strm) const
dumps information about this object
virtual bool is_leaf_sequence()
virtual string toString()
virtual BaseType * ptr_duplicate()=0
string www2id(const string &in, const string &escape, const string &except)
int get_starting_row_number()
Get the starting row number.
Evaluate a constraint expression.
virtual SequenceValues value()
virtual int number_of_rows()
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 void set_read_p(bool state)
Sets the value of the read_p property.
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.
The basic data type for the DODS DAP types.
abstract base class used to marshal/serialize dap data objects
virtual unsigned int val2buf(void *val, bool reuse=false)
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.
string type_name() const
Returns the type of the class instance as a string.
virtual void print_one_row(ostream &out, int row, string space, bool print_row_num=false)
virtual void add_var(BaseType *, Part part=nil)
Adds a variable to the Sequence.
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.
int get_protocol_major() const
virtual bool serialize_parent_part_one(DDS &dds, ConstraintEvaluator &eval, Marshaller &m)
virtual void set_leaf_p(bool state)
virtual void dump(ostream &strm) const
dumps information about this object
stack< SequenceValues * > sequence_values_stack_t
A class for error processing.
virtual int get_ending_row_number()
Get the ending row number.
virtual unsigned int width()
Returns the size of the class instance data.
virtual void set_send_p(bool state)
virtual BaseType * ptr_duplicate()
virtual int get_row_stride()
Get the row stride.
virtual BaseType * var(const string &name, bool exact_match=true, btp_stack *s=0)
Returns a pointer to a member of a constructor class.
virtual void set_value(SequenceValues &values)
string dataset() const
Returns the name of the dataset used to create this instance.
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)=0
Prints the value of the variable.
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.