doc: finish all documentations
This commit is contained in:
parent
7f373ed354
commit
f997990af6
|
@ -2356,7 +2356,7 @@ INCLUDE_FILE_PATTERNS =
|
||||||
# recursively expanded use the := operator instead of the = operator.
|
# recursively expanded use the := operator instead of the = operator.
|
||||||
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
|
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
|
||||||
|
|
||||||
PREDEFINED =
|
PREDEFINED = YYCC_DOXYGEN
|
||||||
|
|
||||||
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
|
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
|
||||||
# tag can be used to specify a list of macro names that should be expanded. The
|
# tag can be used to specify a list of macro names that should be expanded. The
|
||||||
|
|
|
@ -11,8 +11,16 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Universal configuration manager
|
||||||
|
* @details For how to use this namespace, please see \ref config_manager.
|
||||||
|
*/
|
||||||
namespace YYCC::ConfigManager {
|
namespace YYCC::ConfigManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The constraint applied to settings to limit its stored value.
|
||||||
|
* @tparam _Ty The internal data type stroed in corresponding setting.
|
||||||
|
*/
|
||||||
template<typename _Ty>
|
template<typename _Ty>
|
||||||
struct Constraint {
|
struct Constraint {
|
||||||
using CheckFct_t = std::function<bool(const _Ty&)>;
|
using CheckFct_t = std::function<bool(const _Ty&)>;
|
||||||
|
@ -25,8 +33,18 @@ namespace YYCC::ConfigManager {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The namespace containing functions generating common used constraint.
|
||||||
|
*/
|
||||||
namespace ConstraintPresets {
|
namespace ConstraintPresets {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get constraint for arithmetic values by minimum and maximum value range.
|
||||||
|
* @tparam _Ty The underlying arithmetic type.
|
||||||
|
* @param[in] min_value The minimum value of range (inclusive).
|
||||||
|
* @param[in] max_value The maximum value of range (inclusive).
|
||||||
|
* @return The generated constraint instance which can be directly applied.
|
||||||
|
*/
|
||||||
template<typename _Ty, std::enable_if_t<std::is_arithmetic_v<_Ty> && !std::is_enum_v<_Ty> && !std::is_same_v<_Ty, bool>, int> = 0>
|
template<typename _Ty, std::enable_if_t<std::is_arithmetic_v<_Ty> && !std::is_enum_v<_Ty> && !std::is_same_v<_Ty, bool>, int> = 0>
|
||||||
Constraint<_Ty> GetNumberRangeConstraint(_Ty min_value, _Ty max_value) {
|
Constraint<_Ty> GetNumberRangeConstraint(_Ty min_value, _Ty max_value) {
|
||||||
if (min_value > max_value)
|
if (min_value > max_value)
|
||||||
|
@ -39,9 +57,15 @@ namespace YYCC::ConfigManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief The base class of every setting.
|
||||||
|
/// @details Programmer can inherit this class and implement essential to create custom setting.
|
||||||
class AbstractSetting {
|
class AbstractSetting {
|
||||||
friend class CoreManager;
|
friend class CoreManager;
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a setting
|
||||||
|
* @param[in] name The name of this setting.
|
||||||
|
*/
|
||||||
AbstractSetting(const yycc_char8_t* name) : m_Name(), m_RawData() {
|
AbstractSetting(const yycc_char8_t* name) : m_Name(), m_RawData() {
|
||||||
if (name != nullptr) m_Name = name;
|
if (name != nullptr) m_Name = name;
|
||||||
}
|
}
|
||||||
|
@ -49,28 +73,57 @@ namespace YYCC::ConfigManager {
|
||||||
|
|
||||||
// Name interface
|
// Name interface
|
||||||
public:
|
public:
|
||||||
|
/// @brief Get name of this setting.
|
||||||
|
/// @details Name was used in storing setting in file.
|
||||||
const yycc_u8string& GetName() const { return m_Name; }
|
const yycc_u8string& GetName() const { return m_Name; }
|
||||||
private:
|
private:
|
||||||
yycc_u8string m_Name;
|
yycc_u8string m_Name;
|
||||||
|
|
||||||
// User Implementations
|
// User Implementations
|
||||||
protected:
|
protected:
|
||||||
|
/// @brief User implemented custom load functions
|
||||||
|
/// @remarks
|
||||||
|
/// In this function, programmer should read data from internal buffer
|
||||||
|
/// and store it to its own another internal variables.
|
||||||
|
/// @return True if success, otherwise false.
|
||||||
virtual bool UserLoad() = 0;
|
virtual bool UserLoad() = 0;
|
||||||
|
/// @brief User implemented custom save functions
|
||||||
|
/// @remarks
|
||||||
|
/// In this function, programmer should write data,
|
||||||
|
/// which is stored in another variavle by it own, to internal buffer.
|
||||||
|
/// @return True if success, otherwise false.
|
||||||
virtual bool UserSave() = 0;
|
virtual bool UserSave() = 0;
|
||||||
|
/// @brief User implemented custom reset functions
|
||||||
|
/// @remarks In this function, programmer should reset its internal variable to default value.
|
||||||
virtual void UserReset() = 0;
|
virtual void UserReset() = 0;
|
||||||
|
|
||||||
// Buffer related functions
|
// Buffer related functions
|
||||||
protected:
|
protected:
|
||||||
|
/// @brief Resize internal buffer to given size.
|
||||||
|
/// @remarks It is usually used in UserSave.
|
||||||
|
/// @param[in] new_size The new size of internal buffer.
|
||||||
void ResizeData(size_t new_size) { m_RawData.resize(new_size); }
|
void ResizeData(size_t new_size) { m_RawData.resize(new_size); }
|
||||||
|
/// @brief Get data pointer to internal buffer.
|
||||||
|
/// @remarks It is usually used in UserLoad.
|
||||||
const void* GetDataPtr() const { return m_RawData.data(); }
|
const void* GetDataPtr() const { return m_RawData.data(); }
|
||||||
|
/// @brief Get mutable data pointer to internal buffer.
|
||||||
|
/// @remarks It is usually used in UserSave.
|
||||||
void* GetDataPtr() { return m_RawData.data(); }
|
void* GetDataPtr() { return m_RawData.data(); }
|
||||||
|
/// @brief Get the length of internal buffer.
|
||||||
size_t GetDataSize() const { return m_RawData.size(); }
|
size_t GetDataSize() const { return m_RawData.size(); }
|
||||||
private:
|
private:
|
||||||
std::vector<uint8_t> m_RawData;
|
std::vector<uint8_t> m_RawData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// @brief Settings manager and config file reader writer.
|
||||||
class CoreManager {
|
class CoreManager {
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Build core manager.
|
||||||
|
* @param[in] cfg_file_path The path to config file.
|
||||||
|
* @param[in] version_identifier The identifier of version. Higher is newer. Lower config will try doing migration.
|
||||||
|
* @param[in] settings An initializer list containing pointers to all managed settings.
|
||||||
|
*/
|
||||||
CoreManager(
|
CoreManager(
|
||||||
const yycc_char8_t* cfg_file_path,
|
const yycc_char8_t* cfg_file_path,
|
||||||
uint64_t version_identifier,
|
uint64_t version_identifier,
|
||||||
|
@ -79,8 +132,14 @@ namespace YYCC::ConfigManager {
|
||||||
|
|
||||||
// Core functions
|
// Core functions
|
||||||
public:
|
public:
|
||||||
|
/// @brief Load settings from file.
|
||||||
|
/// @details Before loading, all settings will be reset to default value first.
|
||||||
|
/// @return True if success, otherwise false.
|
||||||
bool Load();
|
bool Load();
|
||||||
|
/// @brief Save settings to file.
|
||||||
|
/// @return True if success, otherwise false.
|
||||||
bool Save();
|
bool Save();
|
||||||
|
/// @brief Reset all settings to default value.
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -94,14 +153,30 @@ namespace YYCC::ConfigManager {
|
||||||
|
|
||||||
#pragma region Setting Presets
|
#pragma region Setting Presets
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Arithmetic (integral, floating point, bool) and enum type setting
|
||||||
|
* @tparam _Ty The internal stored type belongs to arithmetic type.
|
||||||
|
*/
|
||||||
template<typename _Ty, std::enable_if_t<std::is_arithmetic_v<_Ty> || std::is_enum_v<_Ty>, int> = 0>
|
template<typename _Ty, std::enable_if_t<std::is_arithmetic_v<_Ty> || std::is_enum_v<_Ty>, int> = 0>
|
||||||
class NumberSetting : public AbstractSetting {
|
class NumberSetting : public AbstractSetting {
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct arithmetic type setting.
|
||||||
|
* @param[in] name The name of this setting.
|
||||||
|
* @param[in] default_value The default value of this setting.
|
||||||
|
* @param[in] constraint The constraint applied to this setting.
|
||||||
|
*/
|
||||||
NumberSetting(const yycc_char8_t* name, _Ty default_value, Constraint<_Ty> constraint = Constraint<_Ty> {}) :
|
NumberSetting(const yycc_char8_t* name, _Ty default_value, Constraint<_Ty> constraint = Constraint<_Ty> {}) :
|
||||||
AbstractSetting(name), m_Data(default_value), m_DefaultData(default_value), m_Constraint(constraint) {}
|
AbstractSetting(name), m_Data(default_value), m_DefaultData(default_value), m_Constraint(constraint) {}
|
||||||
virtual ~NumberSetting() {}
|
virtual ~NumberSetting() {}
|
||||||
|
|
||||||
|
/// @brief Get stored data in setting.
|
||||||
_Ty Get() const { return m_Data; }
|
_Ty Get() const { return m_Data; }
|
||||||
|
/**
|
||||||
|
* @brief Set data to setting.
|
||||||
|
* @param[in] new_data The new data.
|
||||||
|
* @return True if success, otherwise false (given value is invalid)
|
||||||
|
*/
|
||||||
bool Set(_Ty new_data) {
|
bool Set(_Ty new_data) {
|
||||||
// validate data
|
// validate data
|
||||||
if (m_Constraint.IsValid() && !m_Constraint.m_CheckFct(new_data))
|
if (m_Constraint.IsValid() && !m_Constraint.m_CheckFct(new_data))
|
||||||
|
@ -136,8 +211,15 @@ namespace YYCC::ConfigManager {
|
||||||
Constraint<_Ty> m_Constraint;
|
Constraint<_Ty> m_Constraint;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// @brief String type setting
|
||||||
class StringSetting : public AbstractSetting {
|
class StringSetting : public AbstractSetting {
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct string setting
|
||||||
|
* @param[in] name The name of this setting.
|
||||||
|
* @param[in] default_value The default value of this setting.
|
||||||
|
* @param[in] constraint The constraint applied to this setting.
|
||||||
|
*/
|
||||||
StringSetting(const yycc_char8_t* name, const yycc_u8string_view& default_value, Constraint<yycc_u8string_view> constraint = Constraint<yycc_u8string_view> {}) :
|
StringSetting(const yycc_char8_t* name, const yycc_u8string_view& default_value, Constraint<yycc_u8string_view> constraint = Constraint<yycc_u8string_view> {}) :
|
||||||
AbstractSetting(name), m_Data(), m_DefaultData(), m_Constraint(constraint) {
|
AbstractSetting(name), m_Data(), m_DefaultData(), m_Constraint(constraint) {
|
||||||
m_Data = default_value;
|
m_Data = default_value;
|
||||||
|
@ -145,7 +227,13 @@ namespace YYCC::ConfigManager {
|
||||||
}
|
}
|
||||||
virtual ~StringSetting() {}
|
virtual ~StringSetting() {}
|
||||||
|
|
||||||
|
/// @brief Get reference to stored string.
|
||||||
const yycc_u8string& Get() const { return m_Data; }
|
const yycc_u8string& Get() const { return m_Data; }
|
||||||
|
/**
|
||||||
|
* @brief Set string data to setting.
|
||||||
|
* @param[in] new_data The new string data.
|
||||||
|
* @return True if success, otherwise false (given value is invalid)
|
||||||
|
*/
|
||||||
bool Set(const yycc_u8string_view& new_data) {
|
bool Set(const yycc_u8string_view& new_data) {
|
||||||
// check data validation
|
// check data validation
|
||||||
if (m_Constraint.IsValid() && !m_Constraint.m_CheckFct(new_data))
|
if (m_Constraint.IsValid() && !m_Constraint.m_CheckFct(new_data))
|
||||||
|
|
|
@ -26,8 +26,14 @@
|
||||||
|
|
||||||
// Define the UTF8 char type we used.
|
// Define the UTF8 char type we used.
|
||||||
// And do a polyfill if no embedded char8_t type.
|
// And do a polyfill if no embedded char8_t type.
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Library core namespace
|
||||||
|
* @details Almost library functions are located in this namespace.
|
||||||
|
*/
|
||||||
namespace YYCC {
|
namespace YYCC {
|
||||||
#if defined(__cpp_char8_t)
|
#if defined(__cpp_char8_t)
|
||||||
using yycc_char8_t = char8_t;
|
using yycc_char8_t = char8_t;
|
||||||
|
@ -38,28 +44,27 @@ namespace YYCC {
|
||||||
using yycc_u8string = std::basic_string<yycc_char8_t>;
|
using yycc_u8string = std::basic_string<yycc_char8_t>;
|
||||||
using yycc_u8string_view = std::basic_string_view<yycc_char8_t>;
|
using yycc_u8string_view = std::basic_string_view<yycc_char8_t>;
|
||||||
#endif
|
#endif
|
||||||
/**
|
}
|
||||||
|
/**
|
||||||
\typedef yycc_char8_t
|
\typedef yycc_char8_t
|
||||||
\brief YYCC UTF8 char type.
|
\brief YYCC UTF8 char type.
|
||||||
\details
|
\details
|
||||||
This char type is an alias to \c std::char8_t if your current C++ standard support it.
|
This char type is an alias to \c std::char8_t if your current C++ standard support it.
|
||||||
Otherwise it is defined as <TT>unsigned char</TT> as C++ 20 stdandard does.
|
Otherwise it is defined as <TT>unsigned char</TT> as C++ 20 stdandard does.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
\typedef yycc_u8string
|
\typedef yycc_u8string
|
||||||
\brief YYCC UTF8 string container type.
|
\brief YYCC UTF8 string container type.
|
||||||
\details
|
\details
|
||||||
This type is defined as \c std::basic_string<yycc_char8_t>.
|
This type is defined as \c std::basic_string<yycc_char8_t>.
|
||||||
It is equal to \c std::u8string if your current C++ standard support it.
|
It is equal to \c std::u8string if your current C++ standard support it.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
\typedef yycc_u8string_view
|
\typedef yycc_u8string_view
|
||||||
\brief YYCC UTF8 string view type.
|
\brief YYCC UTF8 string view type.
|
||||||
\details
|
\details
|
||||||
This type is defined as \c std::basic_string_view<yycc_char8_t>.
|
This type is defined as \c std::basic_string_view<yycc_char8_t>.
|
||||||
It is equal to \c std::u8string_view if your current C++ standard support it.
|
It is equal to \c std::u8string_view if your current C++ standard support it.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user