テキストファイルによる unordered_map 永続化クラス
[詳解]
#include <UMT.h>
|
| | UMT (const std::string &filename) |
| | コンストラクタ。ファイルを開いて内容をメモリにロードする
|
| std::string & | operator[] (const std::string &key) |
| | キーに対応する値を参照で取得する(書き込み可能)
|
| const std::string & | operator[] (const std::string &key) const |
| | キーに対応する値を参照で取得する(読み取り専用)
|
| UMT & | operator-= (const std::string &key) |
| | 指定したキーのエントリを削除してファイルを更新する
|
| UMT & | operator+= (const std::string &keyAndValue) |
| | "key: value" 形式の文字列でエントリを追加しファイルを更新する
|
| void | save () |
| | 内部データをファイルに書き出す
|
|
| static std::string | set (const std::string &key, const std::string &value) |
| | キーと値を "key: value" 形式の文字列に変換する
|
|
| std::unordered_map< std::string, std::string > | data |
| | 内部データストア
|
テキストファイルによる unordered_map 永続化クラス
std::string v = db["name"];
db -= "name";
UMT(const std::string &filename)
コンストラクタ。ファイルを開いて内容をメモリにロードする
static std::string set(const std::string &key, const std::string &value)
キーと値を "key: value" 形式の文字列に変換する
UMT.h の 39 行目に定義があります。
◆ UMT()
| UMT::UMT |
( |
const std::string & | filename | ) |
|
|
inline |
コンストラクタ。ファイルを開いて内容をメモリにロードする
- 引数
-
| filename | 使用するテキストファイルのパス。存在しない場合は新規作成する |
- 例外
-
| std::runtime_error | ファイルの作成・読み込みに失敗した場合 |
UMT.h の 46 行目に定義があります。
◆ operator+=()
| UMT & UMT::operator+= |
( |
const std::string & | keyAndValue | ) |
|
|
inline |
"key: value" 形式の文字列でエントリを追加しファイルを更新する
- 引数
-
| keyAndValue | UMT::set(key, value) で生成したセパレータ付き文字列 |
- 戻り値
- *this への参照
- 例外
-
| std::runtime_error | セパレータが含まれていない場合、またはファイル書き込み失敗時 |
UMT.h の 100 行目に定義があります。
◆ operator-=()
| UMT & UMT::operator-= |
( |
const std::string & | key | ) |
|
|
inline |
指定したキーのエントリを削除してファイルを更新する
- 引数
-
- 戻り値
- *this への参照
- 例外
-
| std::runtime_error | ファイルへの書き込みに失敗した場合 |
UMT.h の 88 行目に定義があります。
◆ operator[]() [1/2]
| std::string & UMT::operator[] |
( |
const std::string & | key | ) |
|
|
inline |
キーに対応する値を参照で取得する(書き込み可能)
- 引数
-
- 戻り値
- 対応する値の参照(存在しない場合は空文字列が追加される)
UMT.h の 66 行目に定義があります。
◆ operator[]() [2/2]
| const std::string & UMT::operator[] |
( |
const std::string & | key | ) |
const |
|
inline |
キーに対応する値を参照で取得する(読み取り専用)
- 引数
-
- 戻り値
- 対応する値の const 参照。存在しない場合は空文字列への参照
UMT.h の 75 行目に定義があります。
◆ save()
内部データをファイルに書き出す
- 例外
-
| std::runtime_error | ファイルへの書き込みに失敗した場合 |
UMT.h の 125 行目に定義があります。
◆ set()
| std::string UMT::set |
( |
const std::string & | key, |
|
|
const std::string & | value ) |
|
inlinestatic |
キーと値を "key: value" 形式の文字列に変換する
- 引数
-
- 戻り値
- "key: value" 形式の文字列
- 覚え書き
- operator+= に渡す文字列を生成するために使用します
UMT.h の 114 行目に定義があります。
◆ data
| std::unordered_map<std::string, std::string> UMT::data |
このクラス詳解は次のファイルから抽出されました: