1 //
2 // Copyright RIME Developers
3 // Distributed under the BSD License
4 //
5 // 2011-04-24 GONG Chen <chen.sst@gmail.com>
6 //
7 #ifndef RIME_SCHEMA_H_
8 #define RIME_SCHEMA_H_
9 
10 #include <rime/common.h>
11 #include <rime/config.h>  // for convenience
12 
13 namespace rime {
14 
15 class Schema {
16  public:
17   Schema();
18   explicit Schema(const string& schema_id);
Schema(const string & schema_id,Config * config)19   Schema(const string& schema_id, Config* config)
20       : schema_id_(schema_id), config_(config) {}
21 
schema_id()22   const string& schema_id() const { return schema_id_; }
schema_name()23   const string& schema_name() const { return schema_name_; }
24 
config()25   Config* config() const { return config_.get(); }
set_config(Config * config)26   void set_config(Config* config) { config_.reset(config); }
27 
page_size()28   int page_size() const { return page_size_; }
page_down_cycle()29   bool page_down_cycle() const { return page_down_cycle_; }
select_keys()30   const string& select_keys() const { return select_keys_; }
set_select_keys(const string & keys)31   void set_select_keys(const string& keys) { select_keys_ = keys; }
32 
33  private:
34   void FetchUsefulConfigItems();
35 
36   string schema_id_;
37   string schema_name_;
38   the<Config> config_;
39   // frequently used config items
40   int page_size_ = 5;
41   bool page_down_cycle_ = false;
42   string select_keys_;
43 };
44 
45 class SchemaComponent : public Config::Component {
46  public:
SchemaComponent(Config::Component * config_component)47   SchemaComponent(Config::Component* config_component)
48       : config_component_(config_component) {
49   }
50   // NOTE: creates `Config` for the schema
51   Config* Create(const string& schema_id) override;
52  private:
53   // we do not own the config component, do not try to deallocate it
54   // also be careful that there is no guarantee it will outlive us
55   Config::Component* config_component_;
56 };
57 
58 }  // namespace rime
59 
60 #endif  // RIME_SCHEMA_H_
61