| 29 | { |
| 30 | template <typename Iterator> |
| 31 | bool parse_complex(Iterator first, Iterator last, std::complex<double>& c) |
| 32 | { |
| 33 | using boost::spirit::qi::double_; |
| 34 | using boost::spirit::qi::_1; |
| 35 | using boost::spirit::qi::phrase_parse; |
| 36 | using boost::spirit::ascii::space; |
| 37 | using boost::phoenix::ref; |
| 38 | |
| 39 | double rN = 0.0; |
| 40 | double iN = 0.0; |
| 41 | bool r = phrase_parse(first, last, |
| 42 | |
| 43 | // Begin grammar |
| 44 | ( |
| 45 | '(' >> double_[ref(rN) = _1] |
| 46 | >> -(',' >> double_[ref(iN) = _1]) >> ')' |
| 47 | | double_[ref(rN) = _1] |
| 48 | ), |
| 49 | // End grammar |
| 50 | |
| 51 | space); |
| 52 | |
| 53 | if (!r || first != last) // fail if we did not get a full match |
| 54 | return false; |
| 55 | c = std::complex<double>(rN, iN); |
| 56 | return r; |
| 57 | } |
| 58 | } |
| 59 | //] |
| 60 | |