Compare commits

...

10 Commits

Author SHA1 Message Date
5c3b7c4b1b 新增依赖 2025-08-21 15:49:05 +08:00
a34ad88277 新增主项目检查机制 2025-08-01 09:48:32 +08:00
3147098f71 恢复了nlohmann 2025-07-31 23:17:22 +08:00
4ab5c2378a 更新关于nlohmann的依赖 2025-07-29 11:01:54 +08:00
e87627dec9 Update Config.hpp 2025-07-28 16:04:05 +08:00
6484071f40 GlobalConfig中的静态变量变为可选extern 2025-07-28 12:01:37 +08:00
9d1bc4c0e0 修改了一些格式问题 2025-07-27 01:01:05 +08:00
407de7999c 修复了一些问题 2025-07-26 23:23:49 +08:00
6c0b82861d BS 0.1.0 将json依赖添加 2025-07-16 15:56:54 +08:00
ff039f1918 BS 0.1.0 Architecture.UpdateTimeline无法一次更新彻底的错误 2025-07-16 14:57:44 +08:00
12 changed files with 214 additions and 96 deletions

6
.gitmodules vendored Normal file
View 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

View File

@@ -1,5 +1,14 @@
# 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: --- ----- ----- ----- ----- --")
else()
message("Convention: --- ----- ----- ----- ----- --")
endif()
add_compile_definitions(__PLATFORM_NAME="${PLATFORM_NAME}")
add_compile_definitions(__PLATFORM_VERSION="${PLATFORM_VERSION}")
@@ -15,8 +24,9 @@ set(CMAKE_CXX_STANDARD 17)
set(C_STANDARD 11)
# Enable 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
if (POLICY CMP0141)
@@ -28,13 +38,15 @@ cmake_policy(SET CMP0076 NEW)
# Message Platfrom
message("Root: ${PLATFORM_NAME}-${PLATFORM_VERSION}-${PLATFORM_EXTENSION}")
if(MAIN_PROJECT)
message("Root: ${PLATFORM_NAME}-${PLATFORM_VERSION}-${PLATFORM_EXTENSION}")
endif()
# Threads Enable
add_compile_definitions(_PTHREADS)
# Project
project("Convention-All")
project("Convention")
# 设置构建共享库
set(BUILD_SHARED_LIBS ON)
@@ -55,10 +67,16 @@ endif()
# Project
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_FLAGS = ${CMAKE_CXX_FLAGS}")
message("Root: CMAKE_CXX_COMPILER_VERSION = ${CMAKE_CXX_COMPILER_VERSION}")
message("Root: ----- ----- ----- ----- -----")
message("Root: ----- ----- ----- ----- -----")
else()
message("Convention: ----- ----- ----- ----- -----")
endif()

View File

@@ -1,5 +1,6 @@
message("Convention: --- ----- ----- ----- ----- --")
include_directories(${PROJECT_SOURCE_DIR}/Convention/nlohmann/include)
install(DIRECTORY [Runtime]
DESTINATION ${CMAKE_INSTALL_PREFIX}/include
FILES_MATCHING PATTERN "*.*"

View File

@@ -381,15 +381,20 @@ namespace Convention
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++;
}
}
}

View File

@@ -267,9 +267,9 @@ constexpr int ConstexprStrCompare(
#define __PLATFORM_VERSION "Unknown"
#endif // __PLATFORM_VERSION
#ifndef PLATFORM_EXTENSION
#define PLATFORM_EXTENSION ""
#endif // PLATFORM_EXTENSION
#ifndef __PLATFORM_EXTENSION
#define __PLATFORM_EXTENSION ""
#endif // __PLATFORM_EXTENSION
struct PlatformIndicator
: public
@@ -328,7 +328,6 @@ struct PlatformIndicator
constexpr static bool IsGNUC = false;
#endif // __GNUC__
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
static int KeyboardInput() noexcept;
@@ -1394,7 +1393,9 @@ struct StringIndicator
static str ToString(const T& value)
{
if_exists(T::ToString)
{
return value.ToString();
}
if constexpr (std::is_constructible_v<const T&, str>)
return value;
else if constexpr (std::is_same_v<str, std::wstring>)
@@ -1722,7 +1723,7 @@ namespace Convention
if constexpr (index == 0)
return sizeof(Element);
else
return sizeof(Element) + _MyNext::ElementOffset<index - 1>();
return sizeof(Element) + _MyNext:: template ElementOffset<index - 1>();
}
template<size_t index>
decltype(auto) GetValue() const noexcept
@@ -1800,6 +1801,11 @@ namespace Convention
public:
constexpr static size_t size = 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 _UniquePtr = UniquePtr<T, DefaultDelete<T, Allocator>>;
using _Mybase = std::conditional_t<IsUnique, _UniquePtr, _SharedPtr>;
using _MyAlloc = Allocator<T>;
private:
/**
* @brief 获取内存管理器
@@ -1885,13 +1892,19 @@ namespace Convention
{
T* ptr = GetStaticMyAllocator().allocate(1);
GetStaticMyAllocator().construct(ptr, std::forward<Args>(args)...);
return ptr
return ptr;
}
static void _DestoryMyPtr(_In_ T* ptr)
{
GetStaticMyAllocator().destroy(ptr);
GetStaticMyAllocator().deallocate(ptr, 1);
}
protected:
template<typename... Args>
static T* ConstructMyPtr(Args&&... args)
{
return BuildMyPtr(std::forward<Args>(args)...);
}
public:
/**
* @brief 任意匹配的构造函数
@@ -1952,7 +1965,8 @@ namespace Convention
/**
* @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)
{
@@ -1965,6 +1979,21 @@ namespace Convention
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 移动赋值函数
*/
virtual instance& operator=(instance&& value) noexcept

View File

@@ -10,13 +10,25 @@ namespace Convention
{
private:
std::filesystem::path FullPath;
mutable std::fstream OriginControlStream;
mutable bool StreamOpen = false;
//mutable std::fstream OriginControlStream;
//mutable bool StreamOpen = false;
public:
explicit ToolFile(const std::filesystem::path& path) : FullPath(path) {}
explicit ToolFile(const std::string& path) : FullPath(path) {}
explicit ToolFile(const char* path) : FullPath(path) {}
ToolFile(const std::filesystem::path& path) : FullPath(path) {}
ToolFile(const std::string& 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
operator std::string() const { return FullPath.string(); }
@@ -85,20 +97,21 @@ namespace Convention
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();
OriginControlStream.open(FullPath, mode);
StreamOpen = OriginControlStream.is_open();
return *this;
}
}*/
ToolFile& Close()
{
if (StreamOpen) {
/*if (StreamOpen)
{
OriginControlStream.close();
StreamOpen = false;
}
}*/
return *this;
}
@@ -154,7 +167,8 @@ namespace Convention
ToolFile& MustExistsPath()
{
auto parent = FullPath.parent_path();
if (!parent.empty() && !std::filesystem::exists(parent)) {
if (!parent.empty() && !std::filesystem::exists(parent))
{
std::filesystem::create_directories(parent);
}
return *this;
@@ -320,4 +334,4 @@ namespace Convention
};
}
#endif // Convention_Runtime_File_hpp
#endif // Convention_Runtime_File_hpp

View File

@@ -11,19 +11,17 @@ namespace Convention
class GlobalConfig
{
public:
static std::string ConstConfigFile;
constexpr static auto ConstConfigFile = "config.json";
static void InitExtensionEnv()
{
ConstConfigFile = "config.json";
ProjectConfig::InitExtensionEnv();
}
static void GenerateEmptyConfigJson(ToolFile& file)
{
nlohmann::json config;
config["properties"] = nlohmann::json::object();
file.Open(std::ios::out | std::ios::trunc);
file.SaveAsText(config.dump(4));
file.Close();
}
@@ -54,9 +52,12 @@ namespace Convention
// Build up init data file
auto configFile = GetConfigFile();
if (!configFile.Exists()) {
if (!configFile.Exists())
{
GenerateEmptyConfigJson(configFile);
} else if (isLoad) {
}
else if (isLoad)
{
LoadProperties();
}
}
@@ -69,7 +70,8 @@ namespace Convention
ToolFile GetFile(const std::string& path, bool isMustExist = false)
{
auto file = DataDir | path;
if (isMustExist) {
if (isMustExist)
{
file.MustExistsPath();
}
return file;
@@ -78,13 +80,16 @@ namespace Convention
bool EraseFile(const std::string& path)
{
auto file = DataDir | path;
if (file.Exists()) {
try {
file.Open(std::ios::out | std::ios::trunc);
file.Close();
return true;
} catch (...) {}
}
if (file.Exists())
{
file.MustExistsPath();
if (file.IsFile())
{
file.Remove();
file.Create();
}
return true;
}
return false;
}
@@ -164,22 +169,32 @@ namespace Convention
GlobalConfig& LoadProperties()
{
auto configFile = GetConfigFile();
if (!configFile.Exists()) {
if (!configFile.Exists())
{
data_pair.clear();
} else {
try {
}
else
{
try
{
auto content = configFile.LoadAsText();
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();
for (auto& [key, value] : config["properties"].items()) {
for (auto& [key, value] : config["properties"].items())
{
data_pair[key] = value;
}
} else {
}
else
{
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()));
}
}
@@ -209,7 +224,7 @@ namespace Convention
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());
@@ -238,7 +253,7 @@ namespace Convention
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;
if (!defaultValue.empty()) {
@@ -247,7 +262,7 @@ namespace Convention
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);
}
@@ -258,42 +273,35 @@ namespace Convention
}
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);
if (it != data_pair.end()) {
try {
if (it != data_pair.end())
{
try
{
return it->second.get<T>();
} catch (const nlohmann::json::exception&) {
LogPropertyNotFound("Cannot convert value for key: " + key);
}
} else {
LogPropertyNotFound("Key not found: " + key);
catch (const nlohmann::json::exception&)
{
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;
}
};
// Static member definition
std::string GlobalConfig::ConstConfigFile = "config.json";
class ProjectConfig : public GlobalConfig
{
private:
static std::string ProjectConfigFileFocus;
constexpr static auto ProjectConfigFileFocus = "Assets/";
public:
static void InitExtensionEnv()
{
ProjectConfigFileFocus = "Assets/";
}
ProjectConfig(bool isLoad = true) : GlobalConfig(ProjectConfigFileFocus, true, isLoad) {}
static void SetProjectConfigFileFocus(const std::string& path)
{
ProjectConfigFileFocus = path;
}
ProjectConfig(bool isLoad = true) : GlobalConfig(ToolFile(ProjectConfigFileFocus), true, isLoad) {}
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

Submodule Convention/[Static] added at 004f2f3367

1
Convention/[nlohmann] Submodule

Submodule Convention/[nlohmann] added at d33ecd3f3b

33
README.md Normal file
View 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]
```

View File

@@ -1,4 +1,5 @@
add_executable(TEST test.cpp )
include_directories(${PROJECT_SOURCE_DIR}/Convention/[Runtime])
include_directories(${PROJECT_SOURCE_DIR}/Convention/nlohmann/include)
install(TARGETS TEST
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)

View File

@@ -1,26 +1,28 @@
//#include"Config.hpp"
#include"Architecture.hpp"
#include<Config.hpp>
using namespace std;
using namespace Convention;
#include <iostream>
#include<vector>
#include<map>
using namespace std;
class A
{
public:
virtual void a() {}
};
class B
{
public:
virtual void b() {}
};
class C :public A, protected B
{
public:
virtual void c() {}
};
int main()
{
double t = 0;
for (int i = 1; i < 80; i++)
{
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;
C c;
((A)c).a();
}