33 #include "D4Sequence.h"
35 #include "D4StreamMarshaller.h"
36 #include "D4StreamUnMarshaller.h"
39 #include "D4FilterClause.h"
43 #include "InternalErr.h"
46 #include "DapIndent.h"
48 #undef CLEAR_LOCAL_DATA
57 static const unsigned char end_of_sequence = 0xA5;
58 static const unsigned char start_of_instance = 0x5A;
61 write_end_of_sequence(Marshaller &m)
63 m.put_opaque( (
char *)&end_of_sequence, 1 );
67 write_start_of_instance(Marshaller &m)
69 m.put_opaque( (
char *)&start_of_instance, 1 );
73 read_marker(UnMarshaller &um)
76 um.get_opaque( (
char *)&marker, 1 );
82 is_start_of_instance(
unsigned char marker)
84 return (marker == start_of_instance);
88 is_end_of_sequence(
unsigned char marker)
90 return (marker == end_of_sequence);
102 void D4Sequence::m_duplicate(
const D4Sequence &s)
104 d_length = s.d_length;
106 d_starting_row_number = s.d_starting_row_number;
107 d_ending_row_number = s.d_ending_row_number;
108 d_row_stride = s.d_row_stride;
111 for (D4SeqValues::const_iterator i = s.d_values.begin(), e = s.d_values.end(); i != e; ++i) {
114 for (D4SeqRow::const_iterator j = row.begin(), e = row.end(); j != e; ++j) {
116 dest->push_back((*j)->ptr_duplicate());
119 d_values.push_back(dest);
122 d_copy_clauses = s.d_copy_clauses;
123 d_clauses = (s.d_clauses != 0) ?
new D4FilterClauseList(*s.d_clauses) : 0;
136 D4Sequence::D4Sequence(
const string &n) :
137 Constructor(n, dods_sequence_c, true ), d_clauses(0), d_copy_clauses(true), d_length(0)
152 Constructor(n, d, dods_sequence_c, true ), d_clauses(0), d_copy_clauses(true), d_length(0)
168 static inline void delete_bt(
BaseType *bt_ptr)
173 static inline void delete_rows(
D4SeqRow *bt_row_ptr)
175 for_each(bt_row_ptr->begin(), bt_row_ptr->end(), delete_bt);
180 D4Sequence::~D4Sequence()
188 if (!d_values.empty()) {
189 for_each(d_values.begin(), d_values.end(), delete_rows);
199 if (
this == &rhs)
return *
this;
242 else if (filter && d_clauses && d_clauses->
value()) {
247 else if (!filter || !d_clauses) {
255 }
while (!eof && !done);
268 for (Vars_iter i = d_vars.begin(), e = d_vars.end(); i != e; i++) {
269 if ((*i)->send_p()) {
271 row->push_back((*i)->ptr_duplicate());
275 row->back()->set_read_p(
true);
278 d_values.push_back(row);
308 DBG(cerr << __PRETTY_FUNCTION__ <<
" BEGIN" << endl);
315 DBG(cerr <<
"read_sequence_values() - Adding row" << endl);
317 for (Vars_iter i = d_vars.begin(), e = d_vars.end(); i != e; i++) {
318 if ((*i)->send_p()) {
319 DBG(cerr <<
":serialize() - reading data for " << (*i)->type_name() <<
" " << (*i)->name() << endl);
320 if ((*i)->type() == dods_sequence_c) {
321 DBG(cerr <<
"Reading child sequence values for " << (*i)->name() << endl);
324 d4s->d_copy_clauses =
false;
326 d4s->d_copy_clauses =
true;
327 row->back()->set_read_p(
true);
331 row->push_back((*i)->ptr_duplicate());
335 row->back()->set_read_p(
true);
341 d_values.push_back(row);
342 DBG(cerr <<
" read_sequence_values() - Row completed" << endl);
347 DBGN(cerr << __PRETTY_FUNCTION__ <<
" END added " << d_values.size() << endl);
371 DBGN(cerr << __PRETTY_FUNCTION__ <<
" BEGIN" << endl);
382 for (D4SeqValues::iterator i = d_values.begin(), e = d_values.end(); i != e; ++i) {
383 for (D4SeqRow::iterator j = (*i)->begin(), f = (*i)->end(); j != f; ++j) {
384 (*j)->serialize(m, dmr,
false);
388 DBGN(cerr << __PRETTY_FUNCTION__ <<
" END" << endl);
397 for (int64_t i = 0; i < d_length; ++i) {
399 for (Vars_iter i = d_vars.begin(), e = d_vars.end(); i != e; ++i) {
400 (*i)->deserialize(um, dmr);
401 row->push_back((*i)->ptr_duplicate());
403 d_values.push_back(row);
433 virtual void set_row_number_constraint(
int start,
int stop,
int stride)
436 throw Error(malformed_expr,
"Starting row number must precede the ending row number.");
438 d_starting_row_number = start;
439 d_row_stride = stride;
440 d_ending_row_number = stop;
451 if (row >= d_values.size())
return 0;
452 return d_values[row];
455 static bool base_type_name_eq(
BaseType *btp,
const string name)
457 return btp->
name() == name;
471 D4SeqRow::iterator elem = find_if(row->begin(), row->end(), bind2nd(ptr_fun(base_type_name_eq),
name));
472 return (elem != row->end()) ? *elem : 0;
486 if (i >= row->size())
return 0;
491 void D4Sequence::print_one_row(ostream &out,
int row,
string space,
bool print_row_num)
493 if (print_row_num) out <<
"\n" << space << row <<
": ";
508 while (j < elements && !bt_ptr) {
511 if (bt_ptr->
type() == dods_sequence_c)
static_cast<D4Sequence*
>(bt_ptr)->print_val_by_rows(out,
512 space +
" ",
false, print_row_num);
519 while (j < elements) {
523 if (bt_ptr->
type() == dods_sequence_c)
static_cast<D4Sequence*
>(bt_ptr)->print_val_by_rows(out,
524 space +
" ",
false, print_row_num);
533 void D4Sequence::print_val_by_rows(ostream &out,
string space,
bool print_decl_p,
bool print_row_numbers)
544 for (
int i = 0; i < rows; ++i) {
545 print_one_row(out, i, space, print_row_numbers);
548 print_one_row(out, rows, space, print_row_numbers);
553 if (print_decl_p) out <<
";\n";
560 print_val_by_rows(out, space, print_decl_p,
false);
573 strm << DapIndent::LMarg <<
"Sequence::dump - (" << (
void *)
this <<
")" << endl;
576 strm << DapIndent::LMarg <<
"# rows deserialized: " << d_length << endl;
577 strm << DapIndent::LMarg <<
"bracket notation information:" << endl;
581 strm << DapIndent::LMarg <<
"starting row #: " << d_starting_row_number << endl;
582 strm << DapIndent::LMarg <<
"row stride: " << d_row_stride << endl;
583 strm << DapIndent::LMarg <<
"ending row #: " << d_ending_row_number << endl;
585 DapIndent::UnIndent();
587 DapIndent::UnIndent();
The basic data type for the DODS DAP types.
virtual string type_name() const
Returns the type of the class instance as a string.
virtual string name() const
Returns the name of the class instance.
virtual bool read_p()
Has this variable been read?
virtual Type type() const
Returns the type of the class instance.
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.
virtual int element_count(bool leaves=false)
Count the members of constructor types.
virtual void dump(ostream &strm) const
dumps information about this object
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 bool read()
simple implementation of read that iterates through vars and calls read on them
virtual void set_read_p(bool state)
Sets the value of the read_p property.
List of DAP4 Filter Clauses.
bool value(DMR &dmr)
Evaluate the list of clauses.
virtual D4SeqRow * row_value(size_t row)
Get a whole row from the sequence.
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...
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
D4Sequence(const string &n)
The Sequence constructor.
virtual bool serialize(ConstraintEvaluator &, DDS &, Marshaller &, bool)
Move data to the net, then remove them from the object.
D4FilterClauseList & clauses()
Access the filter clauses for this D4Sequence.
virtual void intern_data()
Read data into this variable.
virtual BaseType * ptr_duplicate()
virtual bool deserialize(UnMarshaller &, DDS *, bool)
Receive data from the net.
void read_sequence_values(bool filter)
Read a Sequence's value into memory.
virtual void set_length(int count)
virtual BaseType * var_value(size_t row, const string &name)
Get the BaseType pointer to the named variable of a given row.
virtual void dump(ostream &strm) const
dumps information about this object
virtual void clear_local_data()
virtual int length() const
The number of elements in a Sequence object.
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
virtual void put_count(int64_t count)
Read data from the stream made by D4StreamMarshaller.
A class for error processing.
top level DAP object to house generic methods
vector< BaseType * > D4SeqRow