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
15 public:
16 ComponentBase() = default;
17 virtual ~ComponentBase() = default;
18};
19
20template <class T, class Arg>
21struct 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>
35struct 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_
Definition algebra.cc:12
ComponentBase()=default
virtual ~ComponentBase()=default
Definition component.h:21
Arg Initializer
Definition component.h:22
static Component * Require(const string &name)
Definition component.h:29
Definition component.h:24
virtual T * Create(Initializer arg)=0
Definition component.h:35
T * Create(typename T::Initializer arg)
Definition component.h:37
static RIME_DLL Registry & instance()
Definition registry.cc:47
RIME_DLL ComponentBase * Find(const string &name)
Definition registry.cc:39