libdap  Updated for version 3.17.2
D4ConstraintEvaluator.h
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
5 // Access Protocol.
6 
7 // Copyright (c) 2002,2003 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 #ifndef D4CEDRIVER_H_
27 #define D4CEDRIVER_H_
28 
29 #include <string>
30 #include <vector>
31 #include <stack>
32 
33 namespace libdap {
34 
35 class location;
36 class DMR;
37 class BaseType;
38 class Array;
39 class D4Dimension;
40 
45  struct index {
46  // start and stride are simple numbers; stop is either the stopping index or
47  // if to_end is true, is ignored and the subset runs to the end of the dimension
48  unsigned long long start, stride, stop;
49  // true if the slice indicates it does not contain a specific 'stop' value but
50  // goes to the end, whatever that value is.
51  bool rest;
52  // An empty slice ([]) means either the entire dimension or apply the shared
53  // dimension slice, depending on whether the corresponding shared dimension has
54  // been sliced.
55  bool empty;
56 
57  // Added because the parser code needs it. Our code does not use this. jhrg 11/26/13
58  index(): start(0), stride(0), stop(0), rest(false), empty(false) {}
59  index(unsigned long long i, unsigned long long s, unsigned long long e, bool r, bool em)
60  : start(i), stride(s), stop(e), rest(r), empty(em) {}
61  };
62 
63  index make_index() { return index(0, 1, 0, true /*rest*/, true /*empty*/); }
64 
65  index make_index(const std::string &is);
66 
67  index make_index(const std::string &i, const std::string &s, const std::string &e);
68  index make_index(const std::string &i, unsigned long long s, const std::string &e);
69 
70  index make_index(const std::string &i, const std::string &s);
71  index make_index(const std::string &i, unsigned long long s);
72 
73  bool d_trace_scanning;
74  bool d_trace_parsing;
75  bool d_result;
76  std::string d_expr;
77 
78  DMR *d_dmr;
79 
80  std::vector<index> d_indexes;
81 
82  std::stack<BaseType*> d_basetype_stack;
83 
84  // d_expr should be set by parse! Its value is used by the parser right before
85  // the actual parsing operation starts. jhrg 11/26/13
86  std::string *expression() { return &d_expr; }
87 #if 0
88  void set_array_slices(const std::string &id, Array *a);
89 #endif
90  void search_for_and_mark_arrays(BaseType *btp);
91  BaseType *mark_variable(BaseType *btp);
92  BaseType *mark_array_variable(BaseType *btp);
93 
94  D4Dimension *slice_dimension(const std::string &id, const index &i);
95 
96  void push_index(const index &i) { d_indexes.push_back(i); }
97 
98  void push_basetype(BaseType *btp) { d_basetype_stack.push(btp); }
99  BaseType *top_basetype() const { return d_basetype_stack.empty() ? 0 : d_basetype_stack.top(); }
100  // throw on pop with an empty stack?
101  void pop_basetype() { d_basetype_stack.pop(); }
102 
103  void throw_not_found(const std::string &id, const std::string &ident);
104  void throw_not_array(const std::string &id, const std::string &ident);
105 
106  friend class D4CEParser;
107 
108 public:
109  D4ConstraintEvaluator() : d_trace_scanning(false), d_trace_parsing(false), d_result(false), d_expr(""), d_dmr(0) { }
110  D4ConstraintEvaluator(DMR *dmr) : d_trace_scanning(false), d_trace_parsing(false), d_result(false), d_expr(""), d_dmr(dmr) { }
111 
112  virtual ~D4ConstraintEvaluator() { }
113 
114  bool parse(const std::string &expr);
115 
116  bool trace_scanning() const { return d_trace_scanning; }
117  void set_trace_scanning(bool ts) { d_trace_scanning = ts; }
118 
119  bool trace_parsing() const { return d_trace_parsing; }
120  void set_trace_parsing(bool tp) { d_trace_parsing = tp; }
121 
122  bool result() const { return d_result; }
123  void set_result(bool r) { d_result = r; }
124 
125  DMR *dmr() const { return d_dmr; }
126  void set_dmr(DMR *dmr) { d_dmr = dmr; }
127 
128  void error(const libdap::location &l, const std::string &m);
129 };
130 
131 } /* namespace libdap */
132 #endif /* D4CEDRIVER_H_ */
The basic data type for the DODS DAP types.
Definition: BaseType.h:117
A multidimensional array of identical data types.
Definition: Array.h:112