Compare commits
10 Commits
afb206c8d1
...
5c3b7c4b1b
Author | SHA1 | Date | |
---|---|---|---|
5c3b7c4b1b | |||
a34ad88277 | |||
3147098f71 | |||
4ab5c2378a | |||
e87627dec9 | |||
6484071f40 | |||
9d1bc4c0e0 | |||
407de7999c | |||
6c0b82861d | |||
ff039f1918 |
6
.gitmodules
vendored
Normal file
6
.gitmodules
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[submodule "Convention/[nlohmann]"]
|
||||||
|
path = Convention/[nlohmann]
|
||||||
|
url = https://github.com/nlohmann/json.git
|
||||||
|
[submodule "Convention/[Static]"]
|
||||||
|
path = Convention/[Static]
|
||||||
|
url = https://github.com/NINEMINEsigma/ModernCPP.git
|
@@ -1,5 +1,14 @@
|
|||||||
# Make Setting
|
# Make Setting
|
||||||
|
set(MAIN_PROJECT OFF)
|
||||||
|
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||||
|
set(MAIN_PROJECT ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(MAIN_PROJECT)
|
||||||
message("Root: --- ----- ----- ----- ----- --")
|
message("Root: --- ----- ----- ----- ----- --")
|
||||||
|
else()
|
||||||
|
message("Convention: --- ----- ----- ----- ----- --")
|
||||||
|
endif()
|
||||||
|
|
||||||
add_compile_definitions(__PLATFORM_NAME="${PLATFORM_NAME}")
|
add_compile_definitions(__PLATFORM_NAME="${PLATFORM_NAME}")
|
||||||
add_compile_definitions(__PLATFORM_VERSION="${PLATFORM_VERSION}")
|
add_compile_definitions(__PLATFORM_VERSION="${PLATFORM_VERSION}")
|
||||||
@@ -15,8 +24,9 @@ set(CMAKE_CXX_STANDARD 17)
|
|||||||
set(C_STANDARD 11)
|
set(C_STANDARD 11)
|
||||||
# Enable UNICODE
|
# Enable UNICODE
|
||||||
add_compile_definitions(UNICODE)
|
add_compile_definitions(UNICODE)
|
||||||
message("Root: PROJECT_BINARY_DIR = ${PROJECT_BINARY_DIR}")
|
if(MAIN_PROJECT)
|
||||||
|
message("Root: PROJECT_BINARY_DIR = ${PROJECT_BINARY_DIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
# MSVC Policy
|
# MSVC Policy
|
||||||
if (POLICY CMP0141)
|
if (POLICY CMP0141)
|
||||||
@@ -28,13 +38,15 @@ cmake_policy(SET CMP0076 NEW)
|
|||||||
|
|
||||||
|
|
||||||
# Message Platfrom
|
# Message Platfrom
|
||||||
message("Root: ${PLATFORM_NAME}-${PLATFORM_VERSION}-${PLATFORM_EXTENSION}")
|
if(MAIN_PROJECT)
|
||||||
|
message("Root: ${PLATFORM_NAME}-${PLATFORM_VERSION}-${PLATFORM_EXTENSION}")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Threads Enable
|
# Threads Enable
|
||||||
add_compile_definitions(_PTHREADS)
|
add_compile_definitions(_PTHREADS)
|
||||||
|
|
||||||
# Project
|
# Project
|
||||||
project("Convention-All")
|
project("Convention")
|
||||||
|
|
||||||
# 设置构建共享库
|
# 设置构建共享库
|
||||||
set(BUILD_SHARED_LIBS ON)
|
set(BUILD_SHARED_LIBS ON)
|
||||||
@@ -55,10 +67,16 @@ endif()
|
|||||||
|
|
||||||
# Project
|
# Project
|
||||||
add_subdirectory("Convention")
|
add_subdirectory("Convention")
|
||||||
add_subdirectory("[Test]")
|
if(MAIN_PROJECT)
|
||||||
|
add_subdirectory("[Test]")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(MAIN_PROJECT)
|
||||||
message("Root: CMAKE_CXX_STANDARD = ${CMAKE_CXX_STANDARD}" )
|
message("Root: CMAKE_CXX_STANDARD = ${CMAKE_CXX_STANDARD}" )
|
||||||
message("Root: CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")
|
message("Root: CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")
|
||||||
message("Root: CMAKE_CXX_COMPILER_VERSION = ${CMAKE_CXX_COMPILER_VERSION}")
|
message("Root: CMAKE_CXX_COMPILER_VERSION = ${CMAKE_CXX_COMPILER_VERSION}")
|
||||||
|
|
||||||
message("Root: ----- ----- ----- ----- -----")
|
message("Root: ----- ----- ----- ----- -----")
|
||||||
|
else()
|
||||||
|
message("Convention: ----- ----- ----- ----- -----")
|
||||||
|
endif()
|
@@ -1,5 +1,6 @@
|
|||||||
message("Convention: --- ----- ----- ----- ----- --")
|
message("Convention: --- ----- ----- ----- ----- --")
|
||||||
|
|
||||||
|
include_directories(${PROJECT_SOURCE_DIR}/Convention/nlohmann/include)
|
||||||
install(DIRECTORY [Runtime]
|
install(DIRECTORY [Runtime]
|
||||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/include
|
DESTINATION ${CMAKE_INSTALL_PREFIX}/include
|
||||||
FILES_MATCHING PATTERN "*.*"
|
FILES_MATCHING PATTERN "*.*"
|
||||||
|
@@ -381,15 +381,20 @@ namespace Convention
|
|||||||
|
|
||||||
void UpdateTimeline()
|
void UpdateTimeline()
|
||||||
{
|
{
|
||||||
for(auto&& [_, timeline] : TimelineQuenes)
|
for (bool stats = true; stats;)
|
||||||
{
|
{
|
||||||
if (timeline.Quene[timeline.Context].predicate())
|
stats = false;
|
||||||
|
for (auto&& [_, timeline] : TimelineQuenes)
|
||||||
{
|
{
|
||||||
for(auto&& action : timeline.Quene[timeline.Context].actions)
|
if (timeline.Quene[timeline.Context].predicate())
|
||||||
{
|
{
|
||||||
action();
|
stats = true;
|
||||||
|
for (auto&& action : timeline.Quene[timeline.Context].actions)
|
||||||
|
{
|
||||||
|
action();
|
||||||
|
}
|
||||||
|
timeline.Context++;
|
||||||
}
|
}
|
||||||
timeline.Context++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -267,9 +267,9 @@ constexpr int ConstexprStrCompare(
|
|||||||
#define __PLATFORM_VERSION "Unknown"
|
#define __PLATFORM_VERSION "Unknown"
|
||||||
#endif // __PLATFORM_VERSION
|
#endif // __PLATFORM_VERSION
|
||||||
|
|
||||||
#ifndef PLATFORM_EXTENSION
|
#ifndef __PLATFORM_EXTENSION
|
||||||
#define PLATFORM_EXTENSION ""
|
#define __PLATFORM_EXTENSION ""
|
||||||
#endif // PLATFORM_EXTENSION
|
#endif // __PLATFORM_EXTENSION
|
||||||
|
|
||||||
struct PlatformIndicator
|
struct PlatformIndicator
|
||||||
: public
|
: public
|
||||||
@@ -328,7 +328,6 @@ struct PlatformIndicator
|
|||||||
constexpr static bool IsGNUC = false;
|
constexpr static bool IsGNUC = false;
|
||||||
#endif // __GNUC__
|
#endif // __GNUC__
|
||||||
|
|
||||||
|
|
||||||
constexpr static const char* PlatformInfomation = __PLATFORM_NAME "-" __PLATFORM_VERSION "-" __PLATFORM_EXTENSION;
|
constexpr static const char* PlatformInfomation = __PLATFORM_NAME "-" __PLATFORM_VERSION "-" __PLATFORM_EXTENSION;
|
||||||
// not lock current thread, if input is exist will return it otherwise return -1
|
// not lock current thread, if input is exist will return it otherwise return -1
|
||||||
static int KeyboardInput() noexcept;
|
static int KeyboardInput() noexcept;
|
||||||
@@ -1394,7 +1393,9 @@ struct StringIndicator
|
|||||||
static str ToString(const T& value)
|
static str ToString(const T& value)
|
||||||
{
|
{
|
||||||
if_exists(T::ToString)
|
if_exists(T::ToString)
|
||||||
|
{
|
||||||
return value.ToString();
|
return value.ToString();
|
||||||
|
}
|
||||||
if constexpr (std::is_constructible_v<const T&, str>)
|
if constexpr (std::is_constructible_v<const T&, str>)
|
||||||
return value;
|
return value;
|
||||||
else if constexpr (std::is_same_v<str, std::wstring>)
|
else if constexpr (std::is_same_v<str, std::wstring>)
|
||||||
@@ -1722,7 +1723,7 @@ namespace Convention
|
|||||||
if constexpr (index == 0)
|
if constexpr (index == 0)
|
||||||
return sizeof(Element);
|
return sizeof(Element);
|
||||||
else
|
else
|
||||||
return sizeof(Element) + _MyNext::ElementOffset<index - 1>();
|
return sizeof(Element) + _MyNext:: template ElementOffset<index - 1>();
|
||||||
}
|
}
|
||||||
template<size_t index>
|
template<size_t index>
|
||||||
decltype(auto) GetValue() const noexcept
|
decltype(auto) GetValue() const noexcept
|
||||||
@@ -1800,6 +1801,11 @@ namespace Convention
|
|||||||
public:
|
public:
|
||||||
constexpr static size_t size = 0;
|
constexpr static size_t size = 0;
|
||||||
constexpr static size_t _MySize = 0;
|
constexpr static size_t _MySize = 0;
|
||||||
|
template<size_t index>
|
||||||
|
constexpr static size_t ElementOffset()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1871,6 +1877,7 @@ namespace Convention
|
|||||||
using _SharedPtr = SharedPtr<T>;
|
using _SharedPtr = SharedPtr<T>;
|
||||||
using _UniquePtr = UniquePtr<T, DefaultDelete<T, Allocator>>;
|
using _UniquePtr = UniquePtr<T, DefaultDelete<T, Allocator>>;
|
||||||
using _Mybase = std::conditional_t<IsUnique, _UniquePtr, _SharedPtr>;
|
using _Mybase = std::conditional_t<IsUnique, _UniquePtr, _SharedPtr>;
|
||||||
|
using _MyAlloc = Allocator<T>;
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief 获取内存管理器
|
* @brief 获取内存管理器
|
||||||
@@ -1885,13 +1892,19 @@ namespace Convention
|
|||||||
{
|
{
|
||||||
T* ptr = GetStaticMyAllocator().allocate(1);
|
T* ptr = GetStaticMyAllocator().allocate(1);
|
||||||
GetStaticMyAllocator().construct(ptr, std::forward<Args>(args)...);
|
GetStaticMyAllocator().construct(ptr, std::forward<Args>(args)...);
|
||||||
return ptr
|
return ptr;
|
||||||
}
|
}
|
||||||
static void _DestoryMyPtr(_In_ T* ptr)
|
static void _DestoryMyPtr(_In_ T* ptr)
|
||||||
{
|
{
|
||||||
GetStaticMyAllocator().destroy(ptr);
|
GetStaticMyAllocator().destroy(ptr);
|
||||||
GetStaticMyAllocator().deallocate(ptr, 1);
|
GetStaticMyAllocator().deallocate(ptr, 1);
|
||||||
}
|
}
|
||||||
|
protected:
|
||||||
|
template<typename... Args>
|
||||||
|
static T* ConstructMyPtr(Args&&... args)
|
||||||
|
{
|
||||||
|
return BuildMyPtr(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief 任意匹配的构造函数
|
* @brief 任意匹配的构造函数
|
||||||
@@ -1952,7 +1965,8 @@ namespace Convention
|
|||||||
/**
|
/**
|
||||||
* @brief 拷贝赋值函数
|
* @brief 拷贝赋值函数
|
||||||
*/
|
*/
|
||||||
virtual instance& operator=(const instance& value) noexcept
|
template<typename = std::void_t<std::declval<instance>().WriteValue(std::declval<instance>().ReadConstValue())>>
|
||||||
|
instance& operator=(const instance& value)
|
||||||
{
|
{
|
||||||
if constexpr (IsUnique)
|
if constexpr (IsUnique)
|
||||||
{
|
{
|
||||||
@@ -1965,6 +1979,21 @@ namespace Convention
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
* @brief 拷贝赋值函数
|
||||||
|
*/
|
||||||
|
virtual instance& operator=(const instance& value) noexcept(IsUnique == false)
|
||||||
|
{
|
||||||
|
if constexpr (IsUnique)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("unique ptr is not support to copy");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_Mybase::operator=(value);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
* @brief 移动赋值函数
|
* @brief 移动赋值函数
|
||||||
*/
|
*/
|
||||||
virtual instance& operator=(instance&& value) noexcept
|
virtual instance& operator=(instance&& value) noexcept
|
||||||
|
@@ -10,13 +10,25 @@ namespace Convention
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::filesystem::path FullPath;
|
std::filesystem::path FullPath;
|
||||||
mutable std::fstream OriginControlStream;
|
//mutable std::fstream OriginControlStream;
|
||||||
mutable bool StreamOpen = false;
|
//mutable bool StreamOpen = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ToolFile(const std::filesystem::path& path) : FullPath(path) {}
|
ToolFile(const std::filesystem::path& path) : FullPath(path) {}
|
||||||
explicit ToolFile(const std::string& path) : FullPath(path) {}
|
ToolFile(const std::string& path) : FullPath(path) {}
|
||||||
explicit ToolFile(const char* path) : FullPath(path) {}
|
ToolFile(const char* path) : FullPath(path) {}
|
||||||
|
ToolFile(const ToolFile& other) : FullPath(other.FullPath) {}
|
||||||
|
ToolFile(ToolFile&& other) : FullPath(std::move(other.FullPath)) {}
|
||||||
|
ToolFile& operator=(const ToolFile& other)
|
||||||
|
{
|
||||||
|
this->FullPath = other.FullPath;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
ToolFile& operator=(ToolFile&& other)
|
||||||
|
{
|
||||||
|
this->FullPath = std::move(other.FullPath);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
// Convert to string
|
// Convert to string
|
||||||
operator std::string() const { return FullPath.string(); }
|
operator std::string() const { return FullPath.string(); }
|
||||||
@@ -85,20 +97,21 @@ namespace Convention
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ToolFile& Open(std::ios::openmode mode = std::ios::in | std::ios::out)
|
/*ToolFile& Open(std::ios::openmode mode = std::ios::in | std::ios::out)
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
OriginControlStream.open(FullPath, mode);
|
OriginControlStream.open(FullPath, mode);
|
||||||
StreamOpen = OriginControlStream.is_open();
|
StreamOpen = OriginControlStream.is_open();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
ToolFile& Close()
|
ToolFile& Close()
|
||||||
{
|
{
|
||||||
if (StreamOpen) {
|
/*if (StreamOpen)
|
||||||
|
{
|
||||||
OriginControlStream.close();
|
OriginControlStream.close();
|
||||||
StreamOpen = false;
|
StreamOpen = false;
|
||||||
}
|
}*/
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +167,8 @@ namespace Convention
|
|||||||
ToolFile& MustExistsPath()
|
ToolFile& MustExistsPath()
|
||||||
{
|
{
|
||||||
auto parent = FullPath.parent_path();
|
auto parent = FullPath.parent_path();
|
||||||
if (!parent.empty() && !std::filesystem::exists(parent)) {
|
if (!parent.empty() && !std::filesystem::exists(parent))
|
||||||
|
{
|
||||||
std::filesystem::create_directories(parent);
|
std::filesystem::create_directories(parent);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
|
@@ -11,19 +11,17 @@ namespace Convention
|
|||||||
class GlobalConfig
|
class GlobalConfig
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static std::string ConstConfigFile;
|
constexpr static auto ConstConfigFile = "config.json";
|
||||||
|
|
||||||
static void InitExtensionEnv()
|
static void InitExtensionEnv()
|
||||||
{
|
{
|
||||||
ConstConfigFile = "config.json";
|
|
||||||
ProjectConfig::InitExtensionEnv();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GenerateEmptyConfigJson(ToolFile& file)
|
static void GenerateEmptyConfigJson(ToolFile& file)
|
||||||
{
|
{
|
||||||
nlohmann::json config;
|
nlohmann::json config;
|
||||||
config["properties"] = nlohmann::json::object();
|
config["properties"] = nlohmann::json::object();
|
||||||
file.Open(std::ios::out | std::ios::trunc);
|
|
||||||
file.SaveAsText(config.dump(4));
|
file.SaveAsText(config.dump(4));
|
||||||
file.Close();
|
file.Close();
|
||||||
}
|
}
|
||||||
@@ -54,9 +52,12 @@ namespace Convention
|
|||||||
|
|
||||||
// Build up init data file
|
// Build up init data file
|
||||||
auto configFile = GetConfigFile();
|
auto configFile = GetConfigFile();
|
||||||
if (!configFile.Exists()) {
|
if (!configFile.Exists())
|
||||||
|
{
|
||||||
GenerateEmptyConfigJson(configFile);
|
GenerateEmptyConfigJson(configFile);
|
||||||
} else if (isLoad) {
|
}
|
||||||
|
else if (isLoad)
|
||||||
|
{
|
||||||
LoadProperties();
|
LoadProperties();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,7 +70,8 @@ namespace Convention
|
|||||||
ToolFile GetFile(const std::string& path, bool isMustExist = false)
|
ToolFile GetFile(const std::string& path, bool isMustExist = false)
|
||||||
{
|
{
|
||||||
auto file = DataDir | path;
|
auto file = DataDir | path;
|
||||||
if (isMustExist) {
|
if (isMustExist)
|
||||||
|
{
|
||||||
file.MustExistsPath();
|
file.MustExistsPath();
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
@@ -78,13 +80,16 @@ namespace Convention
|
|||||||
bool EraseFile(const std::string& path)
|
bool EraseFile(const std::string& path)
|
||||||
{
|
{
|
||||||
auto file = DataDir | path;
|
auto file = DataDir | path;
|
||||||
if (file.Exists()) {
|
if (file.Exists())
|
||||||
try {
|
{
|
||||||
file.Open(std::ios::out | std::ios::trunc);
|
file.MustExistsPath();
|
||||||
file.Close();
|
if (file.IsFile())
|
||||||
return true;
|
{
|
||||||
} catch (...) {}
|
file.Remove();
|
||||||
}
|
file.Create();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,22 +169,32 @@ namespace Convention
|
|||||||
GlobalConfig& LoadProperties()
|
GlobalConfig& LoadProperties()
|
||||||
{
|
{
|
||||||
auto configFile = GetConfigFile();
|
auto configFile = GetConfigFile();
|
||||||
if (!configFile.Exists()) {
|
if (!configFile.Exists())
|
||||||
|
{
|
||||||
data_pair.clear();
|
data_pair.clear();
|
||||||
} else {
|
}
|
||||||
try {
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
auto content = configFile.LoadAsText();
|
auto content = configFile.LoadAsText();
|
||||||
auto config = nlohmann::json::parse(content);
|
auto config = nlohmann::json::parse(content);
|
||||||
|
|
||||||
if (config.contains("properties") && config["properties"].is_object()) {
|
if (config.contains("properties") && config["properties"].is_object())
|
||||||
|
{
|
||||||
data_pair.clear();
|
data_pair.clear();
|
||||||
for (auto& [key, value] : config["properties"].items()) {
|
for (auto& [key, value] : config["properties"].items())
|
||||||
|
{
|
||||||
data_pair[key] = value;
|
data_pair[key] = value;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
throw std::runtime_error("Can't find properties in config file");
|
throw std::runtime_error("Can't find properties in config file");
|
||||||
}
|
}
|
||||||
} catch (const nlohmann::json::exception& e) {
|
}
|
||||||
|
catch (const nlohmann::json::exception& e)
|
||||||
|
{
|
||||||
throw std::runtime_error("JSON parsing error: " + std::string(e.what()));
|
throw std::runtime_error("JSON parsing error: " + std::string(e.what()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,7 +224,7 @@ namespace Convention
|
|||||||
MyDefaultLogger = std::move(logger);
|
MyDefaultLogger = std::move(logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Log(const std::string& messageType, const std::string& message, std::function<void(const std::string&)> logger = nullptr)
|
virtual void Log(const std::string& messageType, const std::string& message, std::function<void(const std::string&)> logger)
|
||||||
{
|
{
|
||||||
configLogging_tspace = std::max(configLogging_tspace, messageType.length());
|
configLogging_tspace = std::max(configLogging_tspace, messageType.length());
|
||||||
|
|
||||||
@@ -238,7 +253,7 @@ namespace Convention
|
|||||||
Log(messageType, message, nullptr);
|
Log(messageType, message, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogPropertyNotFound(const std::string& message, std::function<void(const std::string&)> logger = nullptr, const std::string& defaultValue = "")
|
void LogPropertyNotFound(const std::string& message, std::function<void(const std::string&)> logger, const std::string& defaultValue)
|
||||||
{
|
{
|
||||||
std::string fullMessage = message;
|
std::string fullMessage = message;
|
||||||
if (!defaultValue.empty()) {
|
if (!defaultValue.empty()) {
|
||||||
@@ -247,7 +262,7 @@ namespace Convention
|
|||||||
Log("Property not found", fullMessage, logger);
|
Log("Property not found", fullMessage, logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogPropertyNotFound(const std::string& message, const std::string& defaultValue = "")
|
void LogPropertyNotFound(const std::string& message, const std::string& defaultValue)
|
||||||
{
|
{
|
||||||
LogPropertyNotFound(message, nullptr, defaultValue);
|
LogPropertyNotFound(message, nullptr, defaultValue);
|
||||||
}
|
}
|
||||||
@@ -258,42 +273,35 @@ namespace Convention
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T FindItem(const std::string& key, const T& defaultValue = T{}) const
|
T FindItem(const std::string& key, const T& defaultValue = T{})
|
||||||
{
|
{
|
||||||
auto it = data_pair.find(key);
|
auto it = data_pair.find(key);
|
||||||
if (it != data_pair.end()) {
|
if (it != data_pair.end())
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
return it->second.get<T>();
|
return it->second.get<T>();
|
||||||
} catch (const nlohmann::json::exception&) {
|
|
||||||
LogPropertyNotFound("Cannot convert value for key: " + key);
|
|
||||||
}
|
}
|
||||||
} else {
|
catch (const nlohmann::json::exception&)
|
||||||
LogPropertyNotFound("Key not found: " + key);
|
{
|
||||||
|
LogPropertyNotFound(std::string("Cannot convert value for key: ") + key, std::to_string(defaultValue));
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
LogPropertyNotFound(std::string("Key not found: ") + key, std::to_string(defaultValue));
|
||||||
}
|
}
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Static member definition
|
|
||||||
std::string GlobalConfig::ConstConfigFile = "config.json";
|
|
||||||
|
|
||||||
class ProjectConfig : public GlobalConfig
|
class ProjectConfig : public GlobalConfig
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static std::string ProjectConfigFileFocus;
|
constexpr static auto ProjectConfigFileFocus = "Assets/";
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void InitExtensionEnv()
|
|
||||||
{
|
|
||||||
ProjectConfigFileFocus = "Assets/";
|
|
||||||
}
|
|
||||||
|
|
||||||
ProjectConfig(bool isLoad = true) : GlobalConfig(ProjectConfigFileFocus, true, isLoad) {}
|
ProjectConfig(bool isLoad = true) : GlobalConfig(ToolFile(ProjectConfigFileFocus), true, isLoad) {}
|
||||||
|
|
||||||
static void SetProjectConfigFileFocus(const std::string& path)
|
|
||||||
{
|
|
||||||
ProjectConfigFileFocus = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string GetProjectConfigFileFocus()
|
static std::string GetProjectConfigFileFocus()
|
||||||
{
|
{
|
||||||
@@ -301,8 +309,7 @@ namespace Convention
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Static member definition
|
|
||||||
std::string ProjectConfig::ProjectConfigFileFocus = "Assets/";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // Convention_Runtime_GlobalConfig_hpp
|
#endif // Convention_Runtime_GlobalConfig_hpp
|
1
Convention/[Static]
Submodule
1
Convention/[Static]
Submodule
Submodule Convention/[Static] added at 004f2f3367
1
Convention/[nlohmann]
Submodule
1
Convention/[nlohmann]
Submodule
Submodule Convention/[nlohmann] added at d33ecd3f3b
33
README.md
Normal file
33
README.md
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# 前置要求
|
||||||
|
|
||||||
|
- **编译器**: 支持C++17的编译器 (GCC 7+, Clang 5+, MSVC 2017+)
|
||||||
|
- **CMake**: 3.14或更高版本
|
||||||
|
- **Git**: 用于克隆子模块
|
||||||
|
|
||||||
|
# 克隆项目
|
||||||
|
|
||||||
|
由于项目包含Git子模块,请使用以下命令进行完整克隆:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 方法1: 递归克隆(推荐)
|
||||||
|
git clone --recursive https://github.com/your-username/Convention-CPP.git
|
||||||
|
cd Convention-CPP
|
||||||
|
|
||||||
|
# 方法2: 先克隆主项目,再初始化子模块
|
||||||
|
git clone https://github.com/your-username/Convention-CPP.git
|
||||||
|
cd Convention-CPP
|
||||||
|
git submodule update --init --recursive
|
||||||
|
```
|
||||||
|
|
||||||
|
# 更新子模块
|
||||||
|
|
||||||
|
如果子模块有更新,使用以下命令:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 更新所有子模块到最新版本
|
||||||
|
git submodule update --remote
|
||||||
|
|
||||||
|
# 或者更新特定子模块
|
||||||
|
git submodule update --remote Convention/[nlohmann]
|
||||||
|
git submodule update --remote Convention/[Static]
|
||||||
|
```
|
@@ -1,4 +1,5 @@
|
|||||||
add_executable(TEST test.cpp )
|
add_executable(TEST test.cpp )
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/Convention/[Runtime])
|
include_directories(${PROJECT_SOURCE_DIR}/Convention/[Runtime])
|
||||||
|
include_directories(${PROJECT_SOURCE_DIR}/Convention/nlohmann/include)
|
||||||
install(TARGETS TEST
|
install(TARGETS TEST
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
@@ -1,26 +1,28 @@
|
|||||||
//#include"Config.hpp"
|
#include<Config.hpp>
|
||||||
#include"Architecture.hpp"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace Convention;
|
||||||
|
|
||||||
#include <iostream>
|
class A
|
||||||
#include<vector>
|
{
|
||||||
#include<map>
|
public:
|
||||||
using namespace std;
|
virtual void a() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class B
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void b() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class C :public A, protected B
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void c() {}
|
||||||
|
};
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
double t = 0;
|
C c;
|
||||||
for (int i = 1; i < 80; i++)
|
((A)c).a();
|
||||||
{
|
|
||||||
t += 1.0 / (double)i;
|
|
||||||
}
|
|
||||||
double k = 0;
|
|
||||||
for (int i = 1; i < 80; i++)
|
|
||||||
{
|
|
||||||
k += 1.0 / (double)i;
|
|
||||||
cout << i << ":\t" << k << "/" << t << "\t=\t" << k / t * 100 << "% current step:\t" <<
|
|
||||||
1.0 / (double)i << endl;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user