simplify TYPE_CONSTANT code
This commit is contained in:
@@ -33,8 +33,8 @@ public:
|
||||
INTEGER_CONSTANT( Version, 1 );
|
||||
};
|
||||
|
||||
int version = Bleh::Version();
|
||||
const char* name = Bleh::Name();
|
||||
int version = Bleh::Version;
|
||||
const char* name = Bleh::Name;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,25 +25,7 @@
|
||||
/// \file
|
||||
/// \brief Language extensions for constants that are guaranteed to be evaluated at compile-time.
|
||||
|
||||
/// \brief A compile-time-constant as a type.
|
||||
template<typename Type>
|
||||
struct ConstantWrapper
|
||||
{
|
||||
typedef typename Type::Value Value;
|
||||
operator Value() const
|
||||
{
|
||||
return Type::evaluate();
|
||||
}
|
||||
};
|
||||
template<typename TextOutputStreamType, typename Type>
|
||||
inline TextOutputStreamType& ostream_write( TextOutputStreamType& ostream, const ConstantWrapper<Type>& c ){
|
||||
return ostream_write( ostream, typename Type::Value( c ) );
|
||||
}
|
||||
|
||||
#define TYPE_CONSTANT( name, value, type ) struct name ## _CONSTANT_ { typedef type Value; static Value evaluate() { return value; } }; typedef ConstantWrapper<name ## _CONSTANT_> name
|
||||
#define STRING_CONSTANT( name, value ) TYPE_CONSTANT ( name, value, const char* )
|
||||
#define INTEGER_CONSTANT( name, value ) TYPE_CONSTANT ( name, value, int )
|
||||
|
||||
STRING_CONSTANT( EmptyString, "" );
|
||||
#define STRING_CONSTANT( name, value ) static constexpr const char* name = value
|
||||
#define INTEGER_CONSTANT( name, value ) static constexpr int name = value
|
||||
|
||||
#endif
|
||||
|
||||
@@ -102,7 +102,7 @@ public:
|
||||
if ( !globalModuleServer().getError() ) {
|
||||
if ( string_equal( names, "*" ) ) {
|
||||
InsertModules<Type> visitor( m_modules );
|
||||
globalModuleServer().foreachModule( typename Type::Name(), typename Type::Version(), visitor );
|
||||
globalModuleServer().foreachModule( Type::Name, Type::Version, visitor );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -113,11 +113,11 @@ public:
|
||||
if ( string_empty( name ) ) {
|
||||
break;
|
||||
}
|
||||
Module* module = globalModuleServer().findModule( typename Type::Name(), typename Type::Version(), name );
|
||||
Module* module = globalModuleServer().findModule( Type::Name, Type::Version, name );
|
||||
if ( module == 0 ) {
|
||||
globalErrorStream() << "ModulesRef::initialise: type=" << makeQuoted( typename Type::Name() ) << " version=" << makeQuoted( typename Type::Version() ) << " name=" << makeQuoted( name ) << " - not found\n";
|
||||
globalErrorStream() << "ModulesRef::initialise: type=" << makeQuoted( Type::Name ) << " version=" << makeQuoted( Type::Version ) << " name=" << makeQuoted( name ) << " - not found\n";
|
||||
// do not fail on missing image or model plugin, they can be optional
|
||||
if ( !string_equal( typename Type::Name(), "image" ) && !string_equal( typename Type::Name(), "model" ) ){
|
||||
if ( !string_equal( Type::Name, "image" ) && !string_equal( Type::Name, "model" ) ){
|
||||
globalModuleServer().setError( true );
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class DefaultAPIConstructor
|
||||
{
|
||||
public:
|
||||
const char* getName(){
|
||||
return typename API::Name();
|
||||
return API::Name;
|
||||
}
|
||||
|
||||
API* constructAPI( Dependencies& dependencies ){
|
||||
@@ -49,7 +49,7 @@ class DependenciesAPIConstructor
|
||||
{
|
||||
public:
|
||||
const char* getName(){
|
||||
return typename API::Name();
|
||||
return API::Name;
|
||||
}
|
||||
|
||||
API* constructAPI( Dependencies& dependencies ){
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
}
|
||||
|
||||
void selfRegister(){
|
||||
globalModuleServer().registerModule( typename Type::Name(), typename Type::Version(), APIConstructor::getName(), *this );
|
||||
globalModuleServer().registerModule( Type::Name, Type::Version, APIConstructor::getName(), *this );
|
||||
}
|
||||
|
||||
Dependencies& getDependencies(){
|
||||
@@ -101,16 +101,16 @@ public:
|
||||
}
|
||||
void capture(){
|
||||
if ( ++m_refcount == 1 ) {
|
||||
globalOutputStream() << "Module Initialising: '" << typename Type::Name() << "' '" << APIConstructor::getName() << "'\n";
|
||||
globalOutputStream() << "Module Initialising: '" << Type::Name << "' '" << APIConstructor::getName() << "'\n";
|
||||
m_dependencies = new Dependencies();
|
||||
m_dependencyCheck = !globalModuleServer().getError();
|
||||
if ( m_dependencyCheck ) {
|
||||
m_api = APIConstructor::constructAPI( *m_dependencies );
|
||||
globalOutputStream() << "Module Ready: '" << typename Type::Name() << "' '" << APIConstructor::getName() << "'\n";
|
||||
globalOutputStream() << "Module Ready: '" << Type::Name << "' '" << APIConstructor::getName() << "'\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
globalErrorStream() << "Module Dependencies Failed: '" << typename Type::Name() << "' '" << APIConstructor::getName() << "'\n";
|
||||
globalErrorStream() << "Module Dependencies Failed: '" << Type::Name << "' '" << APIConstructor::getName() << "'\n";
|
||||
}
|
||||
m_cycleCheck = true;
|
||||
}
|
||||
|
||||
@@ -98,17 +98,16 @@ class NodeType : public StaticTypeSystemInitialiser
|
||||
{
|
||||
TypeId m_typeId;
|
||||
public:
|
||||
typedef typename Type::Name Name;
|
||||
NodeType() : m_typeId( NODETYPEID_NONE ){
|
||||
StaticTypeSystemInitialiser::instance().addInitialiser( InitialiseCaller( *this ) );
|
||||
}
|
||||
void initialise(){
|
||||
m_typeId = GlobalSceneGraph().getNodeTypeId( Name() );
|
||||
m_typeId = GlobalSceneGraph().getNodeTypeId( Type::Name );
|
||||
}
|
||||
typedef MemberCaller<NodeType<Type>, &NodeType<Type>::initialise> InitialiseCaller;
|
||||
TypeId getTypeId(){
|
||||
#if defined( _DEBUG )
|
||||
ASSERT_MESSAGE( m_typeId != NODETYPEID_NONE, "node-type " << makeQuoted( Name() ) << " used before being initialised" );
|
||||
ASSERT_MESSAGE( m_typeId != NODETYPEID_NONE, "node-type " << makeQuoted( Name ) << " used before being initialised" );
|
||||
#endif
|
||||
return m_typeId;
|
||||
}
|
||||
@@ -433,17 +432,16 @@ class InstanceType : public StaticTypeSystemInitialiser
|
||||
{
|
||||
TypeId m_typeId;
|
||||
public:
|
||||
typedef typename Type::Name Name;
|
||||
InstanceType() : m_typeId( INSTANCETYPEID_NONE ){
|
||||
StaticTypeSystemInitialiser::instance().addInitialiser( InitialiseCaller( *this ) );
|
||||
}
|
||||
void initialise(){
|
||||
m_typeId = GlobalSceneGraph().getInstanceTypeId( Name() );
|
||||
m_typeId = GlobalSceneGraph().getInstanceTypeId( Type::Name );
|
||||
}
|
||||
typedef MemberCaller<InstanceType<Type>, &InstanceType<Type>::initialise> InitialiseCaller;
|
||||
TypeId getTypeId(){
|
||||
#if defined( _DEBUG )
|
||||
ASSERT_MESSAGE( m_typeId != INSTANCETYPEID_NONE, "instance-type " << makeQuoted( Name() ) << " used before being initialised" );
|
||||
ASSERT_MESSAGE( m_typeId != INSTANCETYPEID_NONE, "instance-type " << makeQuoted( Type::Name ) << " used before being initialised" );
|
||||
#endif
|
||||
return m_typeId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user