I was reading https://bitbucket.org/sinbad/ogre/src/4 ... .h?at=v2-1
Questions:
1. Am I correct that the OgreExport macro is not necessary in this file? I see only header-only/inline code.
2. In the transition document it says:
Wouldn't making IdObject template help with type-safety and value matching?"Note that, for example, Entities are completely different from SceneNodes (they don't even share a common base class), so it is possible for an Entity and a SceneNode to have the same Id."
I mean something like:
Code: Select all
// do NOT modify IdType.
//...
template< class AssociatedType >
class IdObject
{
// ... same as before, do not use AssociatedType at all
};
// ...
// then provide actual types, maybe pre-instantiated in a cpp somewhere, or not:
class SceneNode; // no definition needed, the type is never used
class Entity; // no definition needed, the type is never used
// Use these types in the Ogre API
typedef IdObject<SceneNode> SceneNodeId; // C++11 would be: using SceneNodeId = IdObject<SceneNode>;
typedef IdObject<Entity> EntityId; // C++11 would be: using EntityId = IdObject<Entity>;
//...
I use a very similar technique in several projects and it works very well as long as you keep a comon id value (here IdType).
The cost would be minor: more types would be defined but they would disappear in the optimized builds anyway (compilers optimize away this kind of case by having only one implementation for type several names).
Also, in my projects so far adding the template to id types this way didn't impact build times. (I did it atomically, once per different project, to be sure to see the impact in different use cases)
I can make a pull request if you think it's would help to do it, or if you just want to check yourself if it's cool.
The main issue would be replacing manually IdObject usage by more specific versions of it, but it should be obvious to do for me I suppose.
3. Header guards don't have any kind of prefix and use reserved __-prefixed named. Are there plans to fix that later? Want any help with cleaning?