45 #include <ConstraintEvaluator.h> 46 #include <Marshaller.h> 47 #include <UnMarshaller.h> 50 #include "TabularSequence.h" 53 using namespace libdap;
60 static const unsigned char end_of_sequence = 0xA5;
61 static const unsigned char start_of_instance = 0x5A;
64 write_end_of_sequence(Marshaller &m)
66 m.put_opaque( (
char *)&end_of_sequence, 1 ) ;
70 write_start_of_instance(Marshaller &m)
72 m.put_opaque( (
char *)&start_of_instance, 1 ) ;
75 void TabularSequence::load_prototypes_with_values(BaseTypeRow &btr,
bool safe)
81 Vars_iter i = d_vars.begin(), e = d_vars.end();
82 for (BaseTypeRow::iterator vi = btr.begin(), ve = btr.end(); vi != ve; ++vi) {
84 if (safe && (i == e || ((*i)->type() != (*vi)->var()->type())))
85 throw InternalErr(__FILE__, __LINE__,
"Expected number and types to match when loading values for selection expression evaluation.");
88 switch ((*i)->type()) {
90 static_cast<Byte*>(*i++)->set_value(static_cast<Byte*>(*vi)->value());
93 static_cast<Int16*>(*i++)->set_value(static_cast<Int16*>((*vi))->value());
96 static_cast<Int32*>(*i++)->set_value(static_cast<Int32*>((*vi))->value());
99 static_cast<UInt16*>(*i++)->set_value(static_cast<UInt16*>((*vi))->value());
102 static_cast<UInt32*>(*i++)->set_value(static_cast<UInt32*>((*vi))->value());
105 static_cast<Float32*>(*i++)->set_value(static_cast<Float32*>((*vi))->value());
108 static_cast<Float64*>(*i++)->set_value(static_cast<Float64*>((*vi))->value());
111 static_cast<Str*>(*i++)->set_value(static_cast<Str*>((*vi))->value());
114 static_cast<Url*>(*i++)->set_value(static_cast<Url*>((*vi))->value());
117 throw InternalErr(__FILE__, __LINE__,
"Expected a scalar type when loading values for selection expression evaluation.");
141 TabularSequence::serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m,
bool ce_eval )
143 DBG(cerr <<
"Entering TabularSequence::serialize for " << name() << endl);
145 SequenceValues &values = value_ref();
148 for (SequenceValues::iterator i = values.begin(), e = values.end(); i != e; ++i) {
150 BaseTypeRow &btr = **i;
155 load_prototypes_with_values(btr,
false);
158 for (BaseTypeRow::iterator vi = btr.begin(), ve = btr.end(); vi != ve; ++vi) {
160 (*vi)->buf2val(&val);
161 d_vars.at(j++)->val2buf(val);
164 DBG(cerr << __func__ <<
": Sequence element: " << hex << *btr.begin() << dec << endl);
166 if (ce_eval && !eval.eval_selection(dds, dataset()))
170 write_start_of_instance(m);
173 for (BaseTypeRow::iterator vi = btr.begin(), ve = btr.end(); vi != ve; ++vi) {
174 if ((*vi)->send_p()) {
175 (*vi)->serialize(eval, dds, m,
false);
180 write_end_of_sequence(m);
194 void TabularSequence::intern_data(ConstraintEvaluator &eval, DDS &dds)
196 DBG(cerr <<
"Entering TabularSequence::intern_data" << endl);
203 SequenceValues result;
204 SequenceValues &values = value_ref();
206 for (SequenceValues::iterator i = values.begin(), e = values.end(); i != e; ++i) {
208 BaseTypeRow &btr = **i;
212 load_prototypes_with_values(btr,
false );
215 for (BaseTypeRow::iterator vi = btr.begin(), ve = btr.end(); vi != ve; ++vi) {
218 (*vi)->buf2val(&val);
219 d_vars.at(j++)->val2buf(val);
223 if (!eval.eval_selection(dds, dataset()))
226 BaseTypeRow *result_row =
new BaseTypeRow();
227 for (BaseTypeRow::iterator vi = btr.begin(), ve = btr.end(); vi != ve; ++vi) {
228 if ((*vi)->send_p()) {
229 result_row->push_back(*vi);
233 result.push_back(result_row);
238 DBG(cerr <<
"Leaving TabularSequence::intern_data" << endl);
250 TabularSequence::dump(ostream &strm)
const 252 strm << DapIndent::LMarg <<
"TabularSequence::dump - (" << (
void *)
this <<
")" << endl ;
253 DapIndent::Indent() ;
254 Sequence::dump(strm) ;
255 DapIndent::UnIndent() ;