This class is intended for safe manipulation of supported classes in terms of their time frame.
More...
template<class T>
class artec::sdk::base::TRef< T >
This class is intended for safe manipulation of supported classes in terms of their time frame.
Those classes should implement IRef interface that provides reference counting support. TRef objects should hold pointers to the instances of such classes. Below is an example of how to create an instance of an IFrameMesh implementation: TRef<IFrameMesh> mesh; createFrameMesh( &mesh ); Operator &() is overloaded so that the createFrameMesh() function can fill the passed TRef with a newly created instance. At the very moment of definition TRef object has a count of references equal to 1.
TRef instance represents a smart pointer paradigm, so the ->() operator is also overloaded in order for the object to be used as a normal pointer: bool isTextured = mesh->isTextured();
TRef can also be used as a deletion controller: { TRef<IFrameMesh> mesh; createFrameMesh( &mesh ); bool isTextured = mesh->isTextured(); } At this point, the TRef object is to be deleted. This will causes deletion of the FrameMesh instance, once the number of references counts downs to 0.
Note that all objects in the API should be created using the appropriate createXXX() functions. So, in order to use this technique, one should create an IRef implementation and the createXXX() function as it is not permitted to use clauses like the following one: TRef<IMyObject> mine( new MyObject ); This leads to memory leak as the count of references will equal 2 (1 from the object constructor and 1 from the TRef constructor. If you need to initialize TRef directly, do it as follows: TRef<IMyObject> object; object.attach( new MyObject() );
- Examples:
- parallel-capture-sample.cpp, project-sample.cpp, scanning-and-process-sample.cpp, and simple-capture-sample.cpp.
Definition at line 59 of file TRef.h.