Source Resolver
Usage
 1#pragma once
 2
 3#include <erbsland/conf/SourceResolver.hpp>
 4#include <erbsland/conf/FileSourceResolver.hpp>
 5
 6using el::conf::SourceResolver;
 7using el::conf::SourceResolverPtr;
 8using el::conf::SourceResolverContext;
 9using el::conf::SourceList;
10using el::conf::SourceListPtr;
11using el::conf::FileSourceResolver;
12
13class MySourceResolver final : public SourceResolver {
14public:
15    MySourceResolver() : _fallbackResolver(FileSourceResolver::create()) {}
16    [[nodiscard]] static auto create() -> SourceResolverPtr {
17        return std::make_shared<MySourceResolver>();
18    }
19
20public:
21    auto resolve(const SourceResolverContext &context) -> SourceListPtr override {
22        if (!context.includeText.starts_with(u8"my:")) {
23            return _fallbackResolver->resolve(context);
24        }
25        auto result = std::make_shared<SourceList>();
26        // ...add my sources...
27        return result;
28    }
29
30private:
31    SourceResolverPtr _fallbackResolver;
32};
Interface
- 
class SourceResolver
 The interface for any source resolver implementation.
Subclassed by erbsland::conf::FileSourceResolver
Public Functions
- 
virtual ~SourceResolver() = default
 Default destructor.
- 
virtual SourceListPtr resolve(const SourceResolverContext &context) = 0
 Resolve Sources
This function is called when the parser encounters an
includemeta-command.The raw and unprocessed text of the command and the source of the parsed document are given as arguments to this function. This function must either return a list of sources that match the expression or throw an
Errorexception. If an exception is thrown, the parsing will be stopped and the thrown exception will be passed to the caller ofparse().If a list is returned, the parser will parse the sources in the given order and include the parsed contents in the document. The returned sources should be in a closed state. The parser will open them in the sequence they are parsed.
- Tested:
 Tested via
Parserclass.
- Parameters:
 context – The resolve context.
- Throws:
 Error – Throw
ErrorwithErrorCategory::Syntaxif the include text does not match the required format.- Returns:
 A list of sources (see
SourceList) to include in the document.
- 
virtual ~SourceResolver() = default
 
- 
struct SourceResolverContext
 The context for resolving sources.
- Tested:
 Tested via
Parserclass.
Public Members
- 
SourceIdentifierPtr sourceIdentifier
 The source identifier of the document with the
include-command.
- 
using erbsland::conf::SourceResolverPtr = std::shared_ptr<SourceResolver>
 
- 
class FileSourceResolver : public erbsland::conf::SourceResolver
 A file source resolver.
The file source resolver supports the recommended format to include files. It works with relative and absolute paths and also has support for wildcards.
Here are a few examples:
&at;include "file:example.elcl" # File in the same directory. &at;include "file:sub/example.elcl" # File in a subdirectory of the current configuration file. &at;include "file:../example.elcl" # File in the parent directory (if access rules allow it) &at;include "file:/usr/local/example.elcl" # Absolute path.
Public Types
- 
enum Feature
 Features of the file source resolver
Values:
- 
enumerator RecursiveWildcard
 Support for recursive wildcards.
- 
enumerator FilenameWildcard
 Support for filename wildcards.
- 
enumerator AbsolutePaths
 Support for absolute paths.
- 
enumerator WindowsUNCPath
 Support for Windows UNC paths.
- 
enumerator FileProtocol
 Support for the
file:protocol prefix.
- 
enumerator _featureCount
 
- 
enumerator RecursiveWildcard
 
Public Functions
- 
FileSourceResolver() = default
 Default constructor.
- 
~FileSourceResolver() override = default
 Default destructor.
- 
virtual SourceListPtr resolve(const SourceResolverContext &context) override
 Resolve Sources
This function is called when the parser encounters an
includemeta-command.The raw and unprocessed text of the command and the source of the parsed document are given as arguments to this function. This function must either return a list of sources that match the expression or throw an
Errorexception. If an exception is thrown, the parsing will be stopped and the thrown exception will be passed to the caller ofparse().If a list is returned, the parser will parse the sources in the given order and include the parsed contents in the document. The returned sources should be in a closed state. The parser will open them in the sequence they are parsed.
- Tested:
 Tested via
Parserclass.
- Parameters:
 context – The resolve context.
- Throws:
 Error – Throw
ErrorwithErrorCategory::Syntaxif the include text does not match the required format.- Returns:
 A list of sources (see
SourceList) to include in the document.
Public Static Functions
- 
static inline FileSourceResolverPtr create()
 Create a new instance of the file source resolver.
- 
enum Feature
 
- 
using erbsland::conf::FileSourceResolverPtr = std::shared_ptr<FileSourceResolver>