File: config_include_context.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 (63 lines) | stat: -rw-r--r-- 2,310 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
#pragma once

#include "types.hpp"
#include "config_parse_options.hpp"
#include "export.h"

namespace hocon {

    /**
     * Context provided to a {@link config_includer}; this interface is only useful
     * inside a {@code config_includer} implementation, and is not intended for apps
     * to implement.
     *
     * <p>
     * <em>Do not implement this interface</em>; it should only be implemented by
     * the config library. Arbitrary implementations will not work because the
     * library internals assume a specific concrete implementation. Also, this
     * interface is likely to grow new methods over time, so third-party
     * implementations will break.
     */
    class LIBCPP_HOCON_EXPORT config_include_context {
    public:
        config_include_context() : _cur_dir(new std::string("")) {}
        /**
         * Tries to find a name relative to whatever is doing the including, for
         * example in the same directory as the file doing the including. Returns
         * null if it can't meaningfully create a relative name. The returned
         * parseable may not exist; this function is not required to do any IO, just
         * compute what the name would be.
         *
         * The passed-in filename has to be a complete name (with extension), not
         * just a basename. (Include statements in config files are allowed to give
         * just a basename.)
         *
         * @param filename
         *            the name to make relative to the resource doing the including
         * @return parseable item relative to the resource doing the including, or
         *         null
         */
        virtual shared_parseable relative_to(std::string file_name) const = 0;

        /**
         * Parse options to use (if you use another method to get a
         * {@link config_parseable} then use {@link config_parseable#options()}
         * instead though).
         *
         * @return the parse options
         */
        virtual config_parse_options parse_options() const = 0;

        void set_cur_dir(std::string dir) const {
            _cur_dir->assign(dir);
        }

        std::string get_cur_dir() const {
            return *_cur_dir;
        }

    protected:
        std::shared_ptr<std::string> _cur_dir;
    };

}  // namespace hocon