44 #include "Structure.h" 45 #include "D4Sequence.h" 47 #include "D4StreamMarshaller.h" 48 #include "D4StreamUnMarshaller.h" 52 #include "InternalErr.h" 56 #undef CLEAR_LOCAL_DATA 65 static const unsigned char end_of_sequence = 0xA5;
66 static const unsigned char start_of_instance = 0x5A;
69 write_end_of_sequence(Marshaller &m)
71 m.put_opaque( (
char *)&end_of_sequence, 1 );
75 write_start_of_instance(Marshaller &m)
77 m.put_opaque( (
char *)&start_of_instance, 1 );
81 read_marker(UnMarshaller &um)
84 um.get_opaque( (
char *)&marker, 1 );
90 is_start_of_instance(
unsigned char marker)
92 return (marker == start_of_instance);
96 is_end_of_sequence(
unsigned char marker)
98 return (marker == end_of_sequence);
110 void D4Sequence::m_duplicate(
const D4Sequence &s)
112 d_length = s.d_length;
114 d_starting_row_number = s.d_starting_row_number;
115 d_ending_row_number = s.d_ending_row_number;
116 d_row_stride = s.d_row_stride;
119 for (D4SeqValues::const_iterator i = s.d_values.begin(), e = s.d_values.end(); i != e; ++i) {
122 for (D4SeqRow::const_iterator j = row.begin(), e = row.end(); j != e; ++j) {
124 dest->push_back((*j)->ptr_duplicate());
127 d_values.push_back(dest);
141 D4Sequence::D4Sequence(
const string &n) :
142 Constructor(n, dods_sequence_c, true ), d_length(0)
157 Constructor(n, d, dods_sequence_c, true ), d_length(0)
174 static inline void delete_bt(
BaseType *bt_ptr)
179 static inline void delete_rows(
D4SeqRow *bt_row_ptr)
181 for_each(bt_row_ptr->begin(), bt_row_ptr->end(), delete_bt);
186 D4Sequence::~D4Sequence()
193 if (!d_values.empty()) {
194 for_each(d_values.begin(), d_values.end(), delete_rows);
204 if (
this == &rhs)
return *
this;
248 if (!eof && (!filter )) {
252 }
while (!eof && !done);
254 DBG(cerr <<
"D4Sequence::read_next_instance eof: " << eof << endl);
274 for (Vars_iter i = d_vars.begin(), e = d_vars.end(); i != e; i++) {
275 if ((*i)->send_p()) {
276 (*i)->compute_checksum(checksum);
288 for (Vars_iter i = d_vars.begin(), e = d_vars.end(); i != e; i++) {
289 if ((*i)->send_p()) {
291 row->push_back((*i)->ptr_duplicate());
295 row->back()->set_read_p(
true);
300 if (!row->back()->is_constructor_type()) row->back()->compute_checksum(checksum);
304 d_values.push_back(row);
332 for (Vars_iter i = d_vars.begin(), e = d_vars.end(); i != e; i++) {
333 if ((*i)->send_p()) {
335 row->push_back((*i)->ptr_duplicate());
339 row->back()->set_read_p(
true);
342 d_values.push_back(row);
343 DBG(cerr <<
"D4Sequence::serialize Added row" << endl);
348 DBG(cerr <<
"D4Sequence::serialize count: " << d_length << endl);
352 for (D4SeqValues::iterator i = d_values.begin(), e = d_values.end(); i != e; ++i) {
353 for (D4SeqRow::iterator j = (*i)->begin(), f = (*i)->end(); j != f; ++j) {
354 (*j)->serialize(m, dmr,
false);
358 #ifdef CLEAR_LOCAL_DATA 370 for (Vars_iter i = d_vars.begin(), e = d_vars.end(); i != e; i++) {
371 if ((*i)->send_p()) {
373 row->push_back((*i)->ptr_duplicate());
377 row->back()->set_read_p(
true);
380 d_values.push_back(row);
381 DBG(cerr <<
"D4Sequence::serialize Added row" << endl);
386 DBG(cerr <<
"D4Sequence::serialize count: " << d_length << endl);
390 for (D4SeqValues::iterator i = d_values.begin(), e = d_values.end(); i != e; ++i) {
391 for (D4SeqRow::iterator j = (*i)->begin(), f = (*i)->end(); j != f; ++j) {
392 (*j)->serialize(m, dmr,
false);
401 DBG(cerr <<
"D4Sequence::deserialize count: " << d_length << endl);
403 for (int64_t i = 0; i < d_length; ++i) {
405 for (Vars_iter i = d_vars.begin(), e = d_vars.end(); i != e; ++i) {
406 (*i)->deserialize(um, dmr);
407 row->push_back((*i)->ptr_duplicate());
409 d_values.push_back(row);
422 virtual void set_row_number_constraint(
int start,
int stop,
int stride)
425 throw Error(malformed_expr,
"Starting row number must precede the ending row number.");
427 d_starting_row_number = start;
428 d_row_stride = stride;
429 d_ending_row_number = stop;
440 if (row >= d_values.size())
return 0;
441 return d_values[row];
444 static bool base_type_name_eq(
BaseType *btp,
const string name)
460 D4SeqRow::iterator elem = find_if(row->begin(), row->end(), bind2nd(ptr_fun(base_type_name_eq), name));
461 return (elem != row->end()) ? *elem : 0;
475 if (i >= row->size())
return 0;
480 void D4Sequence::print_one_row(ostream &out,
int row,
string space,
bool print_row_num)
482 if (print_row_num) out <<
"\n" << space << row <<
": ";
497 while (j < elements && !bt_ptr) {
500 if (bt_ptr->
type() == dods_sequence_c) static_cast<D4Sequence*>(bt_ptr)->print_val_by_rows(out,
501 space +
" ",
false, print_row_num);
508 while (j < elements) {
512 if (bt_ptr->
type() == dods_sequence_c) static_cast<D4Sequence*>(bt_ptr)->print_val_by_rows(out,
513 space +
" ",
false, print_row_num);
522 void D4Sequence::print_val_by_rows(ostream &out,
string space,
bool print_decl_p,
bool print_row_numbers)
533 for (
int i = 0; i < rows; ++i) {
534 print_one_row(out, i, space, print_row_numbers);
537 print_one_row(out, rows, space, print_row_numbers);
542 if (print_decl_p) out <<
";\n";
547 print_val_by_rows(out, space, print_decl_p,
false);
560 strm << DapIndent::LMarg <<
"Sequence::dump - (" << (
void *)
this <<
")" << endl;
563 strm << DapIndent::LMarg <<
"# rows deserialized: " << d_length << endl;
564 strm << DapIndent::LMarg <<
"bracket notation information:" << endl;
568 strm << DapIndent::LMarg <<
"starting row #: " << d_starting_row_number << endl;
569 strm << DapIndent::LMarg <<
"row stride: " << d_row_stride << endl;
570 strm << DapIndent::LMarg <<
"ending row #: " << d_ending_row_number << endl;
572 DapIndent::UnIndent();
574 DapIndent::UnIndent();
virtual BaseType * ptr_duplicate()
virtual void put_count(int64_t count)
D4Sequence(const string &n)
The Sequence constructor.
virtual bool read_next_instance(bool filter)
Read the next instance of the sequence While the rest of the variables' read() methods are assumed to...
Read data from the stream made by D4StreamMarshaller.
virtual void compute_checksum(Crc32 &checksum)
include the data for this variable in the checksum DAP4 includes a checksum with every data response...
virtual void clear_local_data()
virtual BaseType * var_value(size_t row, const string &name)
Get the BaseType pointer to the named variable of a given row.
virtual Type type() const
Returns the type of the class instance.
vector< BaseType * > D4SeqRow
virtual int element_count(bool leaves=false)
Count the members of constructor types.
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
virtual void set_length(int count)
virtual void dump(ostream &strm) const
dumps information about this object
virtual int length() const
The number of elements in a Sequence object.
virtual bool read()
simple implementation of read that iterates through vars and calls read on them
virtual void intern_data()
Read data into this variable.
virtual void dump(ostream &strm) const
dumps information about this object
virtual string name() const
Returns the name of the class instance.
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Evaluate a constraint expression.
virtual bool deserialize(UnMarshaller &, DDS *, bool)
Receive data from the net.
The basic data type for the DODS DAP types.
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 D4SeqRow * row_value(size_t row)
Get a whole row from the sequence.
A class for error processing.
virtual bool serialize(ConstraintEvaluator &, DDS &, Marshaller &, bool)
Move data to the net, then remove them from the object.
virtual void set_read_p(bool state)
Sets the value of the read_p property.