36 #include "D4FunctionScanner.h" 37 #include "D4FunctionEvaluator.h" 38 #include "d4_function_parser.tab.hh" 70 std::istringstream iss(expr);
72 D4FunctionParser parser(scanner, *
this );
74 if (trace_parsing()) {
75 parser.set_debug_level(1);
76 parser.set_debug_stream(std::cerr);
79 return parser.parse() == 0;
117 if (ce_parser_debug) parser.set_trace_parsing(
true);
118 bool parse_ok = parser.
parse(
function);
120 Error(malformed_expr,
"Function Expression failed to parse.");
122 if (ce_parser_debug) cerr <<
"Function Parse OK" << endl;
125 function_result =
new DMR(&d4_factory,
"function_results");
128 if (!d_result)
throw InternalErr(__FILE__, __LINE__,
"Must parse() the function expression before calling eval()");
132 for (D4RValueList::iter i = d_result->begin(), e = d_result->end(); i != e; ++i) {
136 root->
add_var((*i)->value(*d_dmr));
150 list<D4Dimension*> dim_set;
152 for (Constructor::Vars_iter i = root->
var_begin(), ie = root->
var_end(); i != ie; ++i) {
153 if ((*i)->is_vector_type()) {
159 bool found = (std::find(dim_set.begin(), dim_set.end(), d4_dim) != dim_set.end());
161 dim_set.push_back(a->dimension_D4dim(d));
170 for (list<D4Dimension*>::iterator i = dim_set.begin(), e = dim_set.end(); i != e; ++i) {
175 list<D4EnumDef*> enum_def_set;
176 for (Constructor::Vars_iter i = root->
var_begin(), ie = root->
var_end(); i != ie; ++i) {
177 if ((*i)->type() == dods_enum_c) {
178 enum_def_set.push_back(static_cast<D4Enum*>(*i)->enumeration());
182 for (list<D4EnumDef*>::iterator i = enum_def_set.begin(), e = enum_def_set.end(); i != e; ++i) {
203 D4FunctionEvaluator::build_rvalue(
const std::string &
id)
208 if (top_basetype()) {
209 btp = top_basetype()->
var(
id);
222 long long ll_val = strtoll(
id.c_str(), &end_ptr, 0);
223 if (*end_ptr ==
'\0' && errno == 0)
return new D4RValue(ll_val);
228 unsigned long long ull_val = strtoull(
id.c_str(), &end_ptr, 0);
229 if (*end_ptr ==
'\0' && errno == 0)
return new D4RValue(ull_val);
232 double d_val = strtod(
id.c_str(), &end_ptr);
233 if (*end_ptr ==
'\0' && errno == 0)
return new D4RValue(d_val);
244 D4FunctionEvaluator::init_arg_list(T val)
246 std::vector<T> *arg_list =
new std::vector<T>();
247 if (get_arg_length_hint() > 0) arg_list->reserve(get_arg_length_hint());
249 arg_list->push_back(val);
256 template std::vector<dods_byte> *D4FunctionEvaluator::init_arg_list(dods_byte val);
257 template std::vector<dods_int8> *D4FunctionEvaluator::init_arg_list(dods_int8 val);
258 template std::vector<dods_uint16> *D4FunctionEvaluator::init_arg_list(dods_uint16 val);
259 template std::vector<dods_int16> *D4FunctionEvaluator::init_arg_list(dods_int16 val);
260 template std::vector<dods_uint32> *D4FunctionEvaluator::init_arg_list(dods_uint32 val);
261 template std::vector<dods_int32> *D4FunctionEvaluator::init_arg_list(dods_int32 val);
262 template std::vector<dods_uint64> *D4FunctionEvaluator::init_arg_list(dods_uint64 val);
263 template std::vector<dods_int64> *D4FunctionEvaluator::init_arg_list(dods_int64 val);
264 template std::vector<dods_float32> *D4FunctionEvaluator::init_arg_list(dods_float32 val);
265 template std::vector<dods_float64> *D4FunctionEvaluator::init_arg_list(dods_float64 val);
270 void D4FunctionEvaluator::error(
const libdap::location &l,
const std::string &m)
273 oss << l <<
": " << m << ends;
274 throw Error(malformed_expr, oss.str());
virtual void add_function(ServerFunction *func)
Adds the passed ServerFunction pointer to the list of ServerFunctions.
virtual void add_var(BaseType *bt, Part part=nil)
top level DAP object to house generic methods
A class for software fault reporting.
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
Returns a pointer to a member of a constructor class.
std::vector< dimension >::iterator Dim_iter
void add_enum(D4EnumDef *enum_def)
bool is_quoted(const string &s)
D4RValueList * result() const
string www2id(const string &in, const string &escape, const string &except)
bool parse(const std::string &expr)
The basic data type for the DODS DAP types.
A class for error processing.
D4EnumDefs * enum_defs()
Get the enumerations defined for this Group.
A multidimensional array of identical data types.
void add_dim(D4Dimension *dim)
BaseType * find_var(const string &name)
D4Dimensions * dims()
Get the dimensions defined for this Group.