librime: config_compiler.h Source File

| librime 1.2 Rime Input Method Engine, the core library

config_compiler.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5#ifndef RIME_CONFIG_COMPILER_H_
6#define RIME_CONFIG_COMPILER_H_
7
8#include <ostream>
9#include <rime/common.h>
10#include <rime/config/config_data.h>
11#include <rime/config/config_types.h>
12
13namespace rime {
14
15 struct ConfigResource : ConfigItemRef {
16 string resource_id;
17 an<ConfigData> data;
18 bool loaded = false;
19
20 ConfigResource(const string& _id, an<ConfigData> _data)
21 : ConfigItemRef(nullptr), resource_id(_id), data(_data) {}
22 an<ConfigItem> GetItem() const override { return data->root; }
23 void SetItem(an<ConfigItem> item) override { data->root = item; }
24};
25
26 struct Reference {
27 string resource_id;
28 string local_path;
29 bool optional;
30
31 string repr() const;
32};
33
34std::ostream& operator<<(std::ostream& stream, const Reference& reference);
35
36class ConfigCompilerPlugin;
37class ResourceResolver;
38struct Dependency;
39struct ConfigDependencyGraph;
40
41 class ConfigCompiler {
42 public:
43 static constexpr const char* INCLUDE_DIRECTIVE = "__include";
44 static constexpr const char* PATCH_DIRECTIVE = "__patch";
45 static constexpr const char* APPEND_DIRECTIVE = "__append";
46 static constexpr const char* MERGE_DIRECTIVE = "__merge";
47
48 ConfigCompiler(ResourceResolver* resource_resolver,
49 ConfigCompilerPlugin* plugin);
50 virtual ~ConfigCompiler();
51
52 Reference CreateReference(const string& qualified_path);
53 void AddDependency(an<Dependency> dependency);
54 void Push(an<ConfigResource> resource);
55 void Push(an<ConfigList> config_list, size_t index);
56 void Push(an<ConfigMap> config_map, const string& key);
57 bool Parse(const string& key, const an<ConfigItem>& item);
58 void Pop();
59
60 void EnumerateResources(
61 function<void(an<ConfigResource> resource)> process_resource);
62 an<ConfigResource> GetCompiledResource(const string& resource_id) const;
63 an<ConfigResource> Compile(const string& file_name);
64 bool Link(an<ConfigResource> target);
65
66 bool blocking(const string& full_path) const;
67 bool pending(const string& full_path) const;
68 bool resolved(const string& full_path) const;
69 vector<of<Dependency>> GetDependencies(const string& path);
70 bool ResolveDependencies(const string& path);
71
72 private:
73 ResourceResolver* resource_resolver_;
74 ConfigCompilerPlugin* plugin_;
75 the<ConfigDependencyGraph> graph_;
76};
77
78} // namespace rime
79
80#endif // RIME_CONFIG_COMPILER_H_
common.h
config_types.h
config_data.h
rime
Definition algebra.cc:12
rime::an
std::shared_ptr< T > an
Definition common.h:60
rime::operator<<
std::ostream & operator<<(std::ostream &stream, const Reference &reference)
Definition config_compiler.cc:12
rime::the
std::unique_ptr< T > the
Definition common.h:58
rime::path
Definition common.h:84
rime::ConfigDependencyGraph
Definition config_compiler.cc:20
rime::ConfigResource::data
an< ConfigData > data
Definition config_compiler.h:17
rime::ConfigResource::SetItem
void SetItem(an< ConfigItem > item) override
Definition config_compiler.h:23
rime::ConfigResource::resource_id
string resource_id
Definition config_compiler.h:16
rime::ConfigResource::ConfigResource
ConfigResource(const string &_id, an< ConfigData > _data)
Definition config_compiler.h:20
rime::ConfigResource::loaded
bool loaded
Definition config_compiler.h:18
rime::ConfigResource::GetItem
an< ConfigItem > GetItem() const override
Definition config_compiler.h:22
rime::Reference
Definition config_compiler.h:26
rime::Reference::local_path
string local_path
Definition config_compiler.h:28
rime::Reference::repr
string repr() const
Definition config_compiler.cc:49
rime::Reference::optional
bool optional
Definition config_compiler.h:29
rime::Reference::resource_id
string resource_id
Definition config_compiler.h:27
rime::ConfigCompiler::Push
void Push(an< ConfigResource > resource)
Definition config_compiler.cc:299
rime::ConfigCompiler::Parse
bool Parse(const string &key, const an< ConfigItem > &item)
Definition config_compiler.cc:488
rime::ConfigCompiler::Compile
an< ConfigResource > Compile(const string &file_name)
Definition config_compiler.cc:328
rime::ConfigCompiler::MERGE_DIRECTIVE
static constexpr const char * MERGE_DIRECTIVE
Definition config_compiler.h:46
rime::ConfigCompiler::AddDependency
void AddDependency(an< Dependency > dependency)
Definition config_compiler.cc:295
rime::ConfigCompiler::PATCH_DIRECTIVE
static constexpr const char * PATCH_DIRECTIVE
Definition config_compiler.h:44
rime::ConfigCompiler::APPEND_DIRECTIVE
static constexpr const char * APPEND_DIRECTIVE
Definition config_compiler.h:45
rime::ConfigCompiler::GetDependencies
vector< of< Dependency > > GetDependencies(const string &path)
Definition config_compiler.cc:413
rime::ConfigCompiler::ResolveDependencies
bool ResolveDependencies(const string &path)
Definition config_compiler.cc:520
rime::ConfigCompiler::INCLUDE_DIRECTIVE
static constexpr const char * INCLUDE_DIRECTIVE
Definition config_compiler.h:43
rime::ConfigCompiler::GetCompiledResource
an< ConfigResource > GetCompiledResource(const string &resource_id) const
Definition config_compiler.cc:323
rime::ConfigCompiler::resolved
bool resolved(const string &full_path) const
Definition config_compiler.cc:408
rime::ConfigCompiler::blocking
bool blocking(const string &full_path) const
Definition config_compiler.cc:398
rime::ConfigCompiler::CreateReference
Reference CreateReference(const string &qualified_path)
Definition config_compiler.cc:279
rime::ConfigCompiler::ConfigCompiler
ConfigCompiler(ResourceResolver *resource_resolver, ConfigCompilerPlugin *plugin)
Definition config_compiler.cc:271
rime::ConfigCompiler::EnumerateResources
void EnumerateResources(function< void(an< ConfigResource > resource)> process_resource)
Definition config_compiler.cc:316
rime::ConfigCompiler::Link
bool Link(an< ConfigResource > target)
Definition config_compiler.cc:499
rime::ConfigCompiler::pending
bool pending(const string &full_path) const
Definition config_compiler.cc:404
rime::ConfigCompiler::Pop
void Pop()
Definition config_compiler.cc:312
rime::Dependency
Definition config_compiler_impl.h:21
rime::ConfigItemRef::ConfigItemRef
ConfigItemRef(ConfigData *data)
Definition config_types.h:128
rime::ConfigCompilerPlugin
Definition plugins.h:15
rime::ResourceResolver
Definition resource.h:22