doc: add documentation for new added features
This commit is contained in:
parent
19023cb949
commit
e167479de3
|
@ -2,7 +2,76 @@
|
|||
|
||||
\page arg_parser Universal Argument Parser
|
||||
|
||||
Universal argument parser provides an universal way to parsing command line arguments.
|
||||
|
||||
Universal argument parser has similar design with universal config manager,
|
||||
it is highly recommand that read \ref config_manager chapter first,
|
||||
because you will have a clear understanding of this namespace after reading universal config manager chapter.
|
||||
|
||||
There is an example about how to use universal argument parser.
|
||||
In following content, we will describe it in detail.
|
||||
|
||||
\section arg_parser__argument Argument
|
||||
|
||||
\subsection arg_parser__argument__presets Argument Presets
|
||||
|
||||
\subsubsection arg_parser__argument__presets__number Number Argument
|
||||
|
||||
\subsubsection arg_parser__argument__presets__string String Argument
|
||||
|
||||
\subsubsection arg_parser__argument__presets__switch Switch Argument
|
||||
|
||||
Switch argument must be optional argument.
|
||||
Because it is true if user specify it explicit it,
|
||||
and will be false if user do not give this flag.
|
||||
|
||||
Switch argument also doesn't contain any value.
|
||||
Because it is just a switch.
|
||||
It can not hold any value.
|
||||
|
||||
\subsection arg_parser__argument__custom Custom Argument
|
||||
|
||||
\section arg_parser__argument_list Argument List
|
||||
|
||||
\section arg_parser__option_context Option Context
|
||||
|
||||
\section arg_parser__limitation Limitation
|
||||
|
||||
This universal argument parser is a tiny parser.
|
||||
It only just fulfill my personal requirements.
|
||||
So it only accepts limited command line syntax.
|
||||
In following content I will tell you some syntaxes which this parser \b not accept.
|
||||
|
||||
\subsection arg_parser__limitation__flag_combination Flag Combination
|
||||
|
||||
\code{sh}
|
||||
exec -l -s -h
|
||||
exec -lsh
|
||||
\endcode
|
||||
|
||||
Parser accept first line but not accept the second line.
|
||||
You must write these flags independently.
|
||||
|
||||
\subsection arg_parser__limitation__equal_symbol Equal Symbol
|
||||
|
||||
\code
|
||||
exec --value 114514
|
||||
exec --value=114514
|
||||
exec --value:114514
|
||||
\endcode
|
||||
|
||||
Parser only accept first line command.
|
||||
You can not use equal symbol or any other symbol to assign value for specified argument.
|
||||
You must write value after the argument immediately please.
|
||||
|
||||
\subsection arg_parser__limitation__variable_argument Variable Argument
|
||||
|
||||
\code
|
||||
exec -DSOME_VARABLE=SOME_VALUE
|
||||
exec -D SOME_VARIABLE=SOME_VALUE
|
||||
\endcode
|
||||
|
||||
Parser only accept second line.
|
||||
However you nned to write a custom argument or constraint to holding this value.
|
||||
|
||||
*/
|
|
@ -16,7 +16,7 @@ public:
|
|||
TestConfigManager() :
|
||||
m_IntSetting(YYCC_U8("int-setting"), INT32_C(0)),
|
||||
m_StringSetting(YYCC_U8("string-setting"), YYCC_U8("")),
|
||||
m_FloatSetting(YYCC_U8("float-setting"), 0.0f, YYCC::ConfigManager::ConstraintPresets::GetNumberRangeConstraint<float>(-1.0f, 1.0f)),
|
||||
m_FloatSetting(YYCC_U8("float-setting"), 0.0f, YYCC::Constraints::GetNumberRangeConstraint<float>(-1.0f, 1.0f)),
|
||||
m_EnumSetting(YYCC_U8("enum-setting"), TestEnum::Test1),
|
||||
m_CoreManager(YYCC_U8("test.cfg"), UINT64_C(0), {
|
||||
&m_IntSetting, &m_StringSetting, &m_FloatSetting, &m_EnumSetting
|
||||
|
@ -57,45 +57,20 @@ When constructing these settings,
|
|||
you need to provide its unique name which will be used when saving to file or reading from file.
|
||||
Also you need to provide a default value for it.
|
||||
It will be used when fail to read file or initializing itself.
|
||||
Optionally, you can assign a constraint to it which we will introduce in following section.
|
||||
|
||||
Optionally, you also can provide a constraint to setting.
|
||||
Constraint is the struct instructing library to limit value in specified range.
|
||||
It usually is used for making sure the setting stored value is valid.
|
||||
See \ref constraints chapters to know how we provide constraints.
|
||||
|
||||
\subsection config_manager__setting__custom Custom Setting
|
||||
|
||||
In most cases, the combination use of setting presets and constraints introduced in following is enough.
|
||||
In most cases, the combination use of setting presets and constraints is enough.
|
||||
However, if you still are urge to create your personal setting,
|
||||
please inherit YYCC::ConfigManager::AbstractSetting and implement essential class functions.
|
||||
For the class functions you need to implement,
|
||||
please refer to our setting presets, YYCC::ConfigManager::NumberSetting and YYCC::ConfigManager::StringSetting.
|
||||
|
||||
\section config_manager__constraint Constraint
|
||||
|
||||
Constraint can be applied to specific setting instance,
|
||||
and limit its value to specific values,
|
||||
such as minimum maximum value, specific string format and etc.
|
||||
|
||||
\subsection config_manager__constraint__presets Constraint Presets
|
||||
|
||||
YYCC::ConfigManager provide some constraint presets in YYCC::ConfigManager::Constraints namespace.
|
||||
All functions inside this namespace will return a YYCC::ConfigManager::Constraint instance,
|
||||
and you can directly assign it to the constructor of setting.
|
||||
Currently there is only one constraint preset:
|
||||
|
||||
\li YYCC::ConfigManager::Constraints::GetNumberRangeConstraint: Constrain the number value in minimum maximum value range (inclusive).
|
||||
|
||||
\subsection config_manager__constraint__custom Custom Constraint
|
||||
|
||||
For creating your personal constraint,
|
||||
you need to create YYCC::ConfigManager::Constraint instance manually.
|
||||
|
||||
First you need decide the template argument of YYCC::ConfigManager::Constraint.
|
||||
The type you assigned to template argument always is
|
||||
the same type which is accepted by the setting this constraint will be applied to.
|
||||
|
||||
Second, you need assign class member of YYCC::ConfigManager::Constraint.
|
||||
Currently there is only one class member.
|
||||
It is a function pointer called when correcting value.
|
||||
See our constraint presets for more infomation about how to write it.
|
||||
|
||||
\section config_manager__core_manager Core Manager
|
||||
|
||||
YYCC::ConfigManager::CoreManager manage a collection of settings.
|
||||
|
|
47
doc/src/constraints.dox
Normal file
47
doc/src/constraints.dox
Normal file
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
|
||||
\page constraints Constraints
|
||||
|
||||
YYCC::Constraints namespace provide YYCC::Constraints::Constraint struct declaration
|
||||
and various common constraint generator function.
|
||||
|
||||
This namespace is specifically used by YYCC::ConfigManager and YYCC::ArgParser namespaces.
|
||||
See \ref config_manager chapter and \ref arg_parser chapter for how to utlize this namespace.
|
||||
|
||||
\section constraints__prototype Prototype
|
||||
|
||||
YYCC::Constraints::Constraint instruct library how check whether given value is in range,
|
||||
and how to clamp it if it is invalid.
|
||||
For example, you can use constraint to limit a number in given minimum maximum value,
|
||||
or limit a string in specific format by using regex and etc.
|
||||
|
||||
YYCC::Constraints::Constraint is a template struct.
|
||||
The argument of template is the underlying data type which need to be checked.
|
||||
The struct with different template argument is not compatible.
|
||||
|
||||
Currently, this struct only contain 1 function pointer,
|
||||
which is used for detecting whether given value is in range / valid.
|
||||
|
||||
\subsection constraints__presets Constraint Presets
|
||||
|
||||
YYCC::Constraints provides some constraint presets which are commonly used.
|
||||
All functions inside this namespace will return a YYCC::Constraints::Constraint instance,
|
||||
and you can directly use it.
|
||||
|
||||
There is a list of all provided functions:
|
||||
|
||||
\li YYCC::Constraints::GetMinMaxRangeConstraint: Limit the number value in given minimum maximum value range (inclusive).
|
||||
\li YYCC::Constraints::GetEnumEnumerationConstraint: Limit the enum value by given all possible value set.
|
||||
\li YYCC::Constraints::GetStringEnumerationConstraint: Limit the string by given all possible value set.
|
||||
|
||||
\subsection config_manager__constraint__custom Custom Constraint
|
||||
|
||||
For creating your personal constraint,
|
||||
you need to create YYCC::Constraints::Constraint instance manually.
|
||||
You can browse all existing constraint preset functions code for know how to write it.
|
||||
|
||||
The things you need to do is simple.
|
||||
First, you need decide the template argument of YYCC::Constraints::Constraint.
|
||||
Second, you need assign class member of YYCC::Constraints::Constraint by C++ lambda syntax.
|
||||
|
||||
*/
|
|
@ -32,6 +32,9 @@ especially in GUI application because the default output stream, \c stderr, is i
|
|||
|
||||
However, please note the pathes provided by callback may be empty.
|
||||
In this case, it means that handler fail to create corresponding log files.
|
||||
Also, if you trying to register unhandled exception handler on the same process in different module with different callback,
|
||||
only the callback provided in first success registering will be called when unhandled exception happened,
|
||||
due to \ref exception_helper__notes__singleton design.
|
||||
|
||||
\subsection exception_helper__usage__location Location
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@
|
|||
|
||||
<B>Advanced Features</B>
|
||||
|
||||
\li \subpage constraints
|
||||
|
||||
\li \subpage config_manager
|
||||
|
||||
\li \subpage arg_parser
|
||||
|
|
|
@ -24,10 +24,11 @@ namespace YYCC::Constraints {
|
|||
CheckFct_t m_CheckFct;
|
||||
|
||||
/**
|
||||
* @brief Check whether this Constraint is valid for using.
|
||||
* @brief Check whether this constraint is valid for using.
|
||||
* @return
|
||||
* True if this Constraint is valid, otherwise false.
|
||||
* You should not use this Constraint if this function return false.
|
||||
* True if this constraint is valid, otherwise false.
|
||||
* If this function return false, it means that there is no contraint.
|
||||
* And you should not use this constraint provided any function pointer.
|
||||
*/
|
||||
bool IsValid() const {
|
||||
return m_CheckFct != nullptr;
|
||||
|
@ -52,7 +53,7 @@ namespace YYCC::Constraints {
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Get constraint for enum values by enumerate all possible values.
|
||||
* @brief Get constraint for enum values by enumerating all possible values.
|
||||
* @tparam _Ty An enum type (except bool) of underlying stored value.
|
||||
* @param[in] il An initializer list storing all possible values.
|
||||
* @return The generated constraint instance which can be directly applied.
|
||||
|
@ -66,7 +67,7 @@ namespace YYCC::Constraints {
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Get constraint for string values by enumerate all possible values.
|
||||
* @brief Get constraint for string values by enumerating all possible values.
|
||||
* @param[in] il An initializer list storing all possible values.
|
||||
* @return The generated constraint instance which can be directly applied.
|
||||
* @remarks
|
||||
|
|
Loading…
Reference in New Issue
Block a user