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