-
Notifications
You must be signed in to change notification settings - Fork 168
/
Copy pathDispatcher.cpp
96 lines (78 loc) · 2.96 KB
/
Dispatcher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/************************************************************************
* Copyright(c) 2021, One Unified. All rights reserved. *
* email: [email protected] *
* *
* This file is provided as is WITHOUT ANY WARRANTY *
* without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
* This software may not be used nor distributed without proper license *
* agreement. *
* *
* See the file LICENSE.txt for redistribution information. *
************************************************************************/
/*
* File: Dispatcher.cpp
* Author: [email protected]
* Project: TFIQFeed/Level2
* Created on October 17, 2021 10:56
*/
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/qi_symbols.hpp>
#include "Dispatcher.h"
BOOST_FUSION_ADAPT_STRUCT(
ou::tf::iqfeed::l2::SystemStatus,
(ou::tf::iqfeed::l2::SystemStatus::ECmd, cmd)
(ou::tf::iqfeed::l2::SystemStatus::vString_t, vString)
)
namespace qi = boost::spirit::qi;
namespace ou { // One Unified
namespace tf { // TradeFrame
namespace iqfeed { // IQFeed
namespace l2 { // level 2 data
template<typename Iterator>
struct SystemStatusParser: qi::grammar<Iterator, ou::tf::iqfeed::l2::SystemStatus()> {
using ECmd = ou::tf::iqfeed::l2::SystemStatus::ECmd;
SystemStatusParser(): SystemStatusParser::base_type( ruleStart ) {
cmd.add
( "SERVER CONNECTED", ECmd::ServerConnected )
( "CURRENT PROTOCOL", ECmd::CurrentProtocol )
( "CLEAR DEPTH", ECmd::ClearDepth )
( "SERVER DISCONNECTED", ECmd::ServerDisconnected )
;
ruleCmd = cmd;
ruleString = +( qi::char_ - qi::char_( ',' ) );
ruleStart
%=
qi::lit( 'S' ) >> qi::lit( ',' )
>> ruleCmd
>> -( qi::lit( ',' ) >> ruleString % ',' )
>> -qi::lit( ',' )
;
}
qi::symbols<char, ECmd> cmd;
qi::rule<Iterator, ECmd()> ruleCmd;
qi::rule<Iterator, std::string()> ruleString;
qi::rule<Iterator, ou::tf::iqfeed::l2::SystemStatus()> ruleStart;
};
bool ParseSystemStatus( const std::string& src, SystemStatus& status ) {
SystemStatusParser<std::string::const_iterator> grammarSystemStatus;
bool bOk( false );
try {
bOk = parse( src.begin(), src.end(), grammarSystemStatus, status );
}
catch( const std::runtime_error& e) {
std::cout << e.what() << std::endl;
}
catch( const boost::exception& e) {
std::cout << boost::diagnostic_information(e) << std::endl;
}
catch(...) {
std::cerr << "error" << std::endl;
}
return bOk;
}
} // namespace l2
} // namesapce iqfeed
} // namespace tf
} // namespace ou