33#include "D4Sequence.h"
35#include "D4StreamMarshaller.h"
36#include "D4StreamUnMarshaller.h"
39#include "D4FilterClause.h"
43#include "InternalErr.h"
48#undef CLEAR_LOCAL_DATA
62void D4Sequence::m_duplicate(
const D4Sequence &s)
64 d_length = s.d_length;
66 d_starting_row_number = s.d_starting_row_number;
67 d_ending_row_number = s.d_ending_row_number;
68 d_row_stride = s.d_row_stride;
71 for (D4SeqValues::const_iterator i = s.d_values.begin(), e = s.d_values.end(); i != e; ++i) {
74 for (D4SeqRow::const_iterator j = row.begin(), e = row.end(); j != e; ++j) {
76 dest->push_back((*j)->ptr_duplicate());
79 d_values.push_back(dest);
82 d_copy_clauses = s.d_copy_clauses;
83 d_clauses = (s.d_clauses != 0) ?
new D4FilterClauseList(*s.d_clauses) : 0;
97 Constructor(n, dods_sequence_c, true ), d_clauses(0), d_copy_clauses(true), d_length(0)
112 Constructor(n, d, dods_sequence_c, true ), d_clauses(0), d_copy_clauses(true), d_length(0)
128static inline void delete_bt(
BaseType *bt_ptr)
133static inline void delete_rows(
D4SeqRow *bt_row_ptr)
135 for_each(bt_row_ptr->begin(), bt_row_ptr->end(), delete_bt);
140D4Sequence::~D4Sequence()
148 if (!d_values.empty()) {
149 for_each(d_values.begin(), d_values.end(), delete_rows);
159 if (
this == &rhs)
return *
this;
160 Constructor::operator=(rhs);
199 else if (filter && d_clauses && d_clauses->
value()) {
204 else if (!filter || !d_clauses) {
212 }
while (!eof && !done);
245 DBG(cerr << __PRETTY_FUNCTION__ <<
" BEGIN" << endl);
252 DBG(cerr <<
"read_sequence_values() - Adding row" << endl);
254 for (Vars_iter i = d_vars.begin(), e = d_vars.end(); i != e; i++) {
255 if ((*i)->send_p()) {
256 DBG(cerr <<
":serialize() - reading data for " << (*i)->type_name() <<
" " << (*i)->name() << endl);
257 if ((*i)->type() == dods_sequence_c) {
258 DBG(cerr <<
"Reading child sequence values for " << (*i)->name() << endl);
261 d4s->d_copy_clauses =
false;
262 row->push_back(d4s->ptr_duplicate());
263 d4s->d_copy_clauses =
true;
264 row->back()->set_read_p(
true);
268 row->push_back((*i)->ptr_duplicate());
272 row->back()->set_read_p(
true);
278 d_values.push_back(row);
279 DBG(cerr <<
" read_sequence_values() - Row completed" << endl);
284 DBGN(cerr << __PRETTY_FUNCTION__ <<
" END added " << d_values.size() << endl);
308 DBGN(cerr << __PRETTY_FUNCTION__ <<
" BEGIN" << endl);
315 m.put_count(d_length);
319 for (D4SeqValues::iterator i = d_values.begin(), e = d_values.end(); i != e; ++i) {
320 for (D4SeqRow::iterator j = (*i)->begin(), f = (*i)->end(); j != f; ++j) {
321 (*j)->serialize(m, dmr,
false);
325 DBGN(cerr << __PRETTY_FUNCTION__ <<
" END" << endl);
330 int64_t um_count = um.get_count();
334 for (int64_t i = 0; i < d_length; ++i) {
336 for (Vars_iter i = d_vars.begin(), e = d_vars.end(); i != e; ++i) {
337 (*i)->deserialize(um, dmr);
338 row->push_back((*i)->ptr_duplicate());
340 d_values.push_back(row);
370virtual void set_row_number_constraint(
int start,
int stop,
int stride)
373 throw Error(malformed_expr,
"Starting row number must precede the ending row number.");
375 d_starting_row_number = start;
376 d_row_stride = stride;
377 d_ending_row_number = stop;
388 if (row >= d_values.size())
return 0;
389 return d_values[row];
401 if (!row)
return nullptr;
403 auto elem = find_if(row->begin(), row->end(),
404 [
name](
const BaseType *btp) { return btp->name() == name; });
406 return (elem != row->end()) ? *elem :
nullptr;
420 if (i >= row->size())
return 0;
425void D4Sequence::print_one_row(ostream &out,
int row,
string space,
bool print_row_num)
427 if (print_row_num) out <<
"\n" << space << row <<
": ";
442 while (j < elements && !bt_ptr) {
445 if (bt_ptr->type() == dods_sequence_c)
static_cast<D4Sequence*
>(bt_ptr)->print_val_by_rows(out,
446 space +
" ",
false, print_row_num);
448 bt_ptr->print_val(out, space,
false);
453 while (j < elements) {
457 if (bt_ptr->type() == dods_sequence_c)
static_cast<D4Sequence*
>(bt_ptr)->print_val_by_rows(out,
458 space +
" ",
false, print_row_num);
460 bt_ptr->print_val(out, space,
false);
467void D4Sequence::print_val_by_rows(ostream &out,
string space,
bool print_decl_p,
bool print_row_numbers)
478 for (
int i = 0; i < rows; ++i) {
479 print_one_row(out, i, space, print_row_numbers);
482 print_one_row(out, rows, space, print_row_numbers);
487 if (print_decl_p) out <<
";\n";
494 print_val_by_rows(out, space, print_decl_p,
false);
507 strm << DapIndent::LMarg <<
"Sequence::dump - (" << (
void *)
this <<
")" << endl;
510 strm << DapIndent::LMarg <<
"# rows deserialized: " << d_length << endl;
511 strm << DapIndent::LMarg <<
"bracket notation information:" << endl;
515 strm << DapIndent::LMarg <<
"starting row #: " << d_starting_row_number << endl;
516 strm << DapIndent::LMarg <<
"row stride: " << d_row_stride << endl;
517 strm << DapIndent::LMarg <<
"ending row #: " << d_ending_row_number << endl;
519 DapIndent::UnIndent();
521 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?
int element_count(bool leaves=false) override
Count the members of constructor types.
void print_decl(ostream &out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false) override
Print an ASCII representation of the variable structure.
void set_read_p(bool state) override
Set the 'read_p' property for the Constructor and its members.
bool read() override
Read the elements of Constructor marked for transmission.
void dump(ostream &strm) const override
dumps information about this object
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...
Read data from the stream made by D4StreamMarshaller.
A class for error processing.
top level DAP object to house generic methods
vector< BaseType * > D4SeqRow