Owner

Basic owner object class. When you delete it, all owned object are automatically deleted

Constructors

this
this(Owner owner)

Constructor. owner can be null, in this case object won't have an owner. Such objects are called root owners and should be deleted manually.

Destructor

~this
~this()

Destructor

Members

Functions

addOwnedObject
void addOwnedObject(Owned obj)

Add owned object. Usually you don't have to do it explicitly, just pass the owner to constructor

clearOwnedObjects
void clearOwnedObjects()

Delete owned object without deleting object itself

deleteOwnedObject
void deleteOwnedObject(Owned obj)

Delete particular owned object, if it is there

Variables

ownedObjects
Array!Owned ownedObjects;
Undocumented in source.

Examples

class Test: Owner
{
    string name;
    static bool[string] available;

    this(string name, Owner o = null)
    {
        super(o);
        this.name = name;
        available[name] = true;
    }

    ~this()
    {
        available[name] = false;
    }
}

Test obj1 = New!Test("obj1", null);
Test obj2 = New!Test("obj2", obj1);
Test obj3 = New!Test("obj3", obj2);
obj2.deleteOwnedObject(obj3);
assert(!Test.available["obj3"]);
Delete(obj1);
assert(!Test.available["obj2"]);
assert(!Test.available["obj1"]);

Meta