OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
Difference.cpp
Go to the documentation of this file.
2
3#include <regex>
4
5namespace mslang {
6 void Difference::print(int indentwidth) {
7 std::string indent(' ', indentwidth);
8 std::cout << indent << "Difference\n" << indent << " nominators\n";
9 dividend_m->print(indentwidth + 8);
10
11 std::cout << indent << " denominators\n";
12 divisor_m->print(indentwidth + 8);
13 }
14
15 void Difference::apply(std::vector<std::shared_ptr<Base> >& bfuncs) {
16 std::vector<std::shared_ptr<Base> > nom, denom;
17
18 dividend_m->apply(nom);
19 divisor_m->apply(denom);
20 for (auto item : nom) {
21 item->divideBy(denom);
22 bfuncs.emplace_back(item->clone());
23 }
24
25 for (auto item : nom)
26 item.reset();
27 for (auto item : denom)
28 item.reset();
29 }
30
31 bool Difference::parse_detail(iterator& it, const iterator& end, Function*& fun) {
32 Difference* dif = static_cast<Difference*>(fun);
33 if (!parse(it, end, dif->dividend_m)) return false;
34
35 std::regex argumentList("(,[a-z]+\\(.*)");
36 std::regex endParenthesis("\\)(.*)");
37 std::smatch what;
38
39 std::string str(it, end);
40 if (!std::regex_match(str, what, argumentList)) return false;
41
42 iterator it2 = it + 1;
43 if (!parse(it2, end, dif->divisor_m)) return false;
44
45 it = it2;
46 str = std::string(it, end);
47 if (!std::regex_match(str, what, endParenthesis)) return false;
48
49 std::string fullMatch = what[0];
50 std::string rest = what[1];
51
52 it += (fullMatch.size() - rest.size());
53
54 return true;
55 }
56} // namespace mslang
std::string::iterator iterator
Definition MSLang.h:14
Function * dividend_m
Definition Difference.h:8
virtual void apply(std::vector< std::shared_ptr< Base > > &bfuncs)
Function * divisor_m
Definition Difference.h:9
virtual void print(int indentwidth)
Definition Difference.cpp:6
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
virtual void apply(std::vector< std::shared_ptr< Base > > &bfuncs)=0
static bool parse(iterator &it, const iterator &end, Function *&fun)
Definition MSLang.cpp:47
virtual void print(int indent)=0