#include #include #include #include #include #include "datatypes.h" #include "logger.h" namespace qi = boost::spirit::qi; using SSMD::LineType; using SSMD::Lines; BOOST_FUSION_ADAPT_STRUCT( SSMD::LineType, (std::string, switchIP) (std::string, readCommunity) (std::string, writeCommunity) (unsigned, uplinkPort) (unsigned, userPort) (std::string, mac) (unsigned, upShape) (unsigned, downShape) (unsigned, upBurst) (unsigned, downBurst) ) template struct LinesGrammar : qi::grammar { LinesGrammar() : LinesGrammar::base_type(query) { query = +line; line = ip >> qi::lit(",") >> community >> qi::lit(",") >> community >> qi::lit(",") >> port >> qi::lit(",") >> port >> qi::lit(",") >> mac >> qi::lit(",") >> shape >> qi::lit(",") >> shape >> qi::lit(",") >> shape >> qi::lit(",") >> shape >> eol; ip = +qi::digit >> qi::char_('.') >> +qi::digit >> qi::char_('.') >> +qi::digit >> qi::char_('.') >> +qi::digit; community = +qi::char_("a-zA-Z0-9_"); port = qi::int_; mac = qi::xdigit >> qi::xdigit >> qi::xdigit >> qi::xdigit >> qi::xdigit >> qi::xdigit >> qi::xdigit >> qi::xdigit >> qi::xdigit >> qi::xdigit >> qi::xdigit >> qi::xdigit; shape = qi::int_; eol = qi::lit("\r\n") | '\r' | '\n'; } qi::rule query; qi::rule line; qi::rule ip, community, mac; qi::rule port, shape; qi::rule eol; }; bool SSMD::parseData(std::string & data, Lines & lines) { std::string::iterator begin(data.begin()); std::string::iterator end(data.end()); LinesGrammar parser; // Our parser if (!qi::parse(begin, end, parser, lines)) { logger << "parseData() - Failed to parse data" << std::endl; return false; } return true; }