Scopira
20080306
|
The base object class is scopira::tool::object. This is the base class for all classes that want to be:
You should almost always inherit from this class virtually. That is:
Each object descendant, during debug builds exposes an scopira::tool::object::is_alive_object method that returns true if the given object is non-null and valid (not destroyed) and matches an internal magic number. This is useful in catching many bad-memory manipulation errors.
Also while in debug builds, Scopira will notify the user on exit if there are any non-deleted scopira::tool::object decendants in memory. This greatly helps in detecting memory leaks.
Reference counting is the core memory managment style of most Scopira objects in a Scopira application.
All scopira::tool::object decendant instances can be reference counted, but need not be (ie. they can still be created on the stack, etc). However, once an object is reference counted by atleast one counter, that instance now must be reference counted until its destruction. Reference counted objects may be shared by multiple reference counters. When the last counter releases their count, the object is destroyed.
scopira::tool::count_ptr is the basic "smart pointer" template class for handling reference counts. This smart pointer provides all the usual pointer like methods, but makes sure to keep a reference count on the object they contain.
Some sample code:
All scopira::tool::object descendants can be reference counted by scopira::tool::count_ptr by simply proving your own add_ref() and sub_ref() methods. This is typically only done in the most sepecialized of cases, however.
To make your own objects serialization, see Object I/O