2022-07-31 21:43:26 +08:00
|
|
|
#pragma once
|
|
|
|
#include "core/common.h"
|
2022-08-05 12:50:34 +08:00
|
|
|
#include "ref.h"
|
2022-07-31 21:43:26 +08:00
|
|
|
|
2022-08-07 21:12:17 +08:00
|
|
|
namespace infini {
|
2022-07-31 21:43:26 +08:00
|
|
|
|
|
|
|
using GuidBaseType = int;
|
|
|
|
|
|
|
|
class Guid {
|
|
|
|
private:
|
|
|
|
GuidBaseType guid;
|
|
|
|
|
|
|
|
private:
|
|
|
|
GuidBaseType generateGuid() {
|
|
|
|
static GuidBaseType guidCnt = 0;
|
|
|
|
return ++guidCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
Guid() { guid = generateGuid(); }
|
|
|
|
Guid(const Guid &rhs) { guid = generateGuid(); }
|
|
|
|
Guid &operator=(const Guid &rhs) {
|
|
|
|
guid = generateGuid();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator GuidBaseType() const { return guid; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class Object {
|
|
|
|
protected:
|
|
|
|
Guid guid;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~Object(){};
|
|
|
|
virtual string toString() const = 0;
|
|
|
|
void print() { std::cout << toString() << std::endl; }
|
2022-10-18 22:02:51 +08:00
|
|
|
GuidBaseType getGuid() const { return guid; }
|
2022-07-31 21:43:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
inline std::ostream &operator<<(std::ostream &os, const Object &obj) {
|
|
|
|
os << obj.toString();
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2022-08-05 12:50:34 +08:00
|
|
|
// Overload for Ref-wrapped Object
|
|
|
|
template <typename T,
|
|
|
|
typename std::enable_if_t<std::is_base_of_v<Object, T>> * = nullptr>
|
|
|
|
inline std::ostream &operator<<(std::ostream &os, const Ref<T> &obj) {
|
|
|
|
os << obj->toString();
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2022-08-07 21:12:17 +08:00
|
|
|
} // namespace infini
|