Спілкування з духами

Nov 12, 2010 18:54

Мо кому згодиться - парсер детальної статистики Stargazer на Boost.Spirit2:


#include
#include

#include
#include
#include
#include

namespace qi = boost::spirit::qi;

struct Stat {
std::string ip;
int dir;
uint64_t down;
uint64_t up;
double cash;
};

struct Interval {
std::string fromTime;
std::string toTime;
};

typedef std::list Stats;
typedef std::pair StatRec;
typedef std::list StatRecs;

BOOST_FUSION_ADAPT_STRUCT(
Stat,
(std::string, ip)
(int, dir)
(uint64_t, down)
(uint64_t, up)
(double, cash)
)

BOOST_FUSION_ADAPT_STRUCT(
Interval,
(std::string, fromTime)
(std::string, toTime)
)

template
struct StatGrammar
: qi::grammar
{
StatGrammar()
: StatGrammar::base_type(query)
{
query = +chunk;
chunk = timeline >> statlines;
statlines = +statline;
timeline = qi::lit("->") >> space >> timevalue >> qi::lit(" - ") >> timevalue >> eol;
statline = space >> ip >> space >> qi::int_ >> space >> qi::int_ >> space >> qi::int_ >> space >> qi::double_ >> eol;
timevalue = +qi::digit >> qi::char_('.') >> +qi::digit >> qi::char_('.') >> +qi::digit;
ip = +qi::digit >> qi::char_('.') >> +qi::digit >> qi::char_('.') >> +qi::digit >> qi::char_('.') >> +qi::digit;
space = *qi::char_("\t ");
eol = qi::lit("\r\n") | '\r' | '\n';
}

qi::rule query;
qi::rule chunk;
qi::rule statlines;
qi::rule timeline;
qi::rule statline;
qi::rule ip;
qi::rule timevalue;
qi::rule space, eol;
};
_Winnie C++ Colorizer

cpp, spirit, stargazer, boost

Previous post Next post
Up