2019-04-11 14:40:54 +08:00
|
|
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
2019-03-31 01:37:06 +08:00
|
|
|
|
//
|
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
|
//
|
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
|
//
|
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
2019-10-11 21:55:29 +08:00
|
|
|
|
#include <kiwano/macros.h>
|
2019-12-23 18:05:08 +08:00
|
|
|
|
#include <kiwano/core/common.h>
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-04-11 14:40:54 +08:00
|
|
|
|
namespace kiwano
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
2019-12-30 10:00:24 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD>ش洢
|
|
|
|
|
|
/// @details LocalStorage<67><65>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ij־û<D6BE><C3BB><EFBFBD><EFBFBD>ߣ<EFBFBD><DFA3><EFBFBD><EFBFBD>ţ<EFBFBD><C5A3>ַ<EFBFBD><D6B7><EFBFBD>-ֵ<><D6B5><EFBFBD>ļ<EFBFBD>ֵ<EFBFBD><D6B5>
|
|
|
|
|
|
/// ֧<>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͱ<EFBFBD><CDB0><EFBFBD> (bool | int | float | double | String)
|
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD>߷<EFBFBD>, <20>Ա<EFBFBD><D4B1>´ν<C2B4><CEBD><EFBFBD><EFBFBD><EFBFBD>Ϸʱ<CFB7><CAB1>ȡ:
|
|
|
|
|
|
/// @code
|
|
|
|
|
|
/// LocalStorage data; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>
|
|
|
|
|
|
/// data.SaveInt(L"best-score", 20); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߷<EFBFBD> 20
|
|
|
|
|
|
/// int best = data.GetInt(L"best-score"); // <20><>ȡ֮ǰ<D6AE><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߷<EFBFBD>
|
|
|
|
|
|
/// @endcode
|
2019-10-11 21:12:29 +08:00
|
|
|
|
class KGE_API LocalStorage
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
public:
|
2019-12-30 10:00:24 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ش洢<D8B4><E6B4A2><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param file_path <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|
|
|
|
|
/// @param field <20>ֶ<EFBFBD><D6B6><EFBFBD>
|
|
|
|
|
|
LocalStorage(String const& file_path = L"data.ini", String const& field = L"defalut");
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|
|
|
|
|
String const& GetFilePath() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|
|
|
|
|
void SetFilePath(String const& file_path);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>
|
|
|
|
|
|
String const& GetFieldName() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>
|
|
|
|
|
|
void SetFieldName(String const& field);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20>жϼ<D0B6><CFBC><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
bool Exists(String const& key) const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD> int <20><><EFBFBD>͵<EFBFBD>ֵ
|
|
|
|
|
|
/// @param key <20><>
|
|
|
|
|
|
/// @param val ֵ
|
|
|
|
|
|
/// @return <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
|
|
|
|
|
bool SaveInt(String const& key, int val) const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD> float <20><><EFBFBD>͵<EFBFBD>ֵ
|
|
|
|
|
|
/// @param key <20><>
|
|
|
|
|
|
/// @param val ֵ
|
|
|
|
|
|
/// @return <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
|
|
|
|
|
bool SaveFloat(String const& key, float val) const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD> double <20><><EFBFBD>͵<EFBFBD>ֵ
|
|
|
|
|
|
/// @param key <20><>
|
|
|
|
|
|
/// @param val ֵ
|
|
|
|
|
|
/// @return <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
|
|
|
|
|
bool SaveDouble(String const& key, double val) const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD> bool <20><><EFBFBD>͵<EFBFBD>ֵ
|
|
|
|
|
|
/// @param key <20><>
|
|
|
|
|
|
/// @param val ֵ
|
|
|
|
|
|
/// @return <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
|
|
|
|
|
bool SaveBool(String const& key, bool val) const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD> String <20><><EFBFBD>͵<EFBFBD>ֵ
|
|
|
|
|
|
/// @param key <20><>
|
|
|
|
|
|
/// @param val ֵ
|
|
|
|
|
|
/// @return <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
|
|
|
|
|
bool SaveString(String const& key, String const& val) const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ int <20><><EFBFBD>͵<EFBFBD>ֵ
|
|
|
|
|
|
/// @param key <20><>
|
|
|
|
|
|
/// @param default_value ֵ<><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ص<EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
|
|
|
|
|
|
/// @return ֵ
|
|
|
|
|
|
int GetInt(String const& key, int default_value = 0) const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ float <20><><EFBFBD>͵<EFBFBD>ֵ
|
|
|
|
|
|
/// @param key <20><>
|
|
|
|
|
|
/// @param default_value ֵ<><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ص<EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
|
|
|
|
|
|
/// @return ֵ
|
|
|
|
|
|
float GetFloat(String const& key, float default_value = 0.0f) const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ double <20><><EFBFBD>͵<EFBFBD>ֵ
|
|
|
|
|
|
/// @param key <20><>
|
|
|
|
|
|
/// @param default_value ֵ<><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ص<EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
|
|
|
|
|
|
/// @return ֵ
|
|
|
|
|
|
double GetDouble(String const& key, double default_value = 0.0) const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ bool <20><><EFBFBD>͵<EFBFBD>ֵ
|
|
|
|
|
|
/// @param key <20><>
|
|
|
|
|
|
/// @param default_value ֵ<><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ص<EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
|
|
|
|
|
|
/// @return ֵ
|
|
|
|
|
|
bool GetBool(String const& key, bool default_value = false) const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ <20>ַ<EFBFBD><D6B7><EFBFBD> <20><><EFBFBD>͵<EFBFBD>ֵ
|
|
|
|
|
|
/// @param key <20><>
|
|
|
|
|
|
/// @param default_value ֵ<><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ص<EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
|
|
|
|
|
|
/// @return ֵ
|
|
|
|
|
|
String GetString(String const& key, String const& default_value = String()) const;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
private:
|
2019-03-31 01:37:06 +08:00
|
|
|
|
String file_path_;
|
|
|
|
|
|
String field_name_;
|
|
|
|
|
|
};
|
2019-12-30 10:00:24 +08:00
|
|
|
|
|
|
|
|
|
|
inline String const& LocalStorage::GetFilePath() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return file_path_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline String const& LocalStorage::GetFieldName() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return field_name_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void LocalStorage::SetFilePath(String const& file_path)
|
|
|
|
|
|
{
|
|
|
|
|
|
file_path_ = file_path;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void LocalStorage::SetFieldName(String const& field_name)
|
|
|
|
|
|
{
|
|
|
|
|
|
field_name_ = field_name;
|
|
|
|
|
|
}
|
2019-03-31 01:37:06 +08:00
|
|
|
|
}
|