33#include "D4Sequence.h"
35#include "D4StreamMarshaller.h"
36#include "D4StreamUnMarshaller.h"
38#include "D4FilterClause.h"
43#include "InternalErr.h"
48#undef CLEAR_LOCAL_DATA
62void D4Sequence::m_duplicate(
const D4Sequence &s) {
63 d_length = s.d_length;
65 d_starting_row_number = s.d_starting_row_number;
66 d_ending_row_number = s.d_ending_row_number;
67 d_row_stride = s.d_row_stride;
70 for (D4SeqValues::const_iterator i = s.d_values.begin(), e = s.d_values.end(); i != e; ++i) {
73 for (D4SeqRow::const_iterator j = row.begin(), e = row.end(); j != e; ++j) {
75 dest->push_back((*j)->ptr_duplicate());
78 d_values.push_back(dest);
81 d_copy_clauses = s.d_copy_clauses;
95D4Sequence::D4Sequence(
const string &n)
96 :
Constructor(n, dods_sequence_c, true ), d_clauses(0), d_copy_clauses(true), d_length(0) {}
108D4Sequence::D4Sequence(
const string &n,
const string &d)
109 : Constructor(n, d, dods_sequence_c, true ), d_clauses(0), d_copy_clauses(true), d_length(0) {}
112D4Sequence::D4Sequence(
const D4Sequence &rhs) : Constructor(rhs) { m_duplicate(rhs); }
114BaseType *D4Sequence::ptr_duplicate() {
return new D4Sequence(*
this); }
116static inline void delete_bt(
BaseType *bt_ptr) {
delete bt_ptr; }
118static inline void delete_rows(D4SeqRow *bt_row_ptr) {
119 for_each(bt_row_ptr->begin(), bt_row_ptr->end(), delete_bt);
124D4Sequence::~D4Sequence() {
129void D4Sequence::clear_local_data() {
130 if (!d_values.empty()) {
131 for_each(d_values.begin(), d_values.end(), delete_rows);
138D4Sequence &D4Sequence::operator=(
const D4Sequence &rhs) {
141 Constructor::operator=(rhs);
169bool D4Sequence::read_next_instance(
bool filter) {
179 else if (filter && d_clauses && d_clauses->value()) {
184 else if (!filter || !d_clauses) {
192 }
while (!eof && !done);
197void D4Sequence::intern_data() { read_sequence_values(
true); }
220void D4Sequence::read_sequence_values(
bool filter) {
221 DBG(cerr << __PRETTY_FUNCTION__ <<
" BEGIN" << endl);
229 DBG(cerr <<
"read_sequence_values() - Adding row" << endl);
231 for (Vars_iter i = d_vars.begin(), e = d_vars.end(); i != e; i++) {
232 if ((*i)->send_p()) {
233 DBG(cerr <<
":serialize() - reading data for " << (*i)->type_name() <<
" " << (*i)->name() << endl);
234 if ((*i)->type() == dods_sequence_c) {
235 DBG(cerr <<
"Reading child sequence values for " << (*i)->name() << endl);
236 D4Sequence *d4s =
static_cast<D4Sequence *
>(*i);
237 d4s->read_sequence_values(filter);
238 d4s->d_copy_clauses =
false;
239 row->push_back(d4s->ptr_duplicate());
240 d4s->d_copy_clauses =
true;
241 row->back()->set_read_p(
true);
244 row->push_back((*i)->ptr_duplicate());
248 row->back()->set_read_p(
true);
254 d_values.push_back(row);
255 DBG(cerr <<
" read_sequence_values() - Row completed" << endl);
260 DBGN(cerr << __PRETTY_FUNCTION__ <<
" END added " << d_values.size() << endl);
282void D4Sequence::serialize(D4StreamMarshaller &m, DMR &dmr,
bool filter) {
283 DBGN(cerr << __PRETTY_FUNCTION__ <<
" BEGIN" << endl);
287 read_sequence_values(filter);
290 m.put_count(d_length);
294 for (D4SeqValues::iterator i = d_values.begin(), e = d_values.end(); i != e; ++i) {
295 for (D4SeqRow::iterator j = (*i)->begin(), f = (*i)->end(); j != f; ++j) {
296 (*j)->serialize(m, dmr,
false);
300 DBGN(cerr << __PRETTY_FUNCTION__ <<
" END" << endl);
303void D4Sequence::deserialize(D4StreamUnMarshaller &um, DMR &dmr) {
304 int64_t um_count = um.get_count();
308 for (int64_t i = 0; i < d_length; ++i) {
310 for (Vars_iter i = d_vars.begin(), e = d_vars.end(); i != e; ++i) {
311 (*i)->deserialize(um, dmr);
312 row->push_back((*i)->ptr_duplicate());
314 d_values.push_back(row);
343virtual void set_row_number_constraint(
int start,
int stop,
int stride) {
345 throw Error(malformed_expr,
"Starting row number must precede the ending row number.");
347 d_starting_row_number = start;
348 d_row_stride = stride;
349 d_ending_row_number = stop;
358 if (row >= d_values.size())
360 return d_values[row];
368BaseType *D4Sequence::var_value(
size_t row_num,
const string &name) {
373 auto elem = find_if(row->begin(), row->end(), [name](
const BaseType *btp) { return btp->name() == name; });
375 return (elem != row->end()) ? *elem :
nullptr;
383BaseType *D4Sequence::var_value(
size_t row_num,
size_t i) {
388 if (i >= row->size())
394void D4Sequence::print_one_row(ostream &out,
int row,
string space,
bool print_row_num) {
396 out <<
"\n" << space << row <<
": ";
400 int elements = element_count();
411 while (j < elements && !bt_ptr) {
412 bt_ptr = var_value(row, j++);
414 if (bt_ptr->type() == dods_sequence_c)
415 static_cast<D4Sequence *
>(bt_ptr)->print_val_by_rows(out, space +
" ",
false, print_row_num);
417 bt_ptr->print_val(out, space,
false);
422 while (j < elements) {
426 if (bt_ptr->type() == dods_sequence_c)
427 static_cast<D4Sequence *
>(bt_ptr)->print_val_by_rows(out, space +
" ",
false, print_row_num);
429 bt_ptr->print_val(out, space,
false);
436void D4Sequence::print_val_by_rows(ostream &out,
string space,
bool print_decl_p,
bool print_row_numbers) {
438 print_decl(out, space,
false);
446 for (
int i = 0; i < rows; ++i) {
447 print_one_row(out, i, space, print_row_numbers);
450 print_one_row(out, rows, space, print_row_numbers);
459void D4Sequence::print_val(ostream &out,
string space,
bool print_decl_p) {
460 DBG(cerr << name() <<
" isa " <<
type_name() << endl);
462 print_val_by_rows(out, space, print_decl_p,
false);
473void D4Sequence::dump(ostream &strm)
const {
474 strm << DapIndent::LMarg <<
"Sequence::dump - (" << (
void *)
this <<
")" << endl;
476 Constructor::dump(strm);
477 strm << DapIndent::LMarg <<
"# rows deserialized: " << d_length << endl;
478 strm << DapIndent::LMarg <<
"bracket notation information:" << endl;
482 strm << DapIndent::LMarg <<
"starting row #: " << d_starting_row_number << endl;
483 strm << DapIndent::LMarg <<
"row stride: " << d_row_stride << endl;
484 strm << DapIndent::LMarg <<
"ending row #: " << d_ending_row_number << endl;
486 DapIndent::UnIndent();
488 DapIndent::UnIndent();
List of DAP4 Filter Clauses.
top level DAP object to house generic methods
virtual void set_length(int64_t)
Set the number of elements for this variable. use -1 to indicate nothing set.
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 bool read_p()
Has this variable been read?
virtual string type_name() const
Returns the type of the class instance as a string.
vector< BaseType * > D4SeqRow
virtual int length() const
How many elements are in this variable? Uses -1 in places.
virtual BaseType * var_value(size_t row, const string &name)
Get the BaseType pointer to the named variable of a given row.
virtual D4SeqRow * row_value(size_t row)
Get a whole row from the sequence.
virtual void clear_local_data()
The basic data type for the DODS DAP types. */.