33 #include "D4Sequence.h" 35 #include "D4StreamMarshaller.h" 36 #include "D4StreamUnMarshaller.h" 39 #include "D4FilterClause.h" 43 #include "InternalErr.h" 47 #undef CLEAR_LOCAL_DATA 56 static const unsigned char end_of_sequence = 0xA5;
57 static const unsigned char start_of_instance = 0x5A;
60 write_end_of_sequence(Marshaller &m)
62 m.put_opaque( (
char *)&end_of_sequence, 1 );
66 write_start_of_instance(Marshaller &m)
68 m.put_opaque( (
char *)&start_of_instance, 1 );
72 read_marker(UnMarshaller &um)
75 um.get_opaque( (
char *)&marker, 1 );
81 is_start_of_instance(
unsigned char marker)
83 return (marker == start_of_instance);
87 is_end_of_sequence(
unsigned char marker)
89 return (marker == end_of_sequence);
101 void D4Sequence::m_duplicate(
const D4Sequence &s)
103 d_length = s.d_length;
105 d_starting_row_number = s.d_starting_row_number;
106 d_ending_row_number = s.d_ending_row_number;
107 d_row_stride = s.d_row_stride;
110 for (D4SeqValues::const_iterator i = s.d_values.begin(), e = s.d_values.end(); i != e; ++i) {
113 for (D4SeqRow::const_iterator j = row.begin(), e = row.end(); j != e; ++j) {
115 dest->push_back((*j)->ptr_duplicate());
118 d_values.push_back(dest);
121 d_copy_clauses = s.d_copy_clauses;
122 d_clauses = (s.d_clauses != 0) ?
new D4FilterClauseList(*s.d_clauses) : 0;
135 D4Sequence::D4Sequence(
const string &n) :
136 Constructor(n, dods_sequence_c, true ), d_clauses(0), d_copy_clauses(true), d_length(0)
151 Constructor(n, d, dods_sequence_c, true ), d_clauses(0), d_copy_clauses(true), d_length(0)
167 static inline void delete_bt(
BaseType *bt_ptr)
172 static inline void delete_rows(
D4SeqRow *bt_row_ptr)
174 for_each(bt_row_ptr->begin(), bt_row_ptr->end(), delete_bt);
179 D4Sequence::~D4Sequence()
187 if (!d_values.empty()) {
188 for_each(d_values.begin(), d_values.end(), delete_rows);
198 if (
this == &rhs)
return *
this;
241 else if (filter && d_clauses && d_clauses->
value()) {
246 else if (!filter || !d_clauses) {
254 }
while (!eof && !done);
267 for (Vars_iter i = d_vars.begin(), e = d_vars.end(); i != e; i++) {
268 if ((*i)->send_p()) {
270 row->push_back((*i)->ptr_duplicate());
274 row->back()->set_read_p(
true);
277 d_values.push_back(row);
307 DBG(cerr << __PRETTY_FUNCTION__ <<
" BEGIN" << endl);
314 DBG(cerr <<
"read_sequence_values() - Adding row" << endl);
316 for (Vars_iter i = d_vars.begin(), e = d_vars.end(); i != e; i++) {
317 if ((*i)->send_p()) {
318 DBG(cerr <<
":serialize() - reading data for " << (*i)->type_name() <<
" " << (*i)->name() << endl);
319 if ((*i)->type() == dods_sequence_c) {
320 DBG(cerr <<
"Reading child sequence values for " << (*i)->name() << endl);
323 d4s->d_copy_clauses =
false;
324 row->push_back(d4s->ptr_duplicate());
325 d4s->d_copy_clauses =
true;
326 row->back()->set_read_p(
true);
330 row->push_back((*i)->ptr_duplicate());
334 row->back()->set_read_p(
true);
340 d_values.push_back(row);
341 DBG(cerr <<
" read_sequence_values() - Row completed" << endl);
346 DBGN(cerr << __PRETTY_FUNCTION__ <<
" END added " << d_values.size() << endl);
370 DBGN(cerr << __PRETTY_FUNCTION__ <<
" BEGIN" << endl);
381 for (D4SeqValues::iterator i = d_values.begin(), e = d_values.end(); i != e; ++i) {
382 for (D4SeqRow::iterator j = (*i)->begin(), f = (*i)->end(); j != f; ++j) {
383 (*j)->serialize(m, dmr,
false);
387 DBGN(cerr << __PRETTY_FUNCTION__ <<
" END" << endl);
396 for (int64_t i = 0; i < d_length; ++i) {
398 for (Vars_iter i = d_vars.begin(), e = d_vars.end(); i != e; ++i) {
399 (*i)->deserialize(um, dmr);
400 row->push_back((*i)->ptr_duplicate());
402 d_values.push_back(row);
432 virtual void set_row_number_constraint(
int start,
int stop,
int stride)
435 throw Error(malformed_expr,
"Starting row number must precede the ending row number.");
437 d_starting_row_number = start;
438 d_row_stride = stride;
439 d_ending_row_number = stop;
450 if (row >= d_values.size())
return 0;
451 return d_values[row];
454 static bool base_type_name_eq(
BaseType *btp,
const string name)
456 return btp->
name() == name;
470 D4SeqRow::iterator elem = find_if(row->begin(), row->end(), bind2nd(ptr_fun(base_type_name_eq),
name));
471 return (elem != row->end()) ? *elem : 0;
485 if (i >= row->size())
return 0;
490 void D4Sequence::print_one_row(ostream &out,
int row,
string space,
bool print_row_num)
492 if (print_row_num) out <<
"\n" << space << row <<
": ";
507 while (j < elements && !bt_ptr) {
510 if (bt_ptr->
type() == dods_sequence_c) static_cast<D4Sequence*>(bt_ptr)->print_val_by_rows(out,
511 space +
" ",
false, print_row_num);
518 while (j < elements) {
522 if (bt_ptr->
type() == dods_sequence_c) static_cast<D4Sequence*>(bt_ptr)->print_val_by_rows(out,
523 space +
" ",
false, print_row_num);
532 void D4Sequence::print_val_by_rows(ostream &out,
string space,
bool print_decl_p,
bool print_row_numbers)
543 for (
int i = 0; i < rows; ++i) {
544 print_one_row(out, i, space, print_row_numbers);
547 print_one_row(out, rows, space, print_row_numbers);
552 if (print_decl_p) out <<
";\n";
559 print_val_by_rows(out, space, print_decl_p,
false);
572 strm << DapIndent::LMarg <<
"Sequence::dump - (" << (
void *)
this <<
")" << endl;
575 strm << DapIndent::LMarg <<
"# rows deserialized: " << d_length << endl;
576 strm << DapIndent::LMarg <<
"bracket notation information:" << endl;
580 strm << DapIndent::LMarg <<
"starting row #: " << d_starting_row_number << endl;
581 strm << DapIndent::LMarg <<
"row stride: " << d_row_stride << endl;
582 strm << DapIndent::LMarg <<
"ending row #: " << d_ending_row_number << endl;
584 DapIndent::UnIndent();
586 DapIndent::UnIndent();
virtual bool read_p()
Has this variable been read?
virtual string name() const
Returns the name of the class instance.
virtual BaseType * ptr_duplicate()
bool value(DMR &dmr)
Evaluate the list of clauses.
void read_sequence_values(bool filter)
Read a Sequence's value into memory.
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 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.
D4FilterClauseList & clauses()
Access the filter clauses for this D4Sequence.
vector< BaseType * > D4SeqRow
virtual int element_count(bool leaves=false)
Count the members of constructor types.
List of DAP4 Filter Clauses.
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 dump(ostream &strm) const
dumps information about this object
virtual Type type() const
Returns the type of the class instance.
virtual void set_length(int count)
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 int length() const
The number of elements in a Sequence object.
virtual void dump(ostream &strm) const
dumps information about this object
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
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 string type_name() const
Returns the type of the class instance as a string.
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.