I've been trying to use MPL to create a system on an embedded platform
(where memory is at a premium and dynamic allocations are expensive)
that allows for multiple components or properties to be combined into a
single object at both compile and run-time.
The basic idea is, say I have the following properties for a 3D model
(each its own independent class; there are more than the examples I list
here):
ModelBase
Configuration
JointAnimation
TextureAnimation
LightingConfig
I know that a box doesn't need JointAnimation, so when I instantiate a
Model for it I'd like it to not have that "property".
(I could easily accomplish all of this using a std::map and a dynamic
allocation for each property, but again, it's prohibitive on the
platform and I'd rather use metaprogramming if I can.)
So what I'd like to do, in theory, is something like:
// Declare a generic class for a property-based object that templates
off of the set of properties it can contain
template<class PropertiesSet>
class ObjectWithProperties
{
public:
// Create an instance of ObjectWithProperties, using some subset of
PropertiesSet
template<class PropertiesSubset>
static ObjectWithProperties *create();
// Attempt to retrieve a Property, return null on failure
template<class PropertyType>
PropertyType *getProperty();
private:
SomeStaticListManager< size<PropertiesSet>::value >
which_properties_are_used;
void *data_buffer_for_properties;
};
// Define the set of properties that a model can consist of
typedef set