Boost logo

Boost :

From: Jesse Jones (jesjones_at_[hidden])
Date: 2001-04-16 21:11:37

>bool entering_object(const void* thisPtr);
>void leaving_object(const void* thisPtr);
>template <class T>
>void invoke_invariant(const void* thisPtr)
>{static_cast<const T*>(thisPtr)->invariant();}
>class check_invariant {
> ~check_invariant()
>{leaving_object(mThisPtr); if (mInvoker) mInvoker(mThisPtr);}
> template <class T>
> check_invariant(const T* thisPtr) : mThisPtr(thisPtr)
>{mInvoker = nil; if (entering_object(mThisPtr))
> mInvoker = invoke_invariant<T>;}
> void (*mInvoker)(const void*);
> const void* mThisPtr;

I went ahead and implemented something close to this and it seems to
work OK. The only real changes I made were to use a member function
pointer in invoke_invariant() to allow for protected or private
invariants and adding a call to the invoker in the check_invariant
ctor that somehow dropped out in one of my edits.

   -- Jesse

Boost list run by bdawes at, gregod at, cpdaniel at, john at