SO
( template )
Package: INCLUDE
Include: base/sharedobj.h
Smart Pointer for Shareable Objects
Methods:
-
- SO
- SO() { obj_ = NULL; }
- SO(const SO& so) {
- obj_ = so.obj_;
- SharedObj::ref((const SharedObj*) obj_); // Tobias: typecast
- }
- SO(T* o) { obj_ = o; SharedObj::ref((const SharedObj*) obj_); } // Tobias: typecast
- ~SO() { SharedObj::unref((const SharedObj*)obj_); } // Tobias: typecast
- SO represents a pointer to an object of type T.
- The object is referenced if the pointer is constructed.
- The object is dereferenced if the pointer is destructed.
- The default constructor sets the pointer to null. If a
- shareable object is given, it is stored and referenced.
- operator=
SO& operator=(T* t) {
SharedObj::ref((const SharedObj*)t); SharedObj::unref((const SharedObj*)obj_); obj_ = t; // Tobias: typecasts
return *this;
}
SO& operator=(const SO& vrs) {
SharedObj::ref((const SharedObj*)vrs.obj_); SharedObj::unref((const SharedObj*)obj_); obj_ = vrs.obj_; // Tobias: typecast
return *this;
}
If a shared object is assigned, the current object is dereferenced,
and the assign object is referenced.
- operator==, operator!=
int operator==(const T* t) const { return obj_==t; }
int operator!=(const T* t) const { return obj_!=t; }
Comparison.
- operator->
T* operator->() { return obj_; }
const T* operator->() const { return obj_; }
operator T* () const { return obj_; }
SO objects can convert to constant references and to non-constant
references of the shared object they store. Implicit conversion
to the type of the shared object is provided.
AutoDOC 2.0:
Created on luxemburg, Wed Jul 2 11:58:46 MET DST 1997