Distribution_Service/CC_SDK/Include/basic/CCObject.h

37 lines
1.0 KiB
C
Raw Normal View History

2025-11-11 17:46:19 +08:00
#ifndef CC_OBJECT_H
#define CC_OBJECT_H
#pragma once
#include <functional>
#include <string>
#include <memory>
#include <cstdlib>
#include "map"
#include "mutex"
namespace CTL {
class Object {
inline static std::mutex Mutex_Object;
std::string MemoryID;
public:
private:
public:
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)...);
}
};
}
#endif