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();
680 DBG2(cerr <<
"Entering Sequence::read_row for " <<
name() << endl);
681 if (row < d_row_number)
throw InternalErr(
"Trying to back up inside a sequence!");
683 DBG2(cerr <<
"read_row: row number " << row <<
", current row " << d_row_number << endl);
684 if (row == d_row_number) {
685 DBG2(cerr <<
"Leaving Sequence::read_row for " <<
name() << endl);
692 while (!eof && d_row_number < row) {
715 DBG2(cerr <<
"Leaving Sequence::read_row for " <<
name() <<
" with eof: " << eof << endl);
727 Sequence::is_end_of_rows(
int i)
729 return ((d_ending_row_number == -1) ?
false : (i > d_ending_row_number));
796 DBG2(cerr <<
"Entering Sequence::serialize for " <<
name() << endl);
813 DBG2(cerr <<
"Entering serialize_parent_part_one for " <<
name() << endl);
815 int i = (d_starting_row_number != -1) ? d_starting_row_number : 0;
821 bool status =
read_row(i, dds, eval,
false);
822 DBG2(cerr <<
"Sequence::serialize_parent_part_one::read_row() status: " << status << endl);
824 while (status && !is_end_of_rows(i)) {
842 (*iter)->serialize(eval, dds, m);
847 status =
read_row(i, dds, eval,
false);
848 DBG(cerr <<
"Sequence::serialize_parent_part_one::read_row() status: " << status << endl);
856 if (d_top_most || d_wrote_soi) {
857 DBG(cerr <<
"Writing End of Sequence marker" << endl);
858 write_end_of_sequence(m);
879 DBG(cerr <<
"Entering serialize_parent_part_two for " <<
name() << endl);
883 static_cast<Sequence&>(*btp).serialize_parent_part_two(dds, eval, m);
886 DBG(cerr <<
"Writing Start of Instance marker" << endl);
888 write_start_of_instance(m);
893 DBG(cerr <<
"Sequence::serialize_parent_part_two(), serializing "
894 << (*iter)->name() << endl);
896 DBG(cerr <<
"Send P is true, sending " << (*iter)->name() << endl);
897 (*iter)->serialize(eval, dds, m,
false);
901 d_unsent_data =
false;
911 DBG(cerr <<
"Entering Sequence::serialize_leaf for " <<
name() << endl);
912 int i = (d_starting_row_number != -1) ? d_starting_row_number : 0;
916 bool status =
read_row(i, dds, eval, ce_eval);
917 DBG(cerr <<
"Sequence::serialize_leaf::read_row() status: " << status << endl);
931 if (status && !is_end_of_rows(i)) {
934 static_cast<Sequence&>(*btp).serialize_parent_part_two(dds,
939 while (status && !is_end_of_rows(i)) {
942 DBG(cerr <<
"Writing Start of Instance marker" << endl);
944 write_start_of_instance(m);
948 DBG(cerr <<
"Sequence::serialize_leaf(), serializing "
949 << (*iter)->name() << endl);
950 if ((*iter)->send_p()) {
951 DBG(cerr <<
"Send P is true, sending " << (*iter)->name() << endl);
952 (*iter)->serialize(eval, dds, m,
false);
958 status =
read_row(i, dds, eval, ce_eval);
959 DBG(cerr <<
"Sequence::serialize_leaf::read_row() status: " << status << endl);
964 if (d_wrote_soi || d_top_most) {
965 DBG(cerr <<
"Writing End of Sequence marker" << endl);
966 write_end_of_sequence(m);
997 DBG(cerr <<
"Sequence::intern_data - for " <<
name() << endl);
998 DBG2(cerr <<
" intern_data, values: " << &d_values << endl);
1005 DBG2(cerr <<
" pushing d_values of " <<
name() <<
" (" << &d_values
1006 <<
") on stack; size: " << sequence_values_stack.size() << endl);
1007 sequence_values_stack.push(&d_values);
1017 DBG(cerr <<
"Entering intern_data_private for " <<
name() << endl);
1029 sequence_values_stack)
1031 DBG(cerr <<
"Entering intern_data_parent_part_one for " <<
name() << endl);
1039 bool status =
read_row(i, dds, eval,
false);
1047 SequenceValues::size_type orig_stack_size = sequence_values_stack.size() ;
1055 if ((*iter)->send_p()) {
1056 switch ((*iter)->type()) {
1059 eval, dds, sequence_values_stack);
1063 (*iter)->intern_data(eval, dds);
1071 status =
read_row(i, dds, eval,
false);
1081 if( sequence_values_stack.size() > orig_stack_size )
1083 DBG2(cerr <<
" popping d_values (" << sequence_values_stack.top()
1084 <<
") off stack; size: " << sequence_values_stack.size() << endl);
1085 sequence_values_stack.pop();
1087 DBG(cerr <<
"Leaving intern_data_parent_part_one for " <<
name() << endl);
1095 DBG(cerr <<
"Entering intern_data_parent_part_two for " <<
name() << endl);
1100 dds, eval, sequence_values_stack);
1103 DBG2(cerr <<
" stack size: " << sequence_values_stack.size() << endl);
1105 DBG2(cerr <<
" using values = " << (
void *)values << endl);
1114 row_data->push_back((*iter)->ptr_duplicate());
1116 else if ((*iter)->send_p()) {
1120 throw InternalErr(__FILE__, __LINE__,
"Expected a Sequence.");
1122 row_data->push_back(tmp);
1123 DBG2(cerr <<
" pushing d_values of " << tmp->
name()
1124 <<
" (" << &(tmp->d_values)
1125 <<
") on stack; size: " << sequence_values_stack.size()
1130 sequence_values_stack.push(&(tmp->d_values));
1134 DBG2(cerr <<
" pushing values for " <<
name()
1135 <<
" to " << values << endl);
1136 values->push_back(row_data);
1139 DBG(cerr <<
"Leaving intern_data_parent_part_two for " <<
name() << endl);
1147 DBG(cerr <<
"Entering intern_data_for_leaf for " <<
name() << endl);
1151 DBG2(cerr <<
" reading row " << i << endl);
1152 bool status =
read_row(i, dds, eval,
true);
1153 DBG2(cerr <<
" status: " << status << endl);
1163 dds, eval, sequence_values_stack);
1170 DBG2(cerr <<
" using values = " << values << endl);
1179 if ((*iter)->send_p()) {
1180 row_data->push_back((*iter)->ptr_duplicate());
1184 DBG2(cerr <<
" pushing values for " <<
name()
1185 <<
" to " << values << endl);
1187 values->push_back(row_data);
1191 status =
read_row(i, dds, eval,
true);
1194 DBG2(cerr <<
" popping d_values (" << sequence_values_stack.top()
1195 <<
") off stack; size: " << sequence_values_stack.size() << endl);
1196 sequence_values_stack.pop();
1198 DBG(cerr <<
"Leaving intern_data_for_leaf for " <<
name() << endl);
1226 throw InternalErr(
"Expected argument 'dds' to be a DataDDS!");
1228 DBG2(cerr <<
"Reading from server/protocol version: "
1235 +
") indicates that this\nis an old server which may not correctly transmit Sequence variables.\nContact the server administrator.");
1240 unsigned char marker = read_marker(um);
1241 if (is_end_of_sequence(marker))
1243 else if (is_start_of_instance(marker)) {
1245 DBG2(cerr <<
"Reading row " << d_row_number <<
" of "
1252 DBG2(cerr <<
"Deserialized " << bt_ptr->
name() <<
" ("
1253 << bt_ptr <<
") = ");
1255 bt_row_ptr->push_back(bt_ptr);
1258 d_values.push_back(bt_row_ptr);
1261 throw Error(
"I could not read the expected Sequence data stream marker!");
1283 return d_starting_row_number;
1299 return d_row_stride;
1316 return d_ending_row_number;
1333 d_starting_row_number = start;
1334 d_row_stride = stride;
1335 d_ending_row_number = stop;
1344 throw InternalErr(__FILE__, __LINE__,
"Never use this method; see the programmer's guide documentation.");
1355 throw InternalErr(__FILE__, __LINE__,
"Use Sequence::var_value() or Sequence::row_value() in place of Sequence::buf2val()");
1366 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
1374 out <<
"\n" << space << row <<
": " ;
1388 while (j < elements && !bt_ptr) {
1392 static_cast<Sequence*>(bt_ptr)->print_val_by_rows
1393 (out, space +
" ",
false, print_row_num);
1400 while (j < elements) {
1405 static_cast<Sequence*>(bt_ptr)->print_val_by_rows
1406 (out, space +
" ",
false, print_row_num);
1417 bool print_row_numbers)
1421 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
1426 bool print_row_numbers)
1437 for (i = 0; i < rows; ++i) {
1473 if (!(*i)->check_semantics(msg,
true)) {
1485 d_leaf_sequence = state;
1491 return d_leaf_sequence;
1521 bool has_child_sequence =
false;
1523 if (lvl == 1) d_top_most =
true;
1525 DBG2(cerr <<
"Processing sequence " <<
name() << endl);
1534 if (has_child_sequence)
1535 throw Error(
"This implementation does not support more than one nested sequence at a level. Contact the server administrator.");
1537 has_child_sequence =
true;
1545 if (!has_child_sequence)
1565 << (
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.