librime: memory.h Source File

| librime 1.2 Rime Input Method Engine, the core library

memory.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5// 2013-01-02 GONG Chen <chen.sst@gmail.com>
6//
7#ifndef RIME_MEMORY_H_
8#define RIME_MEMORY_H_
9
10#include <rime/common.h>
11#include <rime/dict/vocabulary.h>
12
13namespace rime {
14
15class KeyEvent;
16class Context;
17class Engine;
18class Dictionary;
19class UserDictionary;
20class Language;
21class Phrase;
22class Memory;
23
24 struct CommitEntry : DictEntry {
25 vector<const DictEntry*> elements;
26 Memory* memory;
27
28 CommitEntry(Memory* a_memory = NULL) : memory(a_memory) {}
29 bool empty() const { return text.empty(); }
30 void Clear();
31 void AppendPhrase(const an<Phrase>& phrase);
32 bool Save() const;
33 int Length() const;
34};
35
36 class Memory {
37 public:
38 Memory(const Ticket& ticket);
39 virtual ~Memory();
40
41 virtual bool Memorize(const CommitEntry& commit_entry) = 0;
42 virtual bool ProcessSegmentOnCommit(CommitEntry& commit_entry,
43 const Segment& seg);
44 bool StartSession();
45 bool FinishSession();
46 bool DiscardSession();
47
48 Dictionary* dict() const { return dict_.get(); }
49 UserDictionary* user_dict() const { return user_dict_.get(); }
50
51 const Language* language() const { return language_.get(); }
52
53 protected:
54 void OnCommit(Context* ctx);
55 void OnDeleteEntry(Context* ctx);
56 void OnUnhandledKey(Context* ctx, const KeyEvent& key);
57
58 the<Dictionary> dict_;
59 the<UserDictionary> user_dict_;
60 the<Language> language_;
61
62 private:
63 connection commit_connection_;
64 connection delete_connection_;
65 connection unhandled_key_connection_;
66};
67
68} // namespace rime
69
70#endif // RIME_MEMORY_H_
common.h
vocabulary.h
rime
Definition algebra.cc:12
rime::an
std::shared_ptr< T > an
Definition common.h:60
rime::the
std::unique_ptr< T > the
Definition common.h:58
rime::Context
Definition context.h:19
rime::Dictionary
Definition dictionary.h:62
rime::UserDictionary
Definition user_dictionary.h:49
rime::DictEntry::DictEntry
DictEntry()=default
rime::DictEntry::text
string text
Definition vocabulary.h:47
rime::Engine
Definition engine.h:20
rime::CommitEntry
Definition memory.h:24
rime::CommitEntry::elements
vector< const DictEntry * > elements
Definition memory.h:25
rime::CommitEntry::Save
bool Save() const
Definition memory.cc:40
rime::CommitEntry::CommitEntry
CommitEntry(Memory *a_memory=NULL)
Definition memory.h:28
rime::CommitEntry::empty
bool empty() const
Definition memory.h:29
rime::CommitEntry::memory
Memory * memory
Definition memory.h:26
rime::CommitEntry::Length
int Length() const
Definition memory.cc:48
rime::CommitEntry::AppendPhrase
void AppendPhrase(const an< Phrase > &phrase)
Definition memory.cc:28
rime::CommitEntry::Clear
void Clear()
Definition memory.cc:22
rime::Memory
Definition memory.h:36
rime::Memory::ProcessSegmentOnCommit
virtual bool ProcessSegmentOnCommit(CommitEntry &commit_entry, const Segment &seg)
Definition memory.cc:111
rime::Memory::StartSession
bool StartSession()
Definition memory.cc:99
rime::Memory::FinishSession
bool FinishSession()
Definition memory.cc:103
rime::Memory::dict
Dictionary * dict() const
Definition memory.h:48
rime::Memory::dict_
the< Dictionary > dict_
Definition memory.h:58
rime::Memory::Memory
Memory(const Ticket &ticket)
Definition memory.cc:58
rime::Memory::OnCommit
void OnCommit(Context *ctx)
Definition memory.cc:128
rime::Memory::Memorize
virtual bool Memorize(const CommitEntry &commit_entry)=0
rime::Memory::OnUnhandledKey
void OnUnhandledKey(Context *ctx, const KeyEvent &key)
Definition memory.cc:151
rime::Memory::OnDeleteEntry
void OnDeleteEntry(Context *ctx)
Definition memory.cc:138
rime::Memory::user_dict_
the< UserDictionary > user_dict_
Definition memory.h:59
rime::Memory::language
const Language * language() const
Definition memory.h:51
rime::Memory::user_dict
UserDictionary * user_dict() const
Definition memory.h:49
rime::Memory::language_
the< Language > language_
Definition memory.h:60
rime::Memory::DiscardSession
bool DiscardSession()
Definition memory.cc:107
rime::Phrase
Definition translator_commons.h:63
rime::KeyEvent
Definition key_event.h:17
rime::Language
Definition language.h:12
rime::Segment
Definition segmentation.h:18
rime::Ticket
Definition ticket.h:17