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);
369 "Cannot add variable: NULL pointer");
380 BaseType *btp = m_exact_match(name, &s);
384 return m_leaf_match(name, &s);
393 return m_exact_match(n, s);
395 return m_leaf_match(n, s);
399 Sequence::m_leaf_match(
const string &name, btp_stack *s)
402 if ((*i)->name() ==
name) {
404 s->push(static_cast<BaseType *>(
this));
407 if ((*i)->is_constructor_type()) {
408 BaseType *btp = (*i)->var(name,
false, s);
411 s->push(static_cast<BaseType *>(
this));
421 Sequence::m_exact_match(
const string &name, btp_stack *s)
424 if ((*i)->name() ==
name) {
426 s->push(static_cast<BaseType *>(
this));
431 string::size_type dot_pos = name.find(
".");
432 if (dot_pos != string::npos) {
433 string aggregate = name.substr(0, dot_pos);
434 string field = name.substr(dot_pos + 1);
439 s->push(static_cast<BaseType *>(
this));
440 return agg_ptr->var(field,
true, s);
456 if (row >= d_values.size())
458 return d_values[row];
493 BaseTypeRow::iterator bt_row_iter = bt_row_ptr->begin();
494 BaseTypeRow::iterator bt_row_end = bt_row_ptr->end();
495 while (bt_row_iter != bt_row_end && (*bt_row_iter)->name() !=
name)
498 if (bt_row_iter == bt_row_end)
516 if (i >= bt_row_ptr->size())
519 return (*bt_row_ptr)[i];
549 sz += (*i)->width(constrained);
552 sz += (*i)->width(constrained);
587 return d_values.size();
655 DBG2(cerr <<
"Entering Sequence::read_row for " <<
name() << endl);
656 if (row < d_row_number)
657 throw InternalErr(
"Trying to back up inside a sequence!");
659 DBG2(cerr <<
"read_row: row number " << row
660 <<
", current row " << d_row_number << endl);
661 if (row == d_row_number)
663 DBG2(cerr <<
"Leaving Sequence::read_row for " <<
name() << endl);
670 while (!eof && d_row_number < row) {
672 eof = (
read() ==
false);
693 DBG2(cerr <<
"Leaving Sequence::read_row for " <<
name()
694 <<
" with " << (eof == 0) << endl);
706 Sequence::is_end_of_rows(
int i)
708 return ((d_ending_row_number == -1) ?
false : (i > d_ending_row_number));
775 DBG2(cerr <<
"Entering Sequence::serialize for " <<
name() << endl);
792 DBG2(cerr <<
"Entering serialize_parent_part_one for " <<
name() << endl);
794 int i = (d_starting_row_number != -1) ? d_starting_row_number : 0;
800 bool status =
read_row(i, dds, eval,
false);
801 DBG2(cerr <<
"Sequence::serialize_parent_part_one::read_row() status: " << status << endl);
803 while (status && !is_end_of_rows(i)) {
821 (*iter)->serialize(eval, dds, m);
826 status =
read_row(i, dds, eval,
false);
827 DBG(cerr <<
"Sequence::serialize_parent_part_one::read_row() status: " << status << endl);
835 if (d_top_most || d_wrote_soi) {
836 DBG(cerr <<
"Writing End of Sequence marker" << endl);
837 write_end_of_sequence(m);
858 DBG(cerr <<
"Entering serialize_parent_part_two for " <<
name() << endl);
862 dynamic_cast<Sequence&>(*btp).serialize_parent_part_two(dds, eval, m);
865 DBG(cerr <<
"Writing Start of Instance marker" << endl);
867 write_start_of_instance(m);
872 DBG(cerr <<
"Sequence::serialize_parent_part_two(), serializing "
873 << (*iter)->name() << endl);
875 DBG(cerr <<
"Send P is true, sending " << (*iter)->name() << endl);
876 (*iter)->serialize(eval, dds, m,
false);
880 d_unsent_data =
false;
890 DBG(cerr <<
"Entering Sequence::serialize_leaf for " <<
name() << endl);
891 int i = (d_starting_row_number != -1) ? d_starting_row_number : 0;
895 bool status =
read_row(i, dds, eval, ce_eval);
896 DBG(cerr <<
"Sequence::serialize_leaf::read_row() status: " << status << endl);
910 if (status && !is_end_of_rows(i)) {
913 dynamic_cast<Sequence&>(*btp).serialize_parent_part_two(dds,
918 while (status && !is_end_of_rows(i)) {
921 DBG(cerr <<
"Writing Start of Instance marker" << endl);
923 write_start_of_instance(m);
927 DBG(cerr <<
"Sequence::serialize_leaf(), serializing "
928 << (*iter)->name() << endl);
929 if ((*iter)->send_p()) {
930 DBG(cerr <<
"Send P is true, sending " << (*iter)->name() << endl);
931 (*iter)->serialize(eval, dds, m,
false);
937 status =
read_row(i, dds, eval, ce_eval);
938 DBG(cerr <<
"Sequence::serialize_leaf::read_row() status: " << status << endl);
943 if (d_wrote_soi || d_top_most) {
944 DBG(cerr <<
"Writing End of Sequence marker" << endl);
945 write_end_of_sequence(m);
976 DBG(cerr <<
"Sequence::intern_data - for " <<
name() << endl);
977 DBG2(cerr <<
" intern_data, values: " << &d_values << endl);
984 DBG2(cerr <<
" pushing d_values of " <<
name() <<
" (" << &d_values
985 <<
") on stack; size: " << sequence_values_stack.size() << endl);
986 sequence_values_stack.push(&d_values);
996 DBG(cerr <<
"Entering intern_data_private for " <<
name() << endl);
1008 sequence_values_stack)
1010 DBG(cerr <<
"Entering intern_data_parent_part_one for " <<
name() << endl);
1018 bool status =
read_row(i, dds, eval,
false);
1026 SequenceValues::size_type orig_stack_size = sequence_values_stack.size() ;
1034 if ((*iter)->send_p()) {
1035 switch ((*iter)->type()) {
1038 eval, dds, sequence_values_stack);
1042 (*iter)->intern_data(eval, dds);
1050 status =
read_row(i, dds, eval,
false);
1060 if( sequence_values_stack.size() > orig_stack_size )
1062 DBG2(cerr <<
" popping d_values (" << sequence_values_stack.top()
1063 <<
") off stack; size: " << sequence_values_stack.size() << endl);
1064 sequence_values_stack.pop();
1066 DBG(cerr <<
"Leaving intern_data_parent_part_one for " <<
name() << endl);
1074 DBG(cerr <<
"Entering intern_data_parent_part_two for " <<
name() << endl);
1079 dds, eval, sequence_values_stack);
1082 DBG2(cerr <<
" stack size: " << sequence_values_stack.size() << endl);
1084 DBG2(cerr <<
" using values = " << (
void *)values << endl);
1093 row_data->push_back((*iter)->ptr_duplicate());
1095 else if ((*iter)->send_p()) {
1099 throw InternalErr(__FILE__, __LINE__,
"Expected a Sequence.");
1101 row_data->push_back(tmp);
1102 DBG2(cerr <<
" pushing d_values of " << tmp->
name()
1103 <<
" (" << &(tmp->d_values)
1104 <<
") on stack; size: " << sequence_values_stack.size()
1109 sequence_values_stack.push(&(tmp->d_values));
1113 DBG2(cerr <<
" pushing values for " <<
name()
1114 <<
" to " << values << endl);
1115 values->push_back(row_data);
1118 DBG(cerr <<
"Leaving intern_data_parent_part_two for " <<
name() << endl);
1126 DBG(cerr <<
"Entering intern_data_for_leaf for " <<
name() << endl);
1130 DBG2(cerr <<
" reading row " << i << endl);
1131 bool status =
read_row(i, dds, eval,
true);
1132 DBG2(cerr <<
" status: " << status << endl);
1142 dds, eval, sequence_values_stack);
1149 DBG2(cerr <<
" using values = " << values << endl);
1158 if ((*iter)->send_p()) {
1159 row_data->push_back((*iter)->ptr_duplicate());
1163 DBG2(cerr <<
" pushing values for " <<
name()
1164 <<
" to " << values << endl);
1166 values->push_back(row_data);
1170 status =
read_row(i, dds, eval,
true);
1173 DBG2(cerr <<
" popping d_values (" << sequence_values_stack.top()
1174 <<
") off stack; size: " << sequence_values_stack.size() << endl);
1175 sequence_values_stack.pop();
1177 DBG(cerr <<
"Leaving intern_data_for_leaf for " <<
name() << endl);
1205 throw InternalErr(
"Expected argument 'dds' to be a DataDDS!");
1207 DBG2(cerr <<
"Reading from server/protocol version: "
1214 +
") indicates that this\nis an old server which may not correctly transmit Sequence variables.\nContact the server administrator.");
1219 unsigned char marker = read_marker(um);
1220 if (is_end_of_sequence(marker))
1222 else if (is_start_of_instance(marker)) {
1224 DBG2(cerr <<
"Reading row " << d_row_number <<
" of "
1231 DBG2(cerr <<
"Deserialized " << bt_ptr->
name() <<
" ("
1232 << bt_ptr <<
") = ");
1234 bt_row_ptr->push_back(bt_ptr);
1237 d_values.push_back(bt_row_ptr);
1240 throw Error(
"I could not read the expected Sequence data stream marker!");
1262 return d_starting_row_number;
1278 return d_row_stride;
1295 return d_ending_row_number;
1312 d_starting_row_number = start;
1313 d_row_stride = stride;
1314 d_ending_row_number = stop;
1322 throw InternalErr(__FILE__, __LINE__,
"Never use this method; see the programmer's guide documentation.");
1333 throw InternalErr(__FILE__, __LINE__,
"Use Sequence::var_value() or Sequence::row_value() in place of Sequence::buf2val()");
1343 fprintf(out,
"\n%s%d: ", space.c_str(), row) ;
1345 fprintf(out,
"{ ") ;
1351 for (j = 0; j < elements; ++j) {
1355 dynamic_cast<Sequence*>(bt_ptr)->print_val_by_rows
1356 (out, space +
" ",
false, print_row_num);
1359 fprintf(out,
", ") ;
1367 dynamic_cast<Sequence*>(bt_ptr)->print_val_by_rows
1368 (out, space +
" ",
false, print_row_num);
1373 fprintf(out,
" }") ;
1382 out <<
"\n" << space << row <<
": " ;
1396 while (j < elements && !bt_ptr) {
1400 dynamic_cast<Sequence*>(bt_ptr)->print_val_by_rows
1401 (out, space +
" ",
false, print_row_num);
1408 while (j < elements) {
1413 dynamic_cast<Sequence*>(bt_ptr)->print_val_by_rows
1414 (out, space +
" ",
false, print_row_num);
1426 bool print_row_numbers)
1430 fprintf(out,
" = ") ;
1433 fprintf(out,
"{ ") ;
1437 for (i = 0; i < rows; ++i) {
1439 fprintf(out,
", ") ;
1443 fprintf(out,
" }") ;
1446 fprintf(out,
";\n") ;
1452 bool print_row_numbers)
1463 for (i = 0; i < rows; ++i) {
1501 if (!(*i)->check_semantics(msg,
true)) {
1512 d_leaf_sequence = state;
1518 return d_leaf_sequence;
1548 bool has_child_sequence =
false;
1550 if (lvl == 1) d_top_most =
true;
1552 DBG2(cerr <<
"Processing sequence " <<
name() << endl);
1561 if (has_child_sequence)
1562 throw Error(
"This implementation does not support more than one nested sequence at a level. Contact the server administrator.");
1564 has_child_sequence =
true;
1572 if (!has_child_sequence)
1592 << (
void *)
this <<
")" << endl ;
virtual bool read()
Read data into a local buffer.
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
Part
Names the parts of multi-section constructor data types.
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)
int get_protocol_minor() const
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.
Type type() const
Returns the type of the class instance.
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)
string dataset() const
Returns the name of the dataset used to create this instance.
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)
string type_name() const
Returns the type of the class instance as a string.
bool get_unsent_data()
Get the unsent data property.
virtual void set_send_p(bool state)
Sequence(const string &n)
The Sequence constructor.
virtual void set_leaf_sequence(int lvl=1)
Mark the Sequence which holds the leaf elements.
Sequence & operator=(const Sequence &rhs)
virtual void add_var_nocopy(BaseType *, Part part=nil)
Adds a variable to the Sequence.
virtual void set_read_p(bool state)
Sets the value of the read_p property.
virtual void dump(ostream &strm) const
dumps information about this object
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 bool is_leaf_sequence()
string name() const
Returns the name of the class instance.
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.
BaseType(const string &n, const Type &t)
The BaseType constructor.
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.
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)
bool unique_names(vector< BaseType * > l, const string &var_name, const string &type_name, string &msg)
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
string get_protocol() const
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
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.
int get_protocol_major() const
virtual void set_value(SequenceValues &values)
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.