File: simple_includer.hpp

package info (click to toggle)
cpp-hocon 0.3.0-1.2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,320 kB
  • sloc: cpp: 12,223; makefile: 4
file content (108 lines) | stat: -rw-r--r-- 3,842 bytes parent folder | download | duplicates (3)
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
97
98
99
100
101
102
103
104
105
106
107
108
#pragma once

#include <hocon/config_includer.hpp>
#include <hocon/config_includer_file.hpp>
#include <hocon/config_parse_options.hpp>
#include <internal/full_includer.hpp>

namespace hocon {

    class name_source;

    class simple_includer : public config_includer, public config_includer_file, public std::enable_shared_from_this<simple_includer> {
    public:
        simple_includer(shared_includer fallback);

        shared_includer with_fallback(shared_includer fallback) const override;

        shared_object include(shared_include_context context, std::string what) const override;

        shared_object include_without_fallback(shared_include_context context, std::string what) const;

        shared_object include_file(shared_include_context context, std::string what) const override;

        static shared_object include_file_without_fallback(shared_include_context context, std::string what);

        static config_parse_options clear_for_include(config_parse_options const& options);

        static shared_object from_basename(std::shared_ptr<name_source> source,
                                           std::string name,
                                           config_parse_options options);

        static std::shared_ptr<const full_includer> make_full(std::shared_ptr<const config_includer> includer);

    private:
        shared_includer _fallback;

        // the Proxy is a proxy for an application-provided includer that uses our
        // default implementations when the application-provided includer doesn't
        // have an implementation.
        class proxy : public full_includer, public std::enable_shared_from_this<proxy> {
        public:
            proxy(std::shared_ptr<const config_includer> delegate);

            shared_includer with_fallback(shared_includer fallback) const;

            shared_object include(shared_include_context context, std::string what) const;

            shared_object include_file(shared_include_context context, std::string what) const;

            static std::shared_ptr<const full_includer> make_full(shared_includer includer);

        private:
            std::shared_ptr<const config_includer> _delegate;
        };
    };

    class name_source {
    public:
        name_source(shared_include_context context) : _context(move(context)) {
            if (nullptr != _context) {
                _context_initialized = true;
            } else {
                _context_initialized = false;
            }
        }
        name_source() : name_source(nullptr) {}
        virtual shared_parseable name_to_parseable(std::string name,
                                                   config_parse_options parse_options) const = 0;

        void set_context(shared_include_context context) {
            if (!_context_initialized) {
                _context_initialized = true;
                _context = context;
            }
        }

        shared_include_context get_context() const {
            return _context;
        }

        bool context_initialized() const {
            return _context_initialized;
        }

    private:
        shared_include_context _context;
        bool _context_initialized;
    };

    class relative_name_source : public name_source {
    public:
        relative_name_source(shared_include_context context);

        shared_parseable name_to_parseable(std::string name,
                                           config_parse_options parse_options) const override;
    };

    class file_name_source : public name_source {
    public:
        file_name_source();

        file_name_source(shared_include_context context);

        shared_parseable name_to_parseable(std::string name,
                                           config_parse_options parse_options) const override;
    };

}  // namespace hocon