格式整理
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <fstream>
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
|
||||
using wchar = wchar_t;
|
||||
using QWORD = unsigned long long int;
|
||||
@@ -31,7 +31,10 @@ template<typename F> using Function = std::function<F>;
|
||||
#define Success() { return 0; }
|
||||
#define Failed() { return 1; }
|
||||
#define Error() { return -1; }
|
||||
#define Comment(PARAMS) /##/ PARAMS
|
||||
#define SameAs(PARAMS) Comment(PARAMS)
|
||||
|
||||
//NOLINTNEXTLINE(*-reserved-identifier)
|
||||
#define _WINSOCKAPI_ /* 防止winsock.h被引入。winsock.h和winsock2.h冲突。 */
|
||||
#if false
|
||||
#include <WinSock2.h>
|
||||
@@ -45,7 +48,6 @@ template<typename F> using Function = std::function<F>;
|
||||
#include <wingdi.h>
|
||||
#include <WinUser.h>
|
||||
#include <Uxtheme.h>
|
||||
#include <iostream>
|
||||
#include <dwmapi.h>
|
||||
|
||||
#define WM_APP_LBUTTONUP (WM_APP + 1)
|
||||
@@ -76,18 +78,19 @@ concept PointerType = std::is_pointer_v<T>;
|
||||
template<typename T>
|
||||
concept TypeName = NonreferenceType<T> && NonpointerType<T>;
|
||||
|
||||
inline std::wfstream& MainLogFile = *new std::wfstream(L"log.txt", std::ios::out | std::ios::trunc);
|
||||
|
||||
struct MemoryManager {
|
||||
struct MemoryInfo {
|
||||
std::size_t size;
|
||||
const String msg;
|
||||
std::size_t size;
|
||||
};
|
||||
|
||||
Map<void*, MemoryInfo> allocated;
|
||||
Map<void*, MemoryInfo> allocated {};
|
||||
|
||||
constexpr MemoryManager() noexcept = default;
|
||||
} inline memoryManager;
|
||||
|
||||
void requireNonnull(const void* value) noexcept(false);
|
||||
void checkAllocation(const void* value) noexcept(false);
|
||||
inline String ptrtow(QWORD value);
|
||||
|
||||
#if defined __CARLBEKS_DEBUG__ || defined __CARLBEKS_MEMORY__
|
||||
@@ -95,16 +98,16 @@ void printAllocate(void* value, std::size_t size, const String&);
|
||||
void printDeallocate(void* value, std::size_t size, const String&);
|
||||
extern String atow(const char* chars);
|
||||
|
||||
template<typename T> T* _allocatedFor(T* value, const String& msg = L"", std::size_t size = sizeof(T)) {
|
||||
template<typename T> T* allocatedFor$(T* value, const String& msg = L"", std::size_t size = sizeof(T)) {
|
||||
requireNonnull(value);
|
||||
const auto& k = memoryManager.allocated.emplace(value, MemoryManager::MemoryInfo{ size, L"[" + atow(typeid(T).name()) + L"] " + msg }).first;
|
||||
const auto& k = memoryManager.allocated.emplace(value, MemoryManager::MemoryInfo{ L"[" + atow(typeid(T).name()) + L"] " + msg , size}).first;
|
||||
#if __CARLBEKS_MEMORY__ > 1
|
||||
printAllocate(value, k->second.size, k->second.msg);
|
||||
#endif
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename T> T* _deallocating(T* value) {
|
||||
template<typename T> T* deallocating$(T* value) {
|
||||
#if __CARLBEKS_MEMORY__ > 1
|
||||
const MemoryManager::MemoryInfo* info = nullptr;
|
||||
if (memoryManager.allocated.contains(value)) info = &memoryManager.allocated.at(value);
|
||||
@@ -115,11 +118,11 @@ template<typename T> T* _deallocating(T* value) {
|
||||
}
|
||||
|
||||
#if __CARLBEKS_MEMORY__ > 3
|
||||
#define allocatedFor(val, ...) _allocatedFor(val, L"\n From " __FUNCSIG__ "\n At " __FILE__ ":" _STL_STRINGIZE(__LINE__) __VA_OPT__(,) __VA_ARGS__)
|
||||
#define allocatedFor(val, ...) allocatedFor$(val, L"\n From " __FUNCSIG__ "\n At " __FILE__ ":" _STL_STRINGIZE(__LINE__) __VA_OPT__(,) __VA_ARGS__)
|
||||
#else
|
||||
#define allocatedFor(val, ...) _allocatedFor(val, L"" __VA_OPT__(,) __VA_ARGS__)
|
||||
#define allocatedFor(val, ...) allocatedFor$(val, L"" __VA_OPT__(,) __VA_ARGS__)
|
||||
#endif
|
||||
#define deallocating(val) _deallocating(val)
|
||||
#define deallocating(val) deallocating$(val)
|
||||
#else
|
||||
#define allocatedFor(val, ...) val
|
||||
#define deallocating(val) val
|
||||
@@ -137,14 +140,11 @@ public:
|
||||
*/
|
||||
ObjectHolder() : value(nullptr), hasValue(false) {}
|
||||
|
||||
// ReSharper disable once CppNonExplicitConvertingConstructor
|
||||
ObjectHolder(Base* value) : value(value), hasValue(false) {}
|
||||
|
||||
// ReSharper disable once CppNonExplicitConvertingConstructor
|
||||
template<NewCopyable T> requires (std::is_base_of_v<Base, T> || std::is_same_v<Base, T>) && TypeName<T>
|
||||
ObjectHolder(const T& value) : value(allocatedFor(new T(value))), hasValue(true) {}
|
||||
|
||||
// ReSharper disable once CppNonExplicitConvertingConstructor
|
||||
template<NewMoveable T> requires (std::is_base_of_v<Base, T> || std::is_same_v<Base, T>) && TypeName<T>
|
||||
ObjectHolder(T&& value) : value(allocatedFor(new T(std::forward<T>(value)))), hasValue(true) {}
|
||||
|
||||
@@ -196,11 +196,17 @@ public:
|
||||
return *value;
|
||||
}
|
||||
|
||||
// ReSharper disable once CppNonExplicitConversionOperator
|
||||
[[nodiscard]] operator Base*() const noexcept(false) { return value; }
|
||||
Base* ptr() const noexcept { return value; }
|
||||
operator bool() const noexcept { return value; }
|
||||
bool operator!() const noexcept { return value == nullptr; }
|
||||
bool isManager() const noexcept { return hasValue; }
|
||||
[[nodiscard]] bool isManager() const noexcept { return hasValue; }
|
||||
|
||||
template<typename T> ObjectHolder<T> referenceof(const T& other) {
|
||||
ObjectHolder ret{};
|
||||
ret.value = &other;
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
template<TypeName Base> class SynchronizedHolder {
|
||||
|
||||
Reference in New Issue
Block a user