refactor: refactor project
- rename LIBCMO_DISABLE_COPY_MOVE -> YYCC_DEL_CLS_COPY_MOVE and LIBCMO_DEFAULT_COPY_MOVE -> YYCC_DEF_CLS_COPY_MOVE. - fix Vector declaration generator. throw exception when operator[] face invalid index, instead of do fallback. - rename VTAll.hpp -> VTInternal.hpp and VYUserAll -> VTAll.hpp for easy to understand. - fix project name error in Doxygen template. - replace all LIBCMO_OS_WIN32 to YYCC_OS == YYCC_OS_WINDOWS. - fix some compile error (involving utf8 encoding) but not the final result. - use correct way to include std-image library (use <> instead of "") - finish documentation for VTUtils.hpp and VTEncoding.hpp.
This commit is contained in:
@ -13,12 +13,16 @@
|
||||
#include <type_traits>
|
||||
#include <initializer_list>
|
||||
|
||||
/**
|
||||
* @brief The core namespace of LibCmo project.
|
||||
* @details All functions and classes involving LibCmo are located in this namespace.
|
||||
*/
|
||||
namespace LibCmo {
|
||||
|
||||
#pragma region LibCmo Exceptions
|
||||
|
||||
/**
|
||||
* @brief The exception raised when library entering unreachable scope.
|
||||
* @brief The exception thrown when library entering unreachable scope.
|
||||
* @details This exception usually used in \c switch syntax.
|
||||
* It means that program enter the scope which it definitely can not enter.
|
||||
*/
|
||||
@ -33,7 +37,7 @@ namespace LibCmo {
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The exception raised when library entering logic error.
|
||||
* @brief The exception thrown when library entering logic error.
|
||||
* @details In theory, this exception can be found by reading code.
|
||||
* It usually caused by programmer use functions in a wrong way.
|
||||
* For example, pass invalid argument to function and etc.
|
||||
@ -49,7 +53,7 @@ namespace LibCmo {
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The exception raised when library entering runtime error.
|
||||
* @brief The exception thrown when library entering runtime error.
|
||||
* @details In theory, this exception can not be found by reading code.
|
||||
* It may caused by user input or anything else.
|
||||
*/
|
||||
@ -65,13 +69,23 @@ namespace LibCmo {
|
||||
|
||||
#pragma endregion
|
||||
|
||||
/**
|
||||
* @brief The namespace for convenient C++ enum class logic operations.
|
||||
* @details
|
||||
* C++ enum class statement is a modern way to declare enum in C++.
|
||||
* But it lack essential logic operations which is commonly used by programmer.
|
||||
* So we create this helper to resolve this issue.
|
||||
*/
|
||||
namespace EnumsHelper {
|
||||
|
||||
/**
|
||||
* @brief Return 'e1 | e2 | ... | en'
|
||||
* @brief Merge given enum flags like performing <TT>e1 | e2 | ... | en</TT>
|
||||
* @tparam TEnum Enum type for processing.
|
||||
* @param[in] il The list of enum flags to be merged.
|
||||
* @return The merged enum flag.
|
||||
*/
|
||||
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
|
||||
inline TEnum Merge(std::initializer_list<TEnum> il) {
|
||||
constexpr TEnum Merge(std::initializer_list<TEnum> il) {
|
||||
using ut = std::underlying_type_t<TEnum>;
|
||||
ut result = 0;
|
||||
for (auto it = il.begin(); it != il.end(); ++it) {
|
||||
@ -81,48 +95,64 @@ namespace LibCmo {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return '~(e)'
|
||||
* @brief Reverse given enum flags like performing <TT>~(e)</TT>
|
||||
* @tparam TEnum Enum type for processing.
|
||||
* @param[in] il The list of enum flags to be inversed.
|
||||
* @return The inversed enum flag.
|
||||
*/
|
||||
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
|
||||
inline TEnum Inv(TEnum e) {
|
||||
constexpr TEnum Inv(TEnum e) {
|
||||
using ut = std::underlying_type_t<TEnum>;
|
||||
return static_cast<TEnum>(~(static_cast<ut>(e)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Operate e1 &= (~e2)
|
||||
* @brief Remove specified enum flags from given enum flags like performing <TT>e1 &= (~e2)</TT>
|
||||
* @tparam TEnum Enum type for processing.
|
||||
* @param[in,out] e1 The enum flags to be processed.
|
||||
* @param[in] e2 The enum flag to be removed.
|
||||
*/
|
||||
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
|
||||
inline void Rm(TEnum& e1, TEnum e2) {
|
||||
constexpr void Rm(TEnum& e1, TEnum e2) {
|
||||
using ut = std::underlying_type_t<TEnum>;
|
||||
e1 = static_cast<TEnum>(static_cast<ut>(e1) & static_cast<ut>(Inv(e2)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Operate e1 &= e2
|
||||
* @brief Use specified enum flags to mask given enum flags like performing <TT>e1 &= e2</TT>
|
||||
* @tparam TEnum Enum type for processing.
|
||||
* @param[in,out] e1 The enum flags to be masked.
|
||||
* @param[in] e2 The mask enum flag.
|
||||
*/
|
||||
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
|
||||
inline void Mask(TEnum& e1, TEnum e2) {
|
||||
constexpr void Mask(TEnum& e1, TEnum e2) {
|
||||
using ut = std::underlying_type_t<TEnum>;
|
||||
e1 = static_cast<TEnum>(static_cast<ut>(e1) & static_cast<ut>(e2));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Operate e1 |= e2
|
||||
* @brief Add specified enum flags to given enum flags like performing <TT>e1 |= e2</TT>
|
||||
* @tparam TEnum Enum type for processing.
|
||||
* @param[in,out] e1 The enum flags to be processed.
|
||||
* @param[in] e2 The enum flag to be added.
|
||||
*/
|
||||
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
|
||||
inline void Add(TEnum& e1, TEnum e2) {
|
||||
constexpr void Add(TEnum& e1, TEnum e2) {
|
||||
using ut = std::underlying_type_t<TEnum>;
|
||||
e1 = static_cast<TEnum>(static_cast<ut>(e1) | static_cast<ut>(e2));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Return 'bool(e1 & e2)'
|
||||
* @brief Check whether given enum flags has specified enum flag like performing <TT>bool(e & probe)</TT>
|
||||
* @tparam TEnum Enum type for processing.
|
||||
* @param[in] e1 The enum flags to be checked.
|
||||
* @param[in] e2 The enum flag for checking.
|
||||
* @return True if it has, otherwise false.
|
||||
*/
|
||||
template<typename TEnum, std::enable_if_t<std::is_enum_v<TEnum>, int> = 0>
|
||||
inline bool Has(TEnum e, TEnum probe) {
|
||||
constexpr bool Has(TEnum e1, TEnum e2) {
|
||||
using ut = std::underlying_type_t<TEnum>;
|
||||
return static_cast<bool>(static_cast<ut>(e) & static_cast<ut>(probe));
|
||||
return static_cast<bool>(static_cast<ut>(e1) & static_cast<ut>(e2));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user