|
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 {
>public:
> ~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>;}
>private:
> 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 acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk