mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-14 00:55:20 +02:00
Allow ObjDefManager instances to be cloned
This commit is contained in:
18
src/objdef.h
18
src/objdef.h
@@ -45,10 +45,22 @@ class ObjDef {
|
||||
public:
|
||||
virtual ~ObjDef() = default;
|
||||
|
||||
// Only implemented by child classes (leafs in class hierarchy)
|
||||
// Should create new object of its own type, call cloneTo() of parent class
|
||||
// and copy its own instance variables over
|
||||
virtual ObjDef *clone() const = 0;
|
||||
|
||||
u32 index;
|
||||
u32 uid;
|
||||
ObjDefHandle handle;
|
||||
std::string name;
|
||||
|
||||
protected:
|
||||
// Only implemented by classes that have children themselves
|
||||
// by copying the defintion and changing that argument type (!!!)
|
||||
// Should defer to parent class cloneTo() if applicable and then copy
|
||||
// over its own properties
|
||||
void cloneTo(ObjDef *def) const;
|
||||
};
|
||||
|
||||
// WARNING: Ownership of ObjDefs is transferred to the ObjDefManager it is
|
||||
@@ -60,6 +72,8 @@ public:
|
||||
virtual ~ObjDefManager();
|
||||
DISABLE_CLASS_COPY(ObjDefManager);
|
||||
|
||||
// T *clone() const; // implemented in child class with correct type
|
||||
|
||||
virtual const char *getObjectTitle() const { return "ObjDef"; }
|
||||
|
||||
virtual void clear();
|
||||
@@ -88,6 +102,10 @@ public:
|
||||
ObjDefType *type, u32 *uid);
|
||||
|
||||
protected:
|
||||
ObjDefManager() {};
|
||||
// Helper for child classes to implement clone()
|
||||
void cloneTo(ObjDefManager *mgr) const;
|
||||
|
||||
const NodeDefManager *m_ndef;
|
||||
std::vector<ObjDef *> m_objects;
|
||||
ObjDefType m_objtype;
|
||||
|
Reference in New Issue
Block a user