]> git.sesse.net Git - cubemap/blob - parse.h
Change from level-triggered to edge-triggered epoll mode. More than halves CPU usage.
[cubemap] / parse.h
1 #ifndef _PARSE_H
2 #define _PARSE_H
3
4 // Various routines that deal with parsing; both configuration files and HTTP requests.
5
6 #include <map>
7 #include <vector>
8 #include <string>
9
10 struct ConfigLine {
11         std::string keyword;
12         std::vector<std::string> arguments;
13         std::map<std::string, std::string> parameters;
14 };
15
16 // Split a line on whitespace, e.g. "foo  bar baz" -> {"foo", "bar", "baz"}.
17 std::vector<std::string> split_tokens(const std::string &line);
18
19 // Split a string on \n or \r\n, e.g. "foo\nbar\r\n\nbaz\r\n\r\n" -> {"foo", "bar", "baz"}.
20 std::vector<std::string> split_lines(const std::string &str);
21
22 // Parse the configuration file.
23 std::vector<ConfigLine> parse_config(const std::string &filename);
24
25 // Note: Limits are inclusive.
26 int fetch_config_int(const std::vector<ConfigLine> &config, const std::string &keyword, int min_limit, int max_limit);
27
28 #endif  // !defined(_PARSE_H)