librime: engine.h Source File

| librime 1.2 Rime Input Method Engine, the core library

engine.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_ENGINE_H_
8#define RIME_ENGINE_H_
9
10#include <rime_api.h>
11#include <rime/common.h>
12#include <rime/messenger.h>
13
14namespace rime {
15
16class KeyEvent;
17class Schema;
18class Context;
19
20 class Engine : public Messenger {
21 public:
22 using CommitSink = signal<void(const string& commit_text)>;
23
24 virtual ~Engine();
25 virtual bool ProcessKey(const KeyEvent& key_event) { return false; }
26 virtual void ApplySchema(Schema* schema) {}
27 virtual void CommitText(string text) { sink_(text); }
28 virtual void Compose(Context* ctx) {}
29
30 Schema* schema() const { return schema_.get(); }
31 Context* context() const { return context_.get(); }
32 CommitSink& sink() { return sink_; }
33
34 Engine* active_engine() { return active_engine_ ? active_engine_ : this; }
35 void set_active_engine(Engine* engine = nullptr) { active_engine_ = engine; }
36
37 RIME_DLL static Engine* Create();
38
39 protected:
40 Engine();
41
42 the<Schema> schema_;
43 the<Context> context_;
44 CommitSink sink_;
45 Engine* active_engine_ = nullptr;
46};
47
48} // namespace rime
49
50#endif // RIME_ENGINE_H_
common.h
messenger.h
rime_api.h
RIME_DLL
#define RIME_DLL
Definition rime_api.h:33
rime
Definition algebra.cc:12
rime::the
std::unique_ptr< T > the
Definition common.h:58
rime::Context
Definition context.h:19
rime::Engine
Definition engine.h:20
rime::Engine::schema_
the< Schema > schema_
Definition engine.h:42
rime::Engine::sink
CommitSink & sink()
Definition engine.h:32
rime::Engine::CommitText
virtual void CommitText(string text)
Definition engine.h:27
rime::Engine::CommitSink
signal< void(const string &commit_text)> CommitSink
Definition engine.h:22
rime::Engine::active_engine
Engine * active_engine()
Definition engine.h:34
rime::Engine::active_engine_
Engine * active_engine_
Definition engine.h:45
rime::Engine::schema
Schema * schema() const
Definition engine.h:30
rime::Engine::ApplySchema
virtual void ApplySchema(Schema *schema)
Definition engine.h:26
rime::Engine::context
Context * context() const
Definition engine.h:31
rime::Engine::Create
static RIME_DLL Engine * Create()
Definition engine.cc:60
rime::Engine::Engine
Engine()
Definition engine.cc:64
rime::Engine::Compose
virtual void Compose(Context *ctx)
Definition engine.h:28
rime::Engine::set_active_engine
void set_active_engine(Engine *engine=nullptr)
Definition engine.h:35
rime::Engine::ProcessKey
virtual bool ProcessKey(const KeyEvent &key_event)
Definition engine.h:25
rime::Engine::context_
the< Context > context_
Definition engine.h:43
rime::Engine::sink_
CommitSink sink_
Definition engine.h:44
rime::KeyEvent
Definition key_event.h:17
rime::Messenger
Definition messenger.h:14
rime::Schema
Definition schema.h:15