修复了一些问题

This commit is contained in:
2025-07-26 23:23:49 +08:00
parent 6c0b82861d
commit 407de7999c
3 changed files with 48 additions and 24 deletions

View File

@@ -1394,7 +1394,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>)
@@ -1800,6 +1802,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 +1878,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,7 +1893,7 @@ 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)
{ {

View File

@@ -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;

View File

@@ -16,14 +16,12 @@ namespace Convention
static void InitExtensionEnv() static void InitExtensionEnv()
{ {
ConstConfigFile = "config.json"; 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();
} }
@@ -69,7 +67,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 +77,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;
} }
@@ -209,7 +211,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());