template<class M>
class Cantera::Cabinet< M >
Template for classes to hold pointers to objects.
The Cabinet<M> class maintains a list of pointers to objects of class M (or of subclasses of M). These classes are used by the 'CLib' interface library functions that provide access to Cantera C++ objects from outside C++. To refer to an existing object, the library functions take an integer argument that specifies the location in the pointer list maintained by the appropriate Cabinet<M> instance. The pointer is retrieved from the list by the interface function, the desired method is invoked, and the result returned to the non-C++ calling procedure. By storing the pointers in a Cabinet, there is no need to encode them in a string or integer and pass them out to the non-C++ calling routine, as some other interfacing schemes do.
The Cabinet<M> class can be used to store pointers to arbitrary objects. In most cases, class M is a base class with virtual methods, and the base class versions of the methods throw CanteraError exceptions. The subclasses overload these methods to implement the desired functionality. Class Cabinet<M> stores only the base-class pointers, but since the methods are virtual, the method of the appropriate subclass will be invoked.
As the Cabinet<M> class uses smart pointers, it is set up to allow deleting objects in an inherently safe manner. Method 'del' does the following. If called with n >= 0, it dereferences the object. The original object is only destroyed if the reference is not shared by other objects. In this way, if it is deleted again inadvertently nothing happens, and if an attempt is made to reference the object by its index number, a standard exception is thrown.
The Cabinet<M> class is implemented as a singleton. The constructor is never explicitly called; instead, static function Cabinet<M>::Cabinet() is called to obtain a pointer to the instance. This function calls the constructor on the first call and stores the pointer to this instance. Subsequent calls simply return the already-created pointer.
Definition at line 50 of file Cabinet.h.