cpp-hocon 0.3.0
Loading...
Searching...
No Matches
simple_includer.hpp
1#pragma once
2
3#include <hocon/config_includer.hpp>
4#include <hocon/config_includer_file.hpp>
5#include <hocon/config_parse_options.hpp>
6#include <internal/full_includer.hpp>
7
8namespace hocon {
9
10 class name_source;
11
12 class simple_includer : public config_includer, public config_includer_file, public std::enable_shared_from_this<simple_includer> {
13 public:
14 simple_includer(shared_includer fallback);
15
16 shared_includer with_fallback(shared_includer fallback) const override;
17
18 shared_object include(shared_include_context context, std::string what) const override;
19
20 shared_object include_without_fallback(shared_include_context context, std::string what) const;
21
22 shared_object include_file(shared_include_context context, std::string what) const override;
23
24 static shared_object include_file_without_fallback(shared_include_context context, std::string what);
25
26 static config_parse_options clear_for_include(config_parse_options const& options);
27
28 static shared_object from_basename(std::shared_ptr<name_source> source,
29 std::string name,
30 config_parse_options options);
31
32 static std::shared_ptr<const full_includer> make_full(std::shared_ptr<const config_includer> includer);
33
34 private:
35 shared_includer _fallback;
36
37 // the Proxy is a proxy for an application-provided includer that uses our
38 // default implementations when the application-provided includer doesn't
39 // have an implementation.
40 class proxy : public full_includer, public std::enable_shared_from_this<proxy> {
41 public:
42 proxy(std::shared_ptr<const config_includer> delegate);
43
44 shared_includer with_fallback(shared_includer fallback) const;
45
46 shared_object include(shared_include_context context, std::string what) const;
47
48 shared_object include_file(shared_include_context context, std::string what) const;
49
50 static std::shared_ptr<const full_includer> make_full(shared_includer includer);
51
52 private:
53 std::shared_ptr<const config_includer> _delegate;
54 };
55 };
56
58 public:
59 name_source(shared_include_context context) : _context(move(context)) {
60 if (nullptr != _context) {
61 _context_initialized = true;
62 } else {
63 _context_initialized = false;
64 }
65 }
66 name_source() : name_source(nullptr) {}
67 virtual shared_parseable name_to_parseable(std::string name,
68 config_parse_options parse_options) const = 0;
69
70 void set_context(shared_include_context context) {
71 if (!_context_initialized) {
72 _context_initialized = true;
73 _context = context;
74 }
75 }
76
77 shared_include_context get_context() const {
78 return _context;
79 }
80
81 bool context_initialized() const {
82 return _context_initialized;
83 }
84
85 private:
86 shared_include_context _context;
87 bool _context_initialized;
88 };
89
91 public:
92 relative_name_source(shared_include_context context);
93
94 shared_parseable name_to_parseable(std::string name,
95 config_parse_options parse_options) const override;
96 };
97
99 public:
101
102 file_name_source(shared_include_context context);
103
104 shared_parseable name_to_parseable(std::string name,
105 config_parse_options parse_options) const override;
106 };
107
108} // namespace hocon
Implement this in addition to config_includer if you want to support inclusion of files with the incl...
Implement this interface and provide an instance to config_parse_options.set_includer() to customize ...
A set of options related to parsing.
shared_includer with_fallback(shared_includer fallback) const override
Returns a new includer that falls back to the given includer.
shared_object include_file(shared_include_context context, std::string what) const override
Parses another item to be included.
shared_object include(shared_include_context context, std::string what) const override
Parses another item to be included.
Factory for creating config_document instances.
Definition: config.hpp:18