An Holder instance drives the life-cycle of the object it holds. They allow to make objects obtained through pointers as if they were automatic variables.
To call a method 'hello' on the held object, either use the holder 'myHolder' as if it was a pointer to the held object: 'myHolder->hello(...)' or use 'myHolder.get().hello()', at your convenience.
- Somewhat mimics the behaviour of a shared pointer (with the '->' operator instead of the '.' one, which cannot be be overriden.
- See also:
- Ceylan::CeylanCountedPointer for a far more complex shared pointer template.
Holder<File> myFileHolder( File::Create(...) ) ; myFileHolder->lockForReading() ; As soon as the automatic variable myFileHolder goes out of scope (ex: return or throw statement), it will be deleted and its held content (here, a File instance ) will be deleted too. Thus the file reference can be manipulated here as easily as if it was an automatic variable, thanks to the Holder template.
- No CEYLAN_DLL declaration for templates.