libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4ConstraintEvaluator.h
Go to the documentation of this file.
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 <stack>
30#include <string>
31#include <vector>
32
33#include "Array.h"
34
35namespace libdap {
36
37class location;
38class DMR;
39class BaseType;
40class Array;
41class D4Dimension;
42class D4FilterClause;
44
49 struct index {
50 // start and stride are simple numbers; stop is either the stopping index or
51 // if rest is true, is ignored and the subset runs to the end of the dimension
52 int64_t start = 0;
53 int64_t stride = 0;
54 int64_t stop = 0;
55 // true if the slice indicates it does not contain a specific 'stop' value but
56 // goes to the end, whatever that value is.
57 bool rest = false;
58 // An empty slice ([]) means either the entire dimension or apply the shared
59 // dimension slice, depending on whether the corresponding shared dimension has
60 // been sliced.
61 bool empty = false;
62 // When a slice is applied to an Array with Maps, we need to know the name of
63 // each dimension. These names are then used to apply the slice to each of the
64 // Maps (Maps may have fewer dimensions than the Array, but the idea that a
65 // Map is a simple vector doesn't hold for DAP4, so the mapping between a slice's
66 // indexes and the set of Maps can be complex - use the names to make sure
67 // all cases are covered. The value of this field may be empty.
68 std::string dim_name;
69
70 // Added because the parser code needs it. Our code does not use this. jhrg 11/26/13
71 index() = default;
72 index(int64_t i, int64_t s, int64_t e, bool r, bool em, std::string n)
73 : start(i), stride(s), stop(e), rest(r), empty(em), dim_name{std::move(n)} {}
74 };
75
76 static index make_index() { return {0, 1, 0, true /*rest*/, true /*empty*/, ""}; }
77
78 static index make_index(const std::string &is);
79
80 static index make_index(const std::string &i, const std::string &s, const std::string &e);
81 static index make_index(const std::string &i, int64_t s, const std::string &e);
82
83 static index make_index(const std::string &i, const std::string &s);
84 static index make_index(const std::string &i, int64_t s);
85
86 bool d_trace_scanning = false;
87 bool d_trace_parsing = false;
88 bool d_result = false;
89 std::string d_expr;
90
91 DMR *d_dmr = nullptr;
92
93 std::vector<index> d_indexes;
94
95 std::stack<BaseType *> d_basetype_stack;
96
97 // d_expr should be set by parse! Its value is used by the parser right before
98 // the actual parsing operation starts. jhrg 11/26/13
99 std::string *expression() { return &d_expr; }
100
101 void search_for_and_mark_arrays(BaseType *btp);
102 BaseType *mark_variable(BaseType *btp);
103 BaseType *mark_array_variable(BaseType *btp);
104 static void use_explicit_projection(Array *a, const Array::Dim_iter &dim_iter,
105 const D4ConstraintEvaluator::index &index);
106
107 D4Dimension *slice_dimension(const std::string &id, const index &i);
108
109 void push_index(const index &i) { d_indexes.push_back(i); }
110
111 void push_basetype(BaseType *btp) { d_basetype_stack.push(btp); }
112 BaseType *top_basetype() const { return d_basetype_stack.empty() ? nullptr : d_basetype_stack.top(); }
113 // throw on pop with an empty stack?
114 void pop_basetype() { d_basetype_stack.pop(); }
115
116 [[noreturn]] static void throw_not_found(const std::string &id, const std::string &ident);
117 [[noreturn]] static void throw_not_array(const std::string &id, const std::string &ident);
118
119 // Build FilterClauseList for filter clauses for a Sequence
120 void add_filter_clause(const std::string &op, const std::string &arg1, const std::string &arg2) const;
121
122 static std::string &remove_quotes(std::string &src);
123
124 friend class D4CEParser;
126
127public:
129 explicit D4ConstraintEvaluator(DMR *dmr) : d_dmr(dmr) {}
130
131 virtual ~D4ConstraintEvaluator() = default;
132
133 bool parse(const std::string &expr);
134
135 bool trace_scanning() const { return d_trace_scanning; }
136 void set_trace_scanning(bool ts) { d_trace_scanning = ts; }
137
138 bool trace_parsing() const { return d_trace_parsing; }
139 void set_trace_parsing(bool tp) { d_trace_parsing = tp; }
140
141 bool result() const { return d_result; }
142 void set_result(bool r) { d_result = r; }
143
144 DMR *dmr() const { return d_dmr; }
145 void set_dmr(DMR *dmr) { d_dmr = dmr; }
146
147 [[noreturn]] static void error(const libdap::location &l, const std::string &m);
148};
149
150} /* namespace libdap */
151#endif /* D4CEDRIVER_H_ */
A multidimensional array of identical data types.
Definition Array.h:121
std::vector< dimension >::iterator Dim_iter
Definition Array.h:225
The basic data type for the DODS DAP types.
Definition BaseType.h:118
virtual ~D4ConstraintEvaluator()=default
bool parse(const std::string &expr)
static void error(const libdap::location &l, const std::string &m)
List of DAP4 Filter Clauses.
DAP4 filter clauses.
top level DAP object to house generic methods
Definition AISConnect.cc:30