lifecycle.h revision 738d7f16efb5ce2f9529f05af975af160d0ea31b
/** \file
* Inkscape::Lifecycle - automatic object lifecycle management
*
* Copyright 2008 MenTaLguY <mental@rydia.net>
*
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* See the file COPYING for details.
*
*/
#ifndef SEEN_INKSCAPE_LIFECYCLE_H
#define SEEN_INKSCAPE_LIFECYCLE_H
// Abstract base class for managed objects
AbstractManaged() {}
virtual ~AbstractManaged() {}
virtual void managedAddReference() const=0;
virtual void managedRemoveReference() const=0;
};
// Base class for managed pointers; not intended for direct use
}
}
if (managed) {
}
if (ptr) {
}
}
AbstractManaged const *ptr;
};
// Type-safe managed pointer
ManagedPtr() : BaseManagedPtr() {}
operator T *() const { return get_recast(); }
T &operator*() const { return *get_recast(); }
T *operator->() const { return get_recast(); }
return *this;
}
return *this;
}
T *get_recast() const {
}
};
// Dummy implementation of AbstractManaged to ease migration
virtual void managedAddReference() const {}
virtual void managedRemoveReference() const {}
};
// Straightforward refcounting implementation of AbstractManaged
SimpleManaged() : refcount(0) {}
virtual ~SimpleManaged() {}
virtual void managedAddReference() const {
}
virtual void managedRemoveReference() const {
if (g_atomic_int_dec_and_test(&refcount)) {
}
}
virtual void managedDispose() {
}
};
}
}
#endif
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :