librime: db_pool_impl.h Source File

| librime 1.2 Rime Input Method Engine, the core library

db_pool_impl.h
Go to the documentation of this file.
1#ifndef RIME_DB_POOL_IMPL_H_
2#define RIME_DB_POOL_IMPL_H_
3
4#include "db_pool.h"
5#include <rime/resource.h>
6
7namespace rime {
8
9template <class T>
10DbPool<T>::DbPool(the<ResourceResolver> resource_resolver)
11 : resource_resolver_(std::move(resource_resolver)) {}
12
13template <class T>
14 an<T> DbPool<T>::GetDb(const string& db_name) {
15 auto db = db_pool_[db_name].lock();
16 if (!db) {
17 auto file_path = resource_resolver_->ResolvePath(db_name);
18 db = New<T>(file_path);
19 db_pool_[db_name] = db;
20 }
21 return db;
22};
23
24} // namespace rime
25
26#endif // RIME_DB_POOL_IMPL_H_
db_pool.h
resource.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::New
an< T > New(Args &&... args)
Definition common.h:77
rime::DbPool< ReverseDb >::db_pool_
map< string, weak< ReverseDb > > db_pool_
Definition db_pool.h:20
rime::DbPool::DbPool
DbPool(the< ResourceResolver > resource_resolver)
Definition db_pool_impl.h:10
rime::DbPool::GetDb
an< T > GetDb(const string &db_name)
Definition db_pool_impl.h:14
rime::DbPool::resource_resolver_
the< ResourceResolver > resource_resolver_
Definition db_pool.h:19