librime: component.h Source File

| librime 1.2 Rime Input Method Engine, the core library

component.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5// 2011-03-14 GONG Chen <chen.sst@gmail.com>
6//
7#ifndef RIME_COMPONENT_H_
8#define RIME_COMPONENT_H_
9
10#include <rime/registry.h>
11
12namespace rime {
13
14 class ComponentBase {
15 public:
16 ComponentBase() = default;
17 virtual ~ComponentBase() = default;
18};
19
20template <class T, class Arg>
21 struct Class {
22 using Initializer = Arg;
23
24 class Component : virtual public ComponentBase {
25 public:
26 virtual T* Create(Initializer arg) = 0;
27 };
28
29 static Component* Require(const string& name) {
30 return dynamic_cast<Component*>(Registry::instance().Find(name));
31 }
32};
33
34template <class T>
35 struct Component : public T::Component {
36 public:
37 T* Create(typename T::Initializer arg) { return new T(arg); }
38};
39
40} // namespace rime
41
42#endif // RIME_COMPONENT_H_
registry.h
rime
Definition algebra.cc:12
rime::ComponentBase::ComponentBase
ComponentBase()=default
rime::ComponentBase::~ComponentBase
virtual ~ComponentBase()=default
rime::Class
Definition component.h:21
rime::Class::Initializer
Arg Initializer
Definition component.h:22
rime::Class::Require
static Component * Require(const string &name)
Definition component.h:29
rime::Class::Component
Definition component.h:24
rime::Class::Component::Create
virtual T * Create(Initializer arg)=0
rime::Component
Definition component.h:35
rime::Component::Create
T * Create(typename T::Initializer arg)
Definition component.h:37
rime::Registry::instance
static RIME_DLL Registry & instance()
Definition registry.cc:47
rime::Registry::Find
RIME_DLL ComponentBase * Find(const string &name)
Definition registry.cc:39