4 #include <boost/spirit/include/qi.hpp>
5 #include <boost/fusion/include/std_pair.hpp>
6 #include <boost/fusion/include/adapt_struct.hpp>
11 namespace qi = boost::spirit::qi;
16 BOOST_FUSION_ADAPT_STRUCT(
18 (std::string, switchIP)
19 (std::string, readCommunity)
20 (std::string, writeCommunity)
21 (unsigned, uplinkPort)
30 template <typename Iterator>
32 : qi::grammar<Iterator, Lines()>
35 : LinesGrammar::base_type(query)
38 line = ip >> qi::lit(",") >>
39 community >> qi::lit(",") >>
40 community >> qi::lit(",") >>
41 port >> qi::lit(",") >>
42 port >> qi::lit(",") >>
43 mac >> qi::lit(",") >>
44 shape >> qi::lit(",") >>
45 shape >> qi::lit(",") >>
46 shape >> qi::lit(",") >>
48 ip = +qi::digit >> qi::char_('.') >>
49 +qi::digit >> qi::char_('.') >>
50 +qi::digit >> qi::char_('.') >>
52 community = +qi::char_("a-zA-Z0-9_");
54 mac = qi::xdigit >> qi::xdigit >>
55 qi::xdigit >> qi::xdigit >>
56 qi::xdigit >> qi::xdigit >>
57 qi::xdigit >> qi::xdigit >>
58 qi::xdigit >> qi::xdigit >>
59 qi::xdigit >> qi::xdigit;
61 eol = qi::lit("\r\n") | '\r' | '\n';
64 qi::rule<Iterator, Lines()> query;
65 qi::rule<Iterator, LineType()> line;
66 qi::rule<Iterator, std::string()> ip, community, mac;
67 qi::rule<Iterator, unsigned()> port, shape;
68 qi::rule<Iterator> eol;
71 bool GTS::parseData(std::string & data, Lines & lines)
73 std::string::iterator begin(data.begin());
74 std::string::iterator end(data.end());
76 LinesGrammar<std::string::iterator> parser; // Our parser
78 if (!qi::parse(begin, end, parser, lines)) {
79 logger << "parseData() - Failed to parse data" << std::endl;