librime: db_utils.h Source File

| librime 1.2 Rime Input Method Engine, the core library

db_utils.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5// 2013-04-18 GONG Chen <chen.sst@gmail.com>
6//
7#ifndef RIME_DB_UTILS_H_
8#define RIME_DB_UTILS_H_
9
10#include <rime/common.h>
11
12namespace rime {
13
14 class Sink {
15 public:
16 virtual ~Sink() = default;
17 virtual bool MetaPut(const string& key, const string& value) = 0;
18 virtual bool Put(const string& key, const string& value) = 0;
19
20 template <class SourceType>
21 int operator<<(SourceType& source);
22};
23
24 class Source {
25 public:
26 virtual ~Source() = default;
27 virtual bool MetaGet(string* key, string* value) = 0;
28 virtual bool Get(string* key, string* value) = 0;
29
30 template <class SinkType>
31 int operator>>(SinkType& sink);
32
33 int Dump(Sink* sink);
34};
35
36template <class SourceType>
37 int Sink::operator<<(SourceType& source) {
38 return source.Dump(this);
39}
40
41template <class SinkType>
42 int Source::operator>>(SinkType& sink) {
43 return Dump(&sink);
44}
45
46class Db;
47class DbAccessor;
48
49 class DbSink : public Sink {
50 public:
51 explicit DbSink(Db* db);
52
53 virtual bool MetaPut(const string& key, const string& value);
54 virtual bool Put(const string& key, const string& value);
55
56 protected:
57 Db* db_;
58};
59
60 class DbSource : public Source {
61 public:
62 explicit DbSource(Db* db);
63
64 virtual bool MetaGet(string* key, string* value);
65 virtual bool Get(string* key, string* value);
66
67 protected:
68 Db* db_;
69 an<DbAccessor> metadata_;
70 an<DbAccessor> data_;
71};
72
73} // namespace rime
74
75#endif // RIME_DB_UTILS_H_
common.h
rime
Definition algebra.cc:12
rime::an
std::shared_ptr< T > an
Definition common.h:60
rime::DbAccessor
Definition db.h:16
rime::Db
Definition db.h:33
rime::Sink
Definition db_utils.h:14
rime::Sink::Put
virtual bool Put(const string &key, const string &value)=0
rime::Sink::MetaPut
virtual bool MetaPut(const string &key, const string &value)=0
rime::Sink::~Sink
virtual ~Sink()=default
rime::Sink::operator<<
int operator<<(SourceType &source)
Definition db_utils.h:37
rime::Source
Definition db_utils.h:24
rime::Source::Get
virtual bool Get(string *key, string *value)=0
rime::Source::MetaGet
virtual bool MetaGet(string *key, string *value)=0
rime::Source::~Source
virtual ~Source()=default
rime::Source::Dump
int Dump(Sink *sink)
Definition db_utils.cc:12
rime::Source::operator>>
int operator>>(SinkType &sink)
Definition db_utils.h:42
rime::DbSink::Put
virtual bool Put(const string &key, const string &value)
Definition db_utils.cc:34
rime::DbSink::DbSink
DbSink(Db *db)
Definition db_utils.cc:28
rime::DbSink::db_
Db * db_
Definition db_utils.h:57
rime::DbSink::MetaPut
virtual bool MetaPut(const string &key, const string &value)
Definition db_utils.cc:30
rime::DbSource::DbSource
DbSource(Db *db)
Definition db_utils.cc:38
rime::DbSource::metadata_
an< DbAccessor > metadata_
Definition db_utils.h:69
rime::DbSource::Get
virtual bool Get(string *key, string *value)
Definition db_utils.cc:45
rime::DbSource::data_
an< DbAccessor > data_
Definition db_utils.h:70
rime::DbSource::db_
Db * db_
Definition db_utils.h:68
rime::DbSource::MetaGet
virtual bool MetaGet(string *key, string *value)
Definition db_utils.cc:41