librime: resource.h Source File

| librime 1.2 Rime Input Method Engine, the core library

resource.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5
6#ifndef RIME_RESOURCE_H_
7#define RIME_RESOURCE_H_
8
9#include <rime_api.h>
10#include <rime/common.h>
11
12namespace rime {
13
14class ResourceResolver;
15
16 struct ResourceType {
17 string name;
18 string prefix;
19 string suffix;
20};
21
22 class RIME_DLL ResourceResolver {
23 public:
24 explicit ResourceResolver(const ResourceType type) : type_(type) {}
25 virtual ~ResourceResolver() {}
26 virtual path ResolvePath(const string& resource_id);
27 string ToResourceId(const string& file_path) const;
28 string ToFilePath(const string& resource_id) const;
29 void set_root_path(path root_path) { root_path_ = root_path; }
30 path root_path() const { return root_path_; }
31
32 protected:
33 const ResourceType type_;
34 path root_path_;
35};
36
37// try fallback path if target file doesn't exist in root path
38 class RIME_DLL FallbackResourceResolver : public ResourceResolver {
39 public:
40 explicit FallbackResourceResolver(const ResourceType& type)
41 : ResourceResolver(type) {}
42 path ResolvePath(const string& resource_id) override;
43 void set_fallback_root_path(path fallback_root_path) {
44 fallback_root_path_ = fallback_root_path;
45 }
46
47 private:
48 path fallback_root_path_;
49};
50
51} // namespace rime
52
53#endif // RIME_RESOURCE_H_
common.h
rime_api.h
RIME_DLL
#define RIME_DLL
Definition rime_api.h:33
rime
Definition algebra.cc:12
rime::path
Definition common.h:84
rime::ResourceType
Definition resource.h:16
rime::ResourceType::prefix
string prefix
Definition resource.h:18
rime::ResourceType::suffix
string suffix
Definition resource.h:19
rime::ResourceType::name
string name
Definition resource.h:17
rime::ResourceResolver
Definition resource.h:22
rime::ResourceResolver::ResourceResolver
ResourceResolver(const ResourceType type)
Definition resource.h:24
rime::ResourceResolver::type_
const ResourceType type_
Definition resource.h:33
rime::ResourceResolver::~ResourceResolver
virtual ~ResourceResolver()
Definition resource.h:25
rime::ResourceResolver::set_root_path
void set_root_path(path root_path)
Definition resource.h:29
rime::ResourceResolver::root_path_
path root_path_
Definition resource.h:34
rime::ResourceResolver::root_path
path root_path() const
Definition resource.h:30
rime::FallbackResourceResolver::FallbackResourceResolver
FallbackResourceResolver(const ResourceType &type)
Definition resource.h:40
rime::FallbackResourceResolver::set_fallback_root_path
void set_fallback_root_path(path fallback_root_path)
Definition resource.h:43