InnerClasses.h

// InnerClasses.h
//
// Author David Barrett-Lennard
// (C)opyright Cedanet Pty Ltd 2008

#include <stddef.h>

namespace ceda
{

///////////////////////////////////////////////////////////////////////////////////////////////////
// mDefineOuterClassDelegator

/*
Provides a poor man's support for embedded inner classes.  The following simple example shows 
how it is used.

    $class Parent
    {
        void bar();
            
        // An embedded inner class
        class Inner
        {
            mDefineOuterClassDelegator($$,m_inner)
            void foo()
            {
                // OuterClass() returns a Parent&
                OuterClass().bar();
            }
        } m_inner;
    };

Note that the nested class has access to the private members of the containing class!  See

    http://msdn.microsoft.com/en-us/library/aa712788(VS.71).aspx

*/

@def mDefineOuterClassDelegator(parentClass, innerClassMember) =
{
    parentClass& OuterClass()
    {
        return * (parentClass*) ((ceda::octet_t*) this - offsetof(parentClass,innerClassMember));
    }
    const parentClass& OuterClass() const
    {
        return * (parentClass*) ((ceda::octet_t*) this - offsetof(parentClass,innerClassMember));
    }
}

}