libdap  Updated for version 3.17.0
D4FunctionEvaluator.h
00001 // -*- mode: c++; c-basic-offset:4 -*-
00002 
00003 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
00004 // Access Protocol.
00005 
00006 // Copyright (c) 2014 OPeNDAP, Inc.
00007 // Author: James Gallagher <jgallagher@opendap.org>
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 //
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022 //
00023 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
00024 
00025 #ifndef D4_FUNCTION_DRIVER_H_
00026 #define D4_FUNCTION_DRIVER_H_
00027 
00028 #include <string>
00029 #include <vector>
00030 #include <stack>
00031 
00032 namespace libdap {
00033 
00034 class location;
00035 
00036 class BaseType;
00037 class Array;
00038 class ServerFunctionsList;
00039 
00040 class DMR;
00041 class D4Dimension;
00042 class D4RValue;
00043 class D4RValueList;
00044 
00048 class D4FunctionEvaluator
00049 {
00050     bool d_trace_scanning;
00051     bool d_trace_parsing;
00052     std::string d_expr;
00053 
00054     DMR *d_dmr;
00055     ServerFunctionsList *d_sf_list;
00056 
00057     D4RValueList *d_result;
00058 
00059     std::stack<BaseType*> d_basetype_stack;
00060 
00061     unsigned long long d_arg_length_hint;
00062 
00063     // d_expr should be set by parse! Its value is used by the parser right before
00064     // the actual parsing operation starts. jhrg 11/26/13
00065     std::string *expression()
00066     {
00067         return &d_expr;
00068     }
00069 
00070     void push_basetype(BaseType *btp)
00071     {
00072         d_basetype_stack.push(btp);
00073     }
00074     BaseType *top_basetype() const
00075     {
00076         return d_basetype_stack.empty() ? 0 : d_basetype_stack.top();
00077     }
00078     void pop_basetype()
00079     {
00080         d_basetype_stack.pop();
00081     }
00082 
00083     D4RValue *build_rvalue(const std::string &id);
00084 
00085     friend class D4FunctionParser;
00086 
00087 public:
00088     D4FunctionEvaluator() :
00089             d_trace_scanning(false), d_trace_parsing(false), d_expr(""), d_dmr(0), d_sf_list(0), d_result(0), d_arg_length_hint(
00090                     0)
00091     {
00092     }
00093     D4FunctionEvaluator(DMR *dmr, ServerFunctionsList *sf_list) :
00094             d_trace_scanning(false), d_trace_parsing(false), d_expr(""), d_dmr(dmr), d_sf_list(sf_list), d_result(0), d_arg_length_hint(
00095                     0)
00096     {
00097     }
00098 
00099     virtual ~D4FunctionEvaluator()
00100     {
00101     }
00102 
00103     bool parse(const std::string &expr);
00104 
00105     bool trace_scanning() const
00106     {
00107         return d_trace_scanning;
00108     }
00109     void set_trace_scanning(bool ts)
00110     {
00111         d_trace_scanning = ts;
00112     }
00113 
00114     bool trace_parsing() const
00115     {
00116         return d_trace_parsing;
00117     }
00118     void set_trace_parsing(bool tp)
00119     {
00120         d_trace_parsing = tp;
00121     }
00122 
00127     D4RValueList *result() const
00128     {
00129         return d_result;
00130     }
00131     void set_result(D4RValueList *rv_list)
00132     {
00133         d_result = rv_list;
00134     }
00135 
00136     void eval(DMR *dmr);
00137 
00138     unsigned long long get_arg_length_hint() const
00139     {
00140         return d_arg_length_hint;
00141     }
00142     void set_arg_length_hint(unsigned long long alh)
00143     {
00144         d_arg_length_hint = alh;
00145     }
00146 
00147     DMR *dmr() const
00148     {
00149         return d_dmr;
00150     }
00151     void set_dmr(DMR *dmr)
00152     {
00153         d_dmr = dmr;
00154     }
00155 
00156     ServerFunctionsList *sf_list() const
00157     {
00158         return d_sf_list;
00159     }
00160     void set_sf_list(ServerFunctionsList *sf_list)
00161     {
00162         d_sf_list = sf_list;
00163     }
00164 
00165     template<typename t> std::vector<t> *init_arg_list(t val);
00166 
00167     void error(const libdap::location &l, const std::string &m);
00168 };
00169 
00170 } /* namespace libdap */
00171 #endif /* D4_FUNCTION_DRIVER_H_ */