2025-01-12 16:18:03 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "metadata.h"
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
// Struct describing information about an instance
|
|
|
|
struct InstanceType {
|
|
|
|
InstanceType* super; // May be null
|
|
|
|
std::string className;
|
|
|
|
InstanceConstructor constructor;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Base class for all instances in the data model
|
|
|
|
class Instance : std::enable_shared_from_this<Instance> {
|
|
|
|
private:
|
|
|
|
std::optional<std::weak_ptr<Instance>> parent;
|
|
|
|
std::vector<std::shared_ptr<Instance>> children;
|
2025-01-12 17:38:23 +00:00
|
|
|
protected:
|
|
|
|
Instance(InstanceType*);
|
|
|
|
virtual ~Instance();
|
2025-01-12 16:18:03 +00:00
|
|
|
public:
|
|
|
|
static InstanceType* TYPE;
|
|
|
|
std::string name;
|
|
|
|
|
2025-01-12 17:38:23 +00:00
|
|
|
// Instance is abstract, so it should not implement GetClass directly
|
|
|
|
virtual InstanceType* GetClass() = 0;
|
2025-01-12 16:18:03 +00:00
|
|
|
void SetParent(std::optional<std::shared_ptr<Instance>> newParent);
|
|
|
|
std::optional<std::shared_ptr<Instance>> GetParent();
|
|
|
|
inline const std::vector<std::shared_ptr<Instance>> GetChildren() { return children; }
|
2025-01-17 08:24:18 +00:00
|
|
|
|
|
|
|
// Utility functions
|
|
|
|
inline void AddChild(std::shared_ptr<Instance> object) { children.push_back(object); }
|
2025-01-12 16:18:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::shared_ptr<Instance> InstanceRef;
|
|
|
|
typedef std::weak_ptr<Instance> InstanceRefWeak;
|