Factory/CCObject.h

43 lines
1.3 KiB
C
Raw Normal View History

2025-12-06 17:11:34 +08:00
#ifndef CC_OBJECT_H
#define CC_OBJECT_H
#pragma once
#include <functional>
#include <string>
#include <memory>
#include "mutex"
#include "CCClassFactoryInfo.h"
namespace CTL {
class Object {
inline static std::mutex Mutex_Object;
std::string MemoryID;
public:
private:
public:
Object() = default;
virtual ~Object() = default; // 虚析构函数确保正确析构
// 比较两个对象是否逻辑相等(默认实现为地址比较)
virtual bool equals(const Object* other);
// 生成基于对象地址的哈希值
[[nodiscard]] virtual size_t hashCode() const noexcept;
// 返回对象的字符串表示(默认格式:类名@地址)
[[nodiscard]] virtual std::string toString() const;
friend std::ostream& operator<<(std::ostream& os, const Object& map);
template<typename T = Object, typename... Args>
static std::shared_ptr<T> create(Args&&... args) {
return std::make_shared<T>(std::forward<Args>(args)...);
}
int get_info_count();
ClassFactoryInfo* get_info(int pos);
ClassFactoryInfo* get_info(const std::string& infoName);
template<typename T>
T get(const std::string& infoName);
template<typename T>
void set(const std::string& infoName, T value);
};
}
#endif