42#include <InternalErr.h>
44#include <dods-datatypes.h>
57template <
class T>
static bool compare(T elem, relop op,
double value) {
61 case dods_greater_equal_op:
65 case dods_less_equal_op:
69 case dods_not_equal_op:
72 throw Error(malformed_expr,
"Attempt to use NOP in Grid selection.");
74 throw Error(malformed_expr,
"Unknown relational operator in Grid selection.");
79template <
class T>
void GSEClause::set_map_min_max_value(T min, T max) {
80 DBG(cerr <<
"Inside set map min max value " << min <<
", " << max << endl);
81 std::ostringstream oss1;
83 d_map_min_value = oss1.str();
85 std::ostringstream oss2;
87 d_map_max_value = oss2.str();
91template <
class T>
void GSEClause::set_start_stop() {
92 T *vals =
new T[d_map->
length()];
97 set_map_min_max_value<T>(vals[d_start], vals[d_stop]);
106 while (i <= end && !compare<T>(vals[i], d_op1, d_value1))
114 while (i >= 0 && !compare<T>(vals[i], d_op1, d_value1))
122 if (d_op2 != dods_nop_op) {
125 while (i <= end && !compare<T>(vals[i], d_op2, d_value2))
131 while (i >= 0 && !compare<T>(vals[i], d_op2, d_value2))
140void GSEClause::compute_indices() {
141 switch (d_map->
var()->
type()) {
143 set_start_stop<dods_byte>();
146 set_start_stop<dods_int16>();
149 set_start_stop<dods_uint16>();
152 set_start_stop<dods_int32>();
155 set_start_stop<dods_uint32>();
158 set_start_stop<dods_float32>();
161 set_start_stop<dods_float64>();
164 throw Error(malformed_expr,
"Grid selection using non-numeric map vectors is not supported");
171GSEClause::GSEClause(
Grid *grid,
const string &map,
const double value,
const relop op)
172 : d_map(0), d_value1(value), d_value2(0), d_op1(op), d_op2(dods_nop_op), d_map_min_value(
""), d_map_max_value(
"") {
173 d_map =
dynamic_cast<Array *
>(grid->
var(map));
175 throw Error(
string(
"The map variable '") + map +
string(
"' does not exist in the grid '") + grid->
name() +
178 DBG(cerr << d_map->toString());
182 d_start = d_map->dimension_start(iter);
183 d_stop = d_map->dimension_stop(iter);
189GSEClause::GSEClause(
Grid *grid,
const string &map,
const double value1,
const relop op1,
const double value2,
191 : d_map(0), d_value1(value1), d_value2(value2), d_op1(op1), d_op2(op2), d_map_min_value(
""), d_map_max_value(
"") {
192 d_map =
dynamic_cast<Array *
>(grid->
var(map));
194 throw Error(
string(
"The map variable '") + map +
string(
"' does not exist in the grid '") + grid->
name() +
197 DBG(cerr << d_map->toString());
201 d_start = d_map->dimension_start(iter);
202 d_stop = d_map->dimension_stop(iter);
207GSEClause::~GSEClause() {
delete d_map; }
211bool GSEClause::OK()
const {
222Array *GSEClause::get_map()
const {
return d_map; }
228void GSEClause::set_map(
Array *map) { d_map = map; }
232string GSEClause::get_map_name()
const {
return d_map->
name(); }
237int GSEClause::get_start()
const {
return d_start; }
241void GSEClause::set_start(
int start) { d_start = start; }
246int GSEClause::get_stop()
const {
247 DBG(cerr <<
"Returning stop index value of: " << d_stop << endl);
253void GSEClause::set_stop(
int stop) { d_stop = stop; }
259string GSEClause::get_map_min_value()
const {
return d_map_min_value; }
265string GSEClause::get_map_max_value()
const {
return d_map_max_value; }
A multidimensional array of identical data types.
std::vector< dimension >::iterator Dim_iter
virtual string name() const
Returns the name of the class instance.
virtual Type type() const
Returns the type of the class instance.
BaseType * var(const string &name, bool exact_match=true, btp_stack *s=nullptr) override
btp_stack no longer needed; use back pointers (BaseType::get_parent())
A class for error processing.
Holds the Grid data type.
int length() const override
Returns the number of elements in the vector. Note that some child classes of Vector use the length o...
BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=nullptr) override
top level DAP object to house generic methods