text
stringlengths
0
2.2M
public:
// CREATORS
explicit my_Pool(int *counter) : d_counter_p(counter) {}
// Create this object holding the specified (global) counter.
// MANIPULATORS
void deallocate(void *) { ++*d_counter_p; }
// Increment this object's counter.
};
class my_Class {
// This object indicates that its destructor is called by incrementing the
// global counter (supplied at construction) that it holds.
// DATA
int *d_counter_p; // (global) counter to be incremented at destruction
public:
// CREATORS
explicit my_Class(int *counter) : d_counter_p(counter) {}
// Create this object using the address of the specified 'counter' to
// be held.
~my_Class() { ++*d_counter_p; }
// Destroy this object and increment this object's (global) counter.
};
// Testing Single Inheritance
class myParent {
int x;
public:
myParent() {}
virtual ~myParent() {}
};
class myChild : public myParent {
my_Class c;
public:
explicit myChild(int *counter = 0) : c(counter) {}
~myChild() {}
};
// Testing Multiple Inheritance
class myVirtualBase {
int x;
public:
myVirtualBase() { }
virtual ~myVirtualBase() { }
};
class myLeftBase : virtual public myVirtualBase {
int x;
public:
myLeftBase() { }
virtual ~myLeftBase() { }
};
class myRightBase : virtual public myVirtualBase {
int x;
public:
myRightBase() { }
virtual ~myRightBase() { }
};
class myMostDerived : public myLeftBase, public myRightBase {
my_Class c;
public:
explicit myMostDerived(int *counter = 0) : c(counter) {}
~myMostDerived() {}
};
//=============================================================================
// USAGE EXAMPLE
//-----------------------------------------------------------------------------
// 'bslma::RawDeleterProctor' is normally used to achieve *exception* *safety*
// in an *exception* *neutral* way by managing objects that are created
// temporarily on the heap, but not yet committed to a container object's
// management. This (somewhat contrived) example illustrates the use of a
// 'bslma::RawDeleterProctor' to manage a dynamically-allocated object,
// deleting the object automatically should an exception occur.
//
// Suppose we have a simple linked list class that manages objects of
// parameterized 'TYPE', but which are (for the purpose of this example)
// allocated separately from the links that hold them (thereby requiring two
// separate allocations for each 'append' operation):
//..
// my_list.h
// ...
template <class TYPE>
class my_List {
// This class is a container that uses a linked list data structure to
// manage objects of parameterized 'TYPE'.
// PRIVATE TYPES
struct Link {
TYPE *d_object_p; // object held by the link
Link *d_next_p; // next link
};