ztsdb
config_ctx.hpp
1 // (C) 2016 Leonardo Silvestri
2 //
3 // This file is part of ztsdb.
4 //
5 // ztsdb is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // ztsdb is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with ztsdb. If not, see <http://www.gnu.org/licenses/>.
17 
18 
19 #ifndef CONFIG_CTX_HPP
20 #define CONFIG_CTX_HPP
21 
22 
23 #include <map>
24 #include <boost/filesystem.hpp>
25 #include "juice/variant.hpp"
26 #include "config.hpp"
27 #include "config_parser/cfgparser.hpp"
28 
29 
30 // this tells the lexer to replace its own definition of yylex by ours (so we can pass in
31 // the CfgCtx parameter which is what makes it reentrant):
32 #undef YY_DECL
33 #define YY_DECL cfgyy::parser::symbol_type cfgyylex(cfg::CfgCtx& ctx, yyscan_t yyscanner)
34 YY_DECL;
35 
36 
37 namespace fsys = boost::filesystem;
38 
39 
40 namespace cfg {
41 
44  const void read(CfgMap& cfgmap, const fsys::path& p);
45 
46 
47  struct CfgCtx {
48 
49  struct NoConfigFile : std::exception { };
50 
51  CfgCtx(CfgMap& cfgmap_p) : cfgmap(cfgmap_p) { }
52 
53  void add(const kv_t& kv);
54 
58  int parsefile(const std::string& filename);
59 
62  int parse(const std::string& s);
63 
64  void error(const cfgyy::location& l, const std::string& m);
65 
66  // The name of the file being parsed.
67  // Used later to pass the file name to the location tracker.
68  std::string file;
69 
71 
72  std::string string_literal;
73  cfgyy::parser::location_type string_literal_yylloc;
74  private:
75  CfgMap& cfgmap;
76  };
77 }
78 
79 #endif
cfg::CfgCtx::NoConfigFile
Definition: config_ctx.hpp:49
cfg::CfgCtx::parse
int parse(const std::string &s)
Definition: config_ctx.cpp:55
cfg::CfgCtx
Definition: config_ctx.hpp:47
cfgyy::location
Two points in a source file.
Definition: location.hh:181
cfg::CfgCtx::parsefile
int parsefile(const std::string &filename)
Definition: config_ctx.cpp:42
cfg::CfgMap
Definition: config.hpp:35