Vita
string.h
Go to the documentation of this file.
1
13#if !defined(VITA_STRING_PRIMITIVE_H)
14#define VITA_STRING_PRIMITIVE_H
15
16#include <algorithm>
17#include <cstdlib>
18#include <string>
19
20#include "kernel/gp/function.h"
22#include "kernel/gp/terminal.h"
23#include "kernel/random.h"
24
25namespace vita::str
26{
27
31class ife : public function
32{
33public:
34 explicit ife(const cvect &c)
35 : function("SIFE", c[1], {c[0], c[0], c[1], c[1]})
36 { Expects(c.size() == 2); }
37
38 std::string display(format f) const final
39 {
40 switch (f)
41 {
42 case c_format:
43 case cpp_format:
44 case mql_format: return "(%%1%% == %%2%% ? %%3%% : %%4%%)";
45 case python_format: return "(%%3%% if %%1%% == %%2%% else %%4%%)";
46 default: return function::display();
47 }
48 }
49
50 value_t eval(symbol_params &args) const final
51 {
52 const auto v0(args[0]);
53 if (!has_value(v0)) return v0;
54
55 const auto v1(args[1]);
56 if (!has_value(v1)) return v1;
57
58 if (v0 == v1)
59 return args[2];
60
61 return args[3];
62 }
63};
64
65} // namespace vita::str
66
67#endif // include guard
A symbol with arity() > 0.
Definition: function.h:35
function(const std::string &, category_t, cvect)
Definition: function.cc:25
virtual std::string display(format=c_format) const
Definition: function.cc:52
String comparison for equality.
Definition: string.h:32
value_t eval(symbol_params &args) const final
Calculates the value of / performs the action associated with the symbol (it's implementation specifi...
Definition: string.h:50
std::string display(format f) const final
Definition: string.h:38
An interface for parameter passing to functions / terminals.
format
Symbol rendering format.
Definition: symbol.h:39
bool has_value(const value_t &v)
Definition: value.h:51
std::variant< D_VOID, D_INT, D_DOUBLE, D_STRING > value_t
A variant containing the data types used by the interpreter for internal calculations / output value ...
Definition: value.h:45