Apologies if the title of ths thread isnt actually what im looking for.. its the best i could do to describie it in 3 words..
Basically i have a system that i want to make reusable across multiple projects. Part of that system allows users to query / access functionlity based on certain 'types' or 'categories' managed by the system, the types being determined by the needs of this particular project.
As a complete example.. (so dont look too much into the specifics of these types its purely for demonstration!) imagine that this system offered query functionality based on general 'entity categories'. So a user could query for data regarding 'hostile' / 'friendly' / 'neutral' entities.
Now in a single non-reusable system... the simple way would be to provide an enum within the sytem e.g.
enum E_EntityCategory{ E_EntityCategory_None = -1, E_EntityCategory_Hostile, E_EntityCategory_Neutral, E_EntityCategory_Friendly, //... any other types... E_EntityCategory_Max};
The system functionality would just expect these.. as input... and could preallocate memory / resize containers appropriately. simple.
But then we have project 2... It also wants to use the system... but its entity categories are entirely different...
Now the project could be split up.. so we just rewrite the enum file based on the category needs of the current project. But what if we have one codebase... you cant really have both enums exist... ( i mean you could.. with some #ifdef project1.. etc magic.. but ugh) unless..
We give the enums different names e.g. E_projNameEntityCategory.. and then template the system to take the enum to use as an input parameter. But this just seems.. messy..? Plus theres no simple way in the system to refer to the 'max count' of these template enums for container sizing etc.
Ideally..
It'd be great if i could just grab the system and call
System.RegisterCategoryType( someCategoryOption1 )System.RegisterCategoryType( someCategoryOption2 )System.RegisterCategoryType( someCategoryOption3 )System.RegisterCategoryType( someCategoryOption4 )
BUT.. that'd mean i couldnt dynamically size containers in the system implementation to the max category size (And other such setup steps) until all the register stuff was called. And then things become horribly order dependent. That just represents more complexity for the end user. yuck.
Ideally i'd like something similar (i.e. a registration system) but that was done at compile time... Perhaps using some template wizardy (e.g. incrementing some count var each time a template type is instantiated).
e.g.
template< typename T >
RegisterCategoryType< T >
{
// increment some compile time counter
// manipulate type obj if necessary (e.g. setting its 'Id' to current count)
}
This would then allow the max count + ordering to be determined, containers could be preallocated to the correct sizes etc, and the actual system code could remain user friendly. This would require some object representing a type to be passed into the register func though (passed as a template param i mean... not an actual parameter).
Any ideas?
Alot of this probably makes no sense right now.. too early in the morning!.
EDIT: this is in C++ :)
[Edited by - NovaBlack on August 22, 2010 7:25:43 AM]