76 static const unsigned char end_of_sequence = 0xA5;
77 static const unsigned char start_of_instance = 0x5A;
84 d_row_number = s.d_row_number;
85 d_starting_row_number = s.d_starting_row_number;
86 d_ending_row_number = s.d_ending_row_number;
87 d_row_stride = s.d_row_stride;
88 d_leaf_sequence = s.d_leaf_sequence;
89 d_unsent_data = s.d_unsent_data;
90 d_wrote_soi = s.d_wrote_soi;
91 d_top_most = s.d_top_most;
101 for (vector<BaseTypeRow *>::iterator rows_iter = cs.d_values.begin();
102 rows_iter != cs.d_values.end();
110 for (BaseTypeRow::iterator bt_row_iter = src_bt_row_ptr->begin();
111 bt_row_iter != src_bt_row_ptr->end();
113 BaseType *src_bt_ptr = *bt_row_iter;
115 dest_bt_row_ptr->push_back(dest_bt_ptr);
118 d_values.push_back(dest_bt_row_ptr);
129 write_start_of_instance(Marshaller &m)
131 m.put_opaque( (
char *)&start_of_instance, 1 ) ;
135 read_marker(UnMarshaller &um)
137 unsigned char marker;
138 um.get_opaque( (
char *)&marker, 1 ) ;
144 is_start_of_instance(
unsigned char marker)
146 return (marker == start_of_instance);
150 is_end_of_sequence(
unsigned char marker)
152 return (marker == end_of_sequence);
166 d_row_number(-1), d_starting_row_number(-1),
167 d_row_stride(1), d_ending_row_number(-1),
168 d_unsent_data(false), d_wrote_soi(false),
169 d_leaf_sequence(false), d_top_most(false)
184 d_row_number(-1), d_starting_row_number(-1),
185 d_row_stride(1), d_ending_row_number(-1),
186 d_unsent_data(false), d_wrote_soi(false),
187 d_leaf_sequence(false), d_top_most(false)
205 DBG2(cerr <<
"In delete_bt: " << bt_ptr << endl);
206 delete bt_ptr; bt_ptr = 0;
212 DBG2(cerr <<
"In delete_rows: " << bt_row_ptr << endl);
214 for_each(bt_row_ptr->begin(), bt_row_ptr->end(), delete_bt);
216 delete bt_row_ptr; bt_row_ptr = 0;
221 DBG2(cerr <<
"Entering Sequence::~Sequence" << endl);
224 delete btp ; btp = 0;
227 for_each(d_values.begin(), d_values.end(), delete_rows);
228 DBG2(cerr <<
"exiting Sequence::~Sequence" << endl);
261 oss << (*i)->toString();
278 i += (*iter)->element_count(
true);
289 bool seq_found =
false;
307 linear = (*iter)->is_simple_type();
319 (*i)->set_send_p(state);
329 (*i)->set_read_p(state);
340 (*i)->set_in_selection(state);
360 throw InternalErr(__FILE__, __LINE__,
361 "Cannot add variable: NULL pointer");
362 if (bt->is_dap4_only_type())
363 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 Sequence.");
368 BaseType *bt_copy = bt->ptr_duplicate();
369 bt_copy->set_parent(
this);
370 d_vars.push_back(bt_copy);
388 throw InternalErr(__FILE__, __LINE__,
389 "Cannot add variable: NULL pointer");
390 if (bt->is_dap4_only_type())
391 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 Sequence.");
393 bt->set_parent(
this);
412 Sequence::var(
const string &name,
bool exact_match, btp_stack *s)
427 if ((*i)->name() ==
name) {
429 s->push(static_cast<BaseType *>(
this));
432 if ((*i)->is_constructor_type()) {
433 BaseType *btp = (*i)->var(name,
false, s);
436 s->push(static_cast<BaseType *>(
this));
449 if ((*i)->name() ==
name) {
451 s->push(static_cast<BaseType *>(
this));
456 string::size_type dot_pos = name.find(
".");
457 if (dot_pos != string::npos) {
458 string aggregate = name.substr(0, dot_pos);
459 string field = name.substr(dot_pos + 1);
464 s->push(static_cast<BaseType *>(
this));
465 return agg_ptr->var(field,
true, s);
481 if (row >= d_values.size())
483 return d_values[row];
518 BaseTypeRow::iterator bt_row_iter = bt_row_ptr->begin();
519 BaseTypeRow::iterator bt_row_end = bt_row_ptr->end();
520 while (bt_row_iter != bt_row_end && (*bt_row_iter)->name() !=
name)
523 if (bt_row_iter == bt_row_end)
541 if (i >= bt_row_ptr->size())
544 return (*bt_row_ptr)[i];
575 sz += (*i)->width(constrained);
578 sz += (*i)->width(constrained);
614 return d_values.size();
682 DBG2(cerr <<
"Entering Sequence::read_row for " <<
name() << endl);
683 if (row < d_row_number)
684 throw InternalErr(
"Trying to back up inside a sequence!");
686 DBG2(cerr <<
"read_row: row number " << row
687 <<
", current row " << d_row_number << endl);
688 if (row == d_row_number)
690 DBG2(cerr <<
"Leaving Sequence::read_row for " <<
name() << endl);
697 while (!eof && d_row_number < row) {
699 eof = (
read() ==
false);
720 DBG2(cerr <<
"Leaving Sequence::read_row for " <<
name()
721 <<
" with " << (eof == 0) << endl);
733 Sequence::is_end_of_rows(
int i)
735 return ((d_ending_row_number == -1) ?
false : (i > d_ending_row_number));
802 DBG2(cerr <<
"Entering Sequence::serialize for " <<
name() << endl);
819 DBG2(cerr <<
"Entering serialize_parent_part_one for " <<
name() << endl);
821 int i = (d_starting_row_number != -1) ? d_starting_row_number : 0;
827 bool status =
read_row(i, dds, eval,
false);
828 DBG2(cerr <<
"Sequence::serialize_parent_part_one::read_row() status: " << status << endl);
830 while (status && !is_end_of_rows(i)) {
848 (*iter)->serialize(eval, dds, m);
853 status =
read_row(i, dds, eval,
false);
854 DBG(cerr <<
"Sequence::serialize_parent_part_one::read_row() status: " << status << endl);
862 if (d_top_most || d_wrote_soi) {
863 DBG(cerr <<
"Writing End of Sequence marker" << endl);
864 write_end_of_sequence(m);
885 DBG(cerr <<
"Entering serialize_parent_part_two for " <<
name() << endl);
889 static_cast<Sequence&>(*btp).serialize_parent_part_two(dds, eval, m);
892 DBG(cerr <<
"Writing Start of Instance marker" << endl);
894 write_start_of_instance(m);
899 DBG(cerr <<
"Sequence::serialize_parent_part_two(), serializing "
900 << (*iter)->name() << endl);
902 DBG(cerr <<
"Send P is true, sending " << (*iter)->name() << endl);
903 (*iter)->serialize(eval, dds, m,
false);
907 d_unsent_data =
false;
917 DBG(cerr <<
"Entering Sequence::serialize_leaf for " <<
name() << endl);
918 int i = (d_starting_row_number != -1) ? d_starting_row_number : 0;
922 bool status =
read_row(i, dds, eval, ce_eval);
923 DBG(cerr <<
"Sequence::serialize_leaf::read_row() status: " << status << endl);
937 if (status && !is_end_of_rows(i)) {
940 static_cast<Sequence&>(*btp).serialize_parent_part_two(dds,
945 while (status && !is_end_of_rows(i)) {
948 DBG(cerr <<
"Writing Start of Instance marker" << endl);
950 write_start_of_instance(m);
954 DBG(cerr <<
"Sequence::serialize_leaf(), serializing "
955 << (*iter)->name() << endl);
956 if ((*iter)->send_p()) {
957 DBG(cerr <<
"Send P is true, sending " << (*iter)->name() << endl);
958 (*iter)->serialize(eval, dds, m,
false);
964 status =
read_row(i, dds, eval, ce_eval);
965 DBG(cerr <<
"Sequence::serialize_leaf::read_row() status: " << status << endl);
970 if (d_wrote_soi || d_top_most) {
971 DBG(cerr <<
"Writing End of Sequence marker" << endl);
972 write_end_of_sequence(m);
1003 DBG(cerr <<
"Sequence::intern_data - for " <<
name() << endl);
1004 DBG2(cerr <<
" intern_data, values: " << &d_values << endl);
1011 DBG2(cerr <<
" pushing d_values of " <<
name() <<
" (" << &d_values
1012 <<
") on stack; size: " << sequence_values_stack.size() << endl);
1013 sequence_values_stack.push(&d_values);
1023 DBG(cerr <<
"Entering intern_data_private for " <<
name() << endl);
1035 sequence_values_stack)
1037 DBG(cerr <<
"Entering intern_data_parent_part_one for " <<
name() << endl);
1045 bool status =
read_row(i, dds, eval,
false);
1053 SequenceValues::size_type orig_stack_size = sequence_values_stack.size() ;
1061 if ((*iter)->send_p()) {
1062 switch ((*iter)->type()) {
1065 eval, dds, sequence_values_stack);
1069 (*iter)->intern_data(eval, dds);
1077 status =
read_row(i, dds, eval,
false);
1087 if( sequence_values_stack.size() > orig_stack_size )
1089 DBG2(cerr <<
" popping d_values (" << sequence_values_stack.top()
1090 <<
") off stack; size: " << sequence_values_stack.size() << endl);
1091 sequence_values_stack.pop();
1093 DBG(cerr <<
"Leaving intern_data_parent_part_one for " <<
name() << endl);
1101 DBG(cerr <<
"Entering intern_data_parent_part_two for " <<
name() << endl);
1106 dds, eval, sequence_values_stack);
1109 DBG2(cerr <<
" stack size: " << sequence_values_stack.size() << endl);
1111 DBG2(cerr <<
" using values = " << (
void *)values << endl);
1120 row_data->push_back((*iter)->ptr_duplicate());
1122 else if ((*iter)->send_p()) {
1126 throw InternalErr(__FILE__, __LINE__,
"Expected a Sequence.");
1128 row_data->push_back(tmp);
1129 DBG2(cerr <<
" pushing d_values of " << tmp->
name()
1130 <<
" (" << &(tmp->d_values)
1131 <<
") on stack; size: " << sequence_values_stack.size()
1136 sequence_values_stack.push(&(tmp->d_values));
1140 DBG2(cerr <<
" pushing values for " <<
name()
1141 <<
" to " << values << endl);
1142 values->push_back(row_data);
1145 DBG(cerr <<
"Leaving intern_data_parent_part_two for " <<
name() << endl);
1153 DBG(cerr <<
"Entering intern_data_for_leaf for " <<
name() << endl);
1157 DBG2(cerr <<
" reading row " << i << endl);
1158 bool status =
read_row(i, dds, eval,
true);
1159 DBG2(cerr <<
" status: " << status << endl);
1169 dds, eval, sequence_values_stack);
1176 DBG2(cerr <<
" using values = " << values << endl);
1185 if ((*iter)->send_p()) {
1186 row_data->push_back((*iter)->ptr_duplicate());
1190 DBG2(cerr <<
" pushing values for " <<
name()
1191 <<
" to " << values << endl);
1193 values->push_back(row_data);
1197 status =
read_row(i, dds, eval,
true);
1200 DBG2(cerr <<
" popping d_values (" << sequence_values_stack.top()
1201 <<
") off stack; size: " << sequence_values_stack.size() << endl);
1202 sequence_values_stack.pop();
1204 DBG(cerr <<
"Leaving intern_data_for_leaf for " <<
name() << endl);
1232 throw InternalErr(
"Expected argument 'dds' to be a DataDDS!");
1234 DBG2(cerr <<
"Reading from server/protocol version: "
1241 +
") indicates that this\nis an old server which may not correctly transmit Sequence variables.\nContact the server administrator.");
1246 unsigned char marker = read_marker(um);
1247 if (is_end_of_sequence(marker))
1249 else if (is_start_of_instance(marker)) {
1251 DBG2(cerr <<
"Reading row " << d_row_number <<
" of "
1258 DBG2(cerr <<
"Deserialized " << bt_ptr->
name() <<
" ("
1259 << bt_ptr <<
") = ");
1261 bt_row_ptr->push_back(bt_ptr);
1264 d_values.push_back(bt_row_ptr);
1267 throw Error(
"I could not read the expected Sequence data stream marker!");
1289 return d_starting_row_number;
1305 return d_row_stride;
1322 return d_ending_row_number;
1339 d_starting_row_number = start;
1340 d_row_stride = stride;
1341 d_ending_row_number = stop;
1350 throw InternalErr(__FILE__, __LINE__,
"Never use this method; see the programmer's guide documentation.");
1361 throw InternalErr(__FILE__, __LINE__,
"Use Sequence::var_value() or Sequence::row_value() in place of Sequence::buf2val()");
1372 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
1380 out <<
"\n" << space << row <<
": " ;
1394 while (j < elements && !bt_ptr) {
1398 static_cast<Sequence*>(bt_ptr)->print_val_by_rows
1399 (out, space +
" ",
false, print_row_num);
1406 while (j < elements) {
1411 static_cast<Sequence*>(bt_ptr)->print_val_by_rows
1412 (out, space +
" ",
false, print_row_num);
1423 bool print_row_numbers)
1427 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
1432 bool print_row_numbers)
1443 for (i = 0; i < rows; ++i) {
1479 if (!(*i)->check_semantics(msg,
true)) {
1491 d_leaf_sequence = state;
1497 return d_leaf_sequence;
1527 bool has_child_sequence =
false;
1529 if (lvl == 1) d_top_most =
true;
1531 DBG2(cerr <<
"Processing sequence " <<
name() << endl);
1540 if (has_child_sequence)
1541 throw Error(
"This implementation does not support more than one nested sequence at a level. Contact the server administrator.");
1543 has_child_sequence =
true;
1551 if (!has_child_sequence)
1571 << (
void *)
this <<
")" << endl ;
virtual bool read_p()
Has this variable been read?
virtual void intern_data(ConstraintEvaluator &eval, DDS &dds)
virtual void set_in_selection(bool state)
Set the in_selection property.
abstract base class used to unmarshall/deserialize dap data objects
virtual void dump(ostream &strm) const
dumps information about this object
virtual BaseType * var(const string &name, bool exact_match=true, btp_stack *s=0)
btp_stack no longer needed; use back pointers (BaseType::get_parent())
Part
Names the parts of multi-section constructor data types.
void set_unsent_data(bool usd)
Set the unsent data property.
std::vector< BaseType * > d_vars
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 * >::iterator Vars_iter
virtual bool is_dap2_only_type()
virtual BaseType * get_parent()
vector< BaseTypeRow * > SequenceValues
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
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 void put_opaque(char *val, unsigned int len)=0
virtual void add_var_nocopy(BaseType *bt, Part part=nil)
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 void add_var(BaseType *bt, Part part=nil)
Type type() const
Returns the type of the class instance.
virtual string toString()
virtual void set_in_selection(bool state)
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_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 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 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.
virtual void dump(ostream &strm) const
dumps information about this object
virtual unsigned int val2buf(void *, bool)
Loads class data.
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()
BaseType * m_leaf_match(const string &name, btp_stack *s=0)
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.
virtual unsigned int width(bool constrained=false)
Evaluate a constraint expression.
virtual SequenceValues value()
virtual int number_of_rows()
void reset_row_number()
Rest the row number counter.
virtual unsigned int buf2val(void **)
Reads the class data.
virtual void intern_data_parent_part_two(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
static ostream & LMarg(ostream &strm)
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)
virtual void intern_data_parent_part_one(DDS &dds, ConstraintEvaluator &eval, sequence_values_stack_t &sequence_values_stack)
BaseType * m_exact_match(const string &name, btp_stack *s=0)
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
void m_duplicate(const Sequence &s)
A class for error processing.
virtual int get_ending_row_number()
Get the ending row number.
virtual void set_send_p(bool state)
virtual BaseType * ptr_duplicate()
virtual int get_row_stride()
Get the row stride.
int get_protocol_major() const
virtual void set_value(SequenceValues &values)
virtual void set_read_p(bool state)
Sets the value of the read_p property.
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.