librime: config_data.h Source File

| librime 1.2 Rime Input Method Engine, the core library

config_data.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5
6#ifndef RIME_CONFIG_DATA_H_
7#define RIME_CONFIG_DATA_H_
8
9#include <iostream>
10#include <rime/common.h>
11
12namespace rime {
13
14class ConfigCompiler;
15class ConfigItem;
16
17 class ConfigData {
18 public:
19 ConfigData() = default;
20 ~ConfigData();
21
22 // returns whether actually saved to file.
23 bool Save();
24 bool LoadFromStream(std::istream& stream);
25 bool SaveToStream(std::ostream& stream);
26 bool LoadFromFile(const path& file_path, ConfigCompiler* compiler);
27 bool SaveToFile(const path& file_path);
28 bool TraverseWrite(const string& path, an<ConfigItem> item);
29 an<ConfigItem> Traverse(const string& path);
30
31 static vector<string> SplitPath(const string& path);
32 static string JoinPath(const vector<string>& keys);
33 static bool IsListItemReference(const string& key);
34 static string FormatListIndex(size_t index);
35 static size_t ResolveListIndex(an<ConfigItem> list,
36 const string& key,
37 bool read_only = false);
38
39 const path& file_path() const { return file_path_; }
40 bool modified() const { return modified_; }
41 void set_modified() { modified_ = true; }
42 void set_auto_save(bool auto_save) { auto_save_ = auto_save; }
43
44 an<ConfigItem> root;
45
46 protected:
47 path file_path_;
48 bool modified_ = false;
49 bool auto_save_ = false;
50};
51
52} // namespace rime
53
54#endif // RIME_CONFIG_DATA_H_
common.h
rime
Definition algebra.cc:12
rime::an
std::shared_ptr< T > an
Definition common.h:60
rime::path
Definition common.h:84
rime::ConfigCompiler
Definition config_compiler.h:41
rime::ConfigData::TraverseWrite
bool TraverseWrite(const string &path, an< ConfigItem > item)
Definition config_data.cc:201
rime::ConfigData::ResolveListIndex
static size_t ResolveListIndex(an< ConfigItem > list, const string &key, bool read_only=false)
Definition config_data.cc:113
rime::ConfigData::SaveToFile
bool SaveToFile(const path &file_path)
Definition config_data.cc:84
rime::ConfigData::file_path_
path file_path_
Definition config_data.h:47
rime::ConfigData::modified
bool modified() const
Definition config_data.h:40
rime::ConfigData::file_path
const path & file_path() const
Definition config_data.h:39
rime::ConfigData::JoinPath
static string JoinPath(const vector< string > &keys)
Definition config_data.cc:221
rime::ConfigData::FormatListIndex
static string FormatListIndex(size_t index)
Definition config_data.cc:102
rime::ConfigData::modified_
bool modified_
Definition config_data.h:48
rime::ConfigData::root
an< ConfigItem > root
Definition config_data.h:44
rime::ConfigData::Save
bool Save()
Definition config_data.cc:29
rime::ConfigData::SaveToStream
bool SaveToStream(std::ostream &stream)
Definition config_data.cc:48
rime::ConfigData::LoadFromFile
bool LoadFromFile(const path &file_path, ConfigCompiler *compiler)
Definition config_data.cc:63
rime::ConfigData::Traverse
an< ConfigItem > Traverse(const string &path)
Definition config_data.cc:225
rime::ConfigData::LoadFromStream
bool LoadFromStream(std::istream &stream)
Definition config_data.cc:33
rime::ConfigData::IsListItemReference
static bool IsListItemReference(const string &key)
Definition config_data.cc:98
rime::ConfigData::set_auto_save
void set_auto_save(bool auto_save)
Definition config_data.h:42
rime::ConfigData::set_modified
void set_modified()
Definition config_data.h:41
rime::ConfigData::SplitPath
static vector< string > SplitPath(const string &path)
Definition config_data.cc:213
rime::ConfigData::ConfigData
ConfigData()=default
rime::ConfigData::auto_save_
bool auto_save_
Definition config_data.h:49
rime::ConfigItem
Definition config_types.h:17