PDI 1.7.1

the PDI data interface

expression.h
1/*******************************************************************************
2 * Copyright (C) 2015-2021 Commissariat a l'energie atomique et aux energies alternatives (CEA)
3 * Copyright (C) 2020-2021 Institute of Bioorganic Chemistry Polish Academy of Science (PSNC)
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of CEA nor the names of its contributors may be used to
14 * endorse or promote products derived from this software without specific
15 * prior written permission.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 ******************************************************************************/
25
26#ifndef PDI_EXPRESSION_H_
27#define PDI_EXPRESSION_H_
28
29#include <map>
30#include <memory>
31#include <string>
32#include <utility>
33#include <vector>
34
35#include <pdi/paraconf_wrapper.h>
36
37#include <pdi/pdi_fwd.h>
38
39namespace PDI {
40
41class PDI_EXPORT Expression
42{
43 struct PDI_NO_EXPORT Impl;
44
45 std::unique_ptr<Impl> m_impl;
46
47 Expression(std::unique_ptr<Impl>);
48
49public:
55
60 Expression(const Expression& expr);
61
67
75 Expression(const char* expr);
76
84 Expression(const std::string& expr);
85
90 Expression(long expr);
91
96 Expression(double expr);
97
102 Expression(PC_tree_t expr);
103
107
113 Expression& operator= (const Expression& expr);
114
120 Expression& operator= (Expression&& expr);
121
127 Expression operator+ (const Expression& expr) const;
128
134 Expression operator* (const Expression& expr) const;
135
141 Expression operator- (const Expression& expr) const;
142
148 Expression operator/ (const Expression& expr) const;
149
155 Expression operator% (const Expression& expr) const;
156
161 operator bool () const;
162
167 long to_long(Context& ctx) const;
168
173 double to_double(Context& ctx) const;
174
179 std::string to_string(Context& ctx) const;
180
186 Ref to_ref(Context& ctx) const;
187
194 Ref to_ref(Context& ctx, Datatype_sptr type) const;
195
202 static std::pair<Expression, long> parse_reference(const char* reference_str);
203};
204
205} // namespace PDI
206
207#endif // PDI_EXPRESSION_H_
Definition: context.h:44
Definition: expression.h:42
Ref to_ref(Context &ctx, Datatype_sptr type) const
Evaluates an expression as a data reference.
Expression()
Builds an empty expression.
static std::pair< Expression, long > parse_reference(const char *reference_str)
Parses a string that starts with $ and represents a reference expression.
double to_double(Context &ctx) const
Evaluates an expression as a float.
std::string to_string(Context &ctx) const
Evaluates an expression as a string.
Expression(long expr)
Builds an expression that represents an integer.
Expression(const std::string &expr)
Builds (i.e.
Expression(const char *expr)
Builds (i.e.
Expression(double expr)
Builds an expression that represents a float.
Expression(Expression &&expr)
Moves an expression.
long to_long(Context &ctx) const
Evaluates an expression as an integer.
~Expression()
Destroys an expression.
Expression(const Expression &expr)
Copies an expression.
Expression(PC_tree_t expr)
Builds an expression that is parsed from PC_tree_t.
Ref to_ref(Context &ctx) const
Evaluates an expression as a data reference.
A dynamically typed reference to data with automatic memory management and read/write locking semanti...
Definition: ref_any.h:248
Definition: array_datatype.h:38
std::shared_ptr< const Datatype > Datatype_sptr
Definition: pdi_fwd.h:78