FX::Generic::TL::dynamicAt< typelist, instance > Struct Template Reference
[Typelists]

#include <FXGenericTools.h>

Inheritance diagram for FX::Generic::TL::dynamicAt< typelist, instance >:

Inheritance graph
[legend]

List of all members.


Detailed Description

template<typename typelist, template< class > class instance>
struct FX::Generic::TL::dynamicAt< typelist, instance >

Assembles code to call some templated code with the type from a typelist.

This generates at compile-time a jump table within the read-only section of the binary consisting of addresses of the static function instance<type>::Do where type is the type within the typelist from index 0 to the length of the typelist. At run-time the index specified is used to lookup the address of the function and to call it with any set of parameters. This allows you to very efficiently call type specialised code where the type is known only at run time and is a boon for writing modular extensible code which is both type safe and efficient. It also totally removes the bloat associated with sets of if...else statements as there is one routine & table reused by all instances of usage throughout a binary.

If the search does not match (eg; the index is out of range), instance::Do instantiated with NullType is called. Note that like instantiateH parameters are always passed by value.

Usage looks like as follows:

    template<typename type> struct Impl { static void Do(<pars>); }
    Generic::TL::dynamicAt<typelist, Impl>(typeIdx, <pars>);
Note that there is a maximum of 16 entries per jump table as I couldn't figure out how to make it dynamically generated at compile time to any length. If anyone can advise, I'd be most grateful. In the meantime, you can handle > 16 entries by inheriting as many dynamicAt's as you require into a helper class and at construction, invoking those you don't need using the magic idx number which disables execution.

Public Member Functions

 dynamicAt (FXuint idx)
template<typename P1>
 dynamicAt (FXuint idx, P1 p1)
template<typename P1, typename P2>
 dynamicAt (FXuint idx, P1 p1, P2 p2)
template<typename P1, typename P2, typename P3>
 dynamicAt (FXuint idx, P1 p1, P2 p2, P3 p3)
template<typename P1, typename P2, typename P3, typename P4>
 dynamicAt (FXuint idx, P1 p1, P2 p2, P3 p3, P4 p4)

Static Public Attributes

static const FXuint MaxEntries
static const FXuint DisableMagicIdx

Constructor & Destructor Documentation

template<typename typelist, template< class > class instance>
FX::Generic::TL::dynamicAt< typelist, instance >::dynamicAt ( FXuint  idx  )  [inline]

Invoke instance with the type idx in the typelist.

template<typename typelist, template< class > class instance>
template<typename P1>
FX::Generic::TL::dynamicAt< typelist, instance >::dynamicAt ( FXuint  idx,
P1  p1 
) [inline]

Invoke instance with the type idx in the typelist with parameters.


Member Data Documentation

template<typename typelist, template< class > class instance>
const FXuint FX::Generic::TL::dynamicAt< typelist, instance >::MaxEntries [static]

Currently the maximum members permitted in a typelist.

template<typename typelist, template< class > class instance>
const FXuint FX::Generic::TL::dynamicAt< typelist, instance >::DisableMagicIdx [static]

The magic idx value to disable dispatch


The documentation for this struct was generated from the following file:

(C) 2002-2008 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Jun 13 22:30:18 2008 for TnFOX by doxygen v1.5.6