44#include <dods-datatypes.h>
57template <
class T>
static bool compare(T elem,
relop op,
double value) {
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))
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);
247 DBG(cerr <<
"Returning stop index value of: " << d_stop << endl);
#define malformed_expr
(400)
string get_map_name() const
Get the name of the map variable constrained by this clause.
libdap::Array * get_map() const
Get a pointer to the map variable constrained by this clause.
void set_stop(int stop)
Set the stopping index.
int get_stop() const
Get the stopping index of the clause's map variable as constrained by this clause.
void set_start(int start)
Set the starting index.
string get_map_max_value() const
Get the maximum map vector value.
int get_start() const
Get the starting index of the clause's map variable as constrained by this clause.
string get_map_min_value() const
Get the minimum map vector value.
void set_map(libdap::Array *map)
Set the pointer to the map vector contrained by this clause.
A multidimensional array of identical data types.
std::vector< dimension >::iterator Dim_iter
virtual string name() const
Returns the name 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.
top level DAP object to house generic methods