git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8545 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris committed 2008-05-23 20:56:24 +00:00
1 parent d2290cfa3a
commit 00654d880e
338 files changed
+55722 -19397

No files matched your search

+58 -12
View File
@@ -64,6 +64,22 @@ autoObjectPtr::autoObjectPtr() : objectP(NULL) {}
autoObjectPtr::autoObjectPtr(autoObject * const objectP) {
// Note: When someone attempts to use this constructor with a null
// argument, it's normally because a 'new' of the autoObject
// failed, before calling the autoObject's constructor, thus
// generating a null pointer.
// E.g. the following code, where the system is out of memory:
//
// class client : public autoObject { ... }
// class clientPtr : public autoObjectPtr { ... }
// clientPtr clientP(new client);
if (objectP == NULL)
throw(error("Object creation failed; trying to create autoObjectPtr "
"with a null autoObject pointer"));
this->objectP = objectP;
objectP->incref();
}
@@ -81,33 +97,54 @@ autoObjectPtr::autoObjectPtr(autoObjectPtr const& autoObjectPtr) {
autoObjectPtr::~autoObjectPtr() {
if (this->objectP) {
bool dead;
this->objectP->decref(&dead);
if (dead)
delete(this->objectP);
}
this->unpoint();
}
void
autoObjectPtr::instantiate(autoObject * const objectP) {
autoObjectPtr::point(autoObject * const objectP) {
if (this->objectP != NULL)
throw(error("Already pointing"));
this->objectP = objectP;
objectP->incref();
}
void
autoObjectPtr::unpoint() {
if (this->objectP) {
bool dead;
this->objectP->decref(&dead);
if (dead) {
delete(this->objectP);
this->objectP = NULL;
}
}
}
autoObjectPtr
autoObjectPtr::operator=(autoObjectPtr const& autoObjectPtr) {
autoObjectPtr::operator=(autoObjectPtr const& source) {
if (this->objectP != NULL)
throw(error("Already instantiated"));
this->objectP = autoObjectPtr.objectP;
this->objectP->incref();
// If we're overwriting a variable that already points to something,
// we have to unpoint it from what it points to now before we can point
// it to what 'source' points to. But if the source and destination
// are the same object, we just want to leave the pointing alone.
if (this == &source) {
// Assignment of variable to itself; no-op
} else {
this->unpoint();
this->objectP = source.objectP;
if (this->objectP)
this->objectP->incref();
}
return *this;
}
@@ -115,9 +152,18 @@ autoObjectPtr::operator=(autoObjectPtr const& autoObjectPtr) {
autoObject *
autoObjectPtr::operator->() const {
if (this->objectP == NULL)
throw(error("attempt to dereference autoObjectPtr "
"which does not point to anything"));
return this->objectP;
}
autoObject *
autoObjectPtr::get() const {
return this->objectP;
}
} // namespace