MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / IObjectRef

Class IObjectRef

source/script.h:1448–1484  ·  view source on GitHub ↗

IObjectPtr with automatic reference-counting, for storing an object safely, such as in a HotkeyVariant, UserMenuItem, etc. Its specific purpose is to work with old code that wasn't concerned with reference counting.

Source from the content-addressed store, hash-verified

1446// such as in a HotkeyVariant, UserMenuItem, etc. Its specific purpose is to
1447// work with old code that wasn't concerned with reference counting.
1448class IObjectRef : public IObjectPtr
1449{
1450private:
1451 IObjectRef(const IObjectRef &); // Disable default copy constructor.
1452 IObjectRef & operator = (const IObjectRef &); // ...and copy assignment.
1453
1454public:
1455 IObjectRef() : IObjectPtr() {}
1456 IObjectRef(IObject *object) : IObjectPtr(object)
1457 {
1458 if (object)
1459 object->AddRef();
1460 }
1461 IObjectRef(const IObjectPtr &other) : IObjectPtr(other)
1462 {
1463 if (mObject)
1464 mObject->AddRef();
1465 }
1466 IObjectRef & operator = (IObject *object)
1467 {
1468 if (object)
1469 object->AddRef();
1470 if (mObject)
1471 mObject->Release();
1472 mObject = object;
1473 return *this;
1474 }
1475 IObjectRef & operator = (const IObjectPtr &other)
1476 {
1477 return *this = other.ToObject();
1478 }
1479 ~IObjectRef()
1480 {
1481 if (mObject)
1482 mObject->Release();
1483 }
1484};
1485
1486
1487

Callers

nothing calls this directly

Calls 3

AddRefMethod · 0.45
ReleaseMethod · 0.45
ToObjectMethod · 0.45

Tested by

no test coverage detected