indent classes, align by spaces
This commit is contained in:
@@ -42,9 +42,9 @@
|
||||
class Module
|
||||
{
|
||||
public:
|
||||
virtual void capture() = 0;
|
||||
virtual void release() = 0;
|
||||
virtual void* getTable() = 0;
|
||||
virtual void capture() = 0;
|
||||
virtual void release() = 0;
|
||||
virtual void* getTable() = 0;
|
||||
};
|
||||
|
||||
inline void* Module_getTable( Module& module ){
|
||||
@@ -57,38 +57,38 @@ class DebugMessageHandler;
|
||||
class ModuleServer
|
||||
{
|
||||
public:
|
||||
class Visitor
|
||||
{
|
||||
public:
|
||||
virtual void visit( const char* name, Module& module ) const = 0;
|
||||
};
|
||||
class Visitor
|
||||
{
|
||||
public:
|
||||
virtual void visit( const char* name, Module& module ) const = 0;
|
||||
};
|
||||
|
||||
virtual void setError( bool error ) = 0;
|
||||
virtual bool getError() const = 0;
|
||||
virtual void setError( bool error ) = 0;
|
||||
virtual bool getError() const = 0;
|
||||
|
||||
virtual TextOutputStream& getOutputStream() = 0;
|
||||
virtual TextOutputStream& getWarningStream() = 0;
|
||||
virtual TextOutputStream& getErrorStream() = 0;
|
||||
virtual DebugMessageHandler& getDebugMessageHandler() = 0;
|
||||
virtual TextOutputStream& getOutputStream() = 0;
|
||||
virtual TextOutputStream& getWarningStream() = 0;
|
||||
virtual TextOutputStream& getErrorStream() = 0;
|
||||
virtual DebugMessageHandler& getDebugMessageHandler() = 0;
|
||||
|
||||
virtual void registerModule( const char* type, int version, const char* name, Module& module ) = 0;
|
||||
virtual Module* findModule( const char* type, int version, const char* name ) const = 0;
|
||||
virtual void foreachModule( const char* type, int version, const Visitor& visitor ) = 0;
|
||||
virtual void registerModule( const char* type, int version, const char* name, Module& module ) = 0;
|
||||
virtual Module* findModule( const char* type, int version, const char* name ) const = 0;
|
||||
virtual void foreachModule( const char* type, int version, const Visitor& visitor ) = 0;
|
||||
};
|
||||
|
||||
class ModuleServerHolder
|
||||
{
|
||||
ModuleServer* m_server;
|
||||
ModuleServer* m_server;
|
||||
public:
|
||||
ModuleServerHolder()
|
||||
: m_server( 0 ){
|
||||
}
|
||||
void set( ModuleServer& server ){
|
||||
m_server = &server;
|
||||
}
|
||||
ModuleServer& get(){
|
||||
return *m_server;
|
||||
}
|
||||
ModuleServerHolder()
|
||||
: m_server( 0 ){
|
||||
}
|
||||
void set( ModuleServer& server ){
|
||||
m_server = &server;
|
||||
}
|
||||
ModuleServer& get(){
|
||||
return *m_server;
|
||||
}
|
||||
};
|
||||
|
||||
typedef Static<ModuleServerHolder> GlobalModuleServer;
|
||||
@@ -112,104 +112,104 @@ template<typename Type>
|
||||
class Modules
|
||||
{
|
||||
public:
|
||||
class Visitor
|
||||
{
|
||||
public:
|
||||
virtual void visit( const char* name, const Type& table ) const = 0;
|
||||
};
|
||||
class Visitor
|
||||
{
|
||||
public:
|
||||
virtual void visit( const char* name, const Type& table ) const = 0;
|
||||
};
|
||||
|
||||
virtual Type* findModule( const char* name ) = 0;
|
||||
virtual void foreachModule( const Visitor& visitor ) = 0;
|
||||
virtual Type* findModule( const char* name ) = 0;
|
||||
virtual void foreachModule( const Visitor& visitor ) = 0;
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
class ModuleRef
|
||||
{
|
||||
Module* m_module;
|
||||
Type* m_table;
|
||||
Module* m_module;
|
||||
Type* m_table;
|
||||
public:
|
||||
ModuleRef( const char* name ) : m_table( 0 ){
|
||||
if ( !globalModuleServer().getError() ) {
|
||||
m_module = globalModuleServer().findModule( typename Type::Name(), typename Type::Version(), name );
|
||||
if ( m_module == 0 ) {
|
||||
globalModuleServer().setError( true );
|
||||
globalErrorStream() << "ModuleRef::initialise: type=" << makeQuoted( typename Type::Name() ) << " version=" << makeQuoted( typename Type::Version() ) << " name=" << makeQuoted( name ) << " - not found\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_module->capture();
|
||||
if ( !globalModuleServer().getError() ) {
|
||||
m_table = static_cast<Type*>( m_module->getTable() );
|
||||
ModuleRef( const char* name ) : m_table( 0 ){
|
||||
if ( !globalModuleServer().getError() ) {
|
||||
m_module = globalModuleServer().findModule( typename Type::Name(), typename Type::Version(), name );
|
||||
if ( m_module == 0 ) {
|
||||
globalModuleServer().setError( true );
|
||||
globalErrorStream() << "ModuleRef::initialise: type=" << makeQuoted( typename Type::Name() ) << " version=" << makeQuoted( typename Type::Version() ) << " name=" << makeQuoted( name ) << " - not found\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_module->capture();
|
||||
if ( !globalModuleServer().getError() ) {
|
||||
m_table = static_cast<Type*>( m_module->getTable() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
~ModuleRef(){
|
||||
if ( m_module != 0 ) {
|
||||
m_module->release();
|
||||
~ModuleRef(){
|
||||
if ( m_module != 0 ) {
|
||||
m_module->release();
|
||||
}
|
||||
}
|
||||
}
|
||||
Type* getTable(){
|
||||
Type* getTable(){
|
||||
#if defined( _DEBUG )
|
||||
ASSERT_MESSAGE( m_table != 0, "ModuleRef::getTable: type=" << makeQuoted( typename Type::Name() ) << " version=" << makeQuoted( typename Type::Version() ) << " - module-reference used without being initialised" );
|
||||
ASSERT_MESSAGE( m_table != 0, "ModuleRef::getTable: type=" << makeQuoted( typename Type::Name() ) << " version=" << makeQuoted( typename Type::Version() ) << " - module-reference used without being initialised" );
|
||||
#endif
|
||||
return m_table;
|
||||
}
|
||||
return m_table;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
class SingletonModuleRef
|
||||
{
|
||||
Module* m_module;
|
||||
Type* m_table;
|
||||
Module* m_module;
|
||||
Type* m_table;
|
||||
public:
|
||||
|
||||
SingletonModuleRef()
|
||||
: m_module( 0 ), m_table( 0 ){
|
||||
}
|
||||
|
||||
bool initialised() const {
|
||||
return m_module != 0;
|
||||
}
|
||||
|
||||
void initialise( const char* name ){
|
||||
m_module = globalModuleServer().findModule( typename Type::Name(), typename Type::Version(), name );
|
||||
if ( m_module == 0 ) {
|
||||
globalModuleServer().setError( true );
|
||||
globalErrorStream() << "SingletonModuleRef::initialise: type=" << makeQuoted( typename Type::Name() ) << " version=" << makeQuoted( typename Type::Version() ) << " name=" << makeQuoted( name ) << " - not found\n";
|
||||
SingletonModuleRef()
|
||||
: m_module( 0 ), m_table( 0 ){
|
||||
}
|
||||
}
|
||||
|
||||
Type* getTable(){
|
||||
bool initialised() const {
|
||||
return m_module != 0;
|
||||
}
|
||||
|
||||
void initialise( const char* name ){
|
||||
m_module = globalModuleServer().findModule( typename Type::Name(), typename Type::Version(), name );
|
||||
if ( m_module == 0 ) {
|
||||
globalModuleServer().setError( true );
|
||||
globalErrorStream() << "SingletonModuleRef::initialise: type=" << makeQuoted( typename Type::Name() ) << " version=" << makeQuoted( typename Type::Version() ) << " name=" << makeQuoted( name ) << " - not found\n";
|
||||
}
|
||||
}
|
||||
|
||||
Type* getTable(){
|
||||
#if defined( _DEBUG )
|
||||
ASSERT_MESSAGE( m_table != 0, "SingletonModuleRef::getTable: type=" << makeQuoted( typename Type::Name() ) << " version=" << makeQuoted( typename Type::Version() ) << " - module-reference used without being initialised" );
|
||||
ASSERT_MESSAGE( m_table != 0, "SingletonModuleRef::getTable: type=" << makeQuoted( typename Type::Name() ) << " version=" << makeQuoted( typename Type::Version() ) << " - module-reference used without being initialised" );
|
||||
#endif
|
||||
return m_table;
|
||||
}
|
||||
void capture(){
|
||||
if ( initialised() ) {
|
||||
m_module->capture();
|
||||
m_table = static_cast<Type*>( m_module->getTable() );
|
||||
return m_table;
|
||||
}
|
||||
}
|
||||
void release(){
|
||||
if ( initialised() ) {
|
||||
m_module->release();
|
||||
void capture(){
|
||||
if ( initialised() ) {
|
||||
m_module->capture();
|
||||
m_table = static_cast<Type*>( m_module->getTable() );
|
||||
}
|
||||
}
|
||||
void release(){
|
||||
if ( initialised() ) {
|
||||
m_module->release();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
class GlobalModule
|
||||
{
|
||||
static SingletonModuleRef<Type> m_instance;
|
||||
static SingletonModuleRef<Type> m_instance;
|
||||
public:
|
||||
static SingletonModuleRef<Type>& instance(){
|
||||
return m_instance;
|
||||
}
|
||||
static Type& getTable(){
|
||||
return *m_instance.getTable();
|
||||
}
|
||||
static SingletonModuleRef<Type>& instance(){
|
||||
return m_instance;
|
||||
}
|
||||
static Type& getTable(){
|
||||
return *m_instance.getTable();
|
||||
}
|
||||
};
|
||||
|
||||
template<class Type>
|
||||
@@ -220,18 +220,18 @@ template<typename Type>
|
||||
class GlobalModuleRef
|
||||
{
|
||||
public:
|
||||
GlobalModuleRef( const char* name = "*" ){
|
||||
if ( !globalModuleServer().getError() ) {
|
||||
GlobalModule<Type>::instance().initialise( name );
|
||||
GlobalModuleRef( const char* name = "*" ){
|
||||
if ( !globalModuleServer().getError() ) {
|
||||
GlobalModule<Type>::instance().initialise( name );
|
||||
}
|
||||
GlobalModule<Type>::instance().capture();
|
||||
}
|
||||
~GlobalModuleRef(){
|
||||
GlobalModule<Type>::instance().release();
|
||||
}
|
||||
Type& getTable(){
|
||||
return GlobalModule<Type>::getTable();
|
||||
}
|
||||
GlobalModule<Type>::instance().capture();
|
||||
}
|
||||
~GlobalModuleRef(){
|
||||
GlobalModule<Type>::instance().release();
|
||||
}
|
||||
Type& getTable(){
|
||||
return GlobalModule<Type>::getTable();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user