X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=include%2Fmodulesystem.h;h=f7d4656440a1f71c0a54d0474e33225a420ff1af;hb=a31f4689bf410cd2d9a7b658ece392e96b01e388;hp=0378cc1d34031645d5a0e8a232d34647e8fda342;hpb=f57bd8b3da2293e1dc58d96d906cdd3ccf78d019;p=xonotic%2Fnetradiant.git diff --git a/include/modulesystem.h b/include/modulesystem.h index 0378cc1d..f7d46564 100644 --- a/include/modulesystem.h +++ b/include/modulesystem.h @@ -1,40 +1,36 @@ /* -Copyright (C) 2001-2006, William Joseph. -All Rights Reserved. + Copyright (C) 2001-2006, William Joseph. + All Rights Reserved. -This file is part of GtkRadiant. + This file is part of GtkRadiant. -GtkRadiant is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + GtkRadiant is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -GtkRadiant is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GtkRadiant is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GtkRadiant; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + You should have received a copy of the GNU General Public License + along with GtkRadiant; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ -#if !defined(INCLUDED_MODULESYSTEM_H) +#if !defined( INCLUDED_MODULESYSTEM_H ) #define INCLUDED_MODULESYSTEM_H +#include "globaldefs.h" #include "generic/static.h" #include "debugging/debugging.h" -#if defined(WIN32) -#ifdef MINGW32 +#if GDEF_OS_WINDOWS #define RADIANT_DLLEXPORT __declspec(dllexport) #define RADIANT_DLLIMPORT __declspec(dllimport) #else -#define RADIANT_DLLEXPORT __stdcall -#define RADIANT_DLLIMPORT __stdcall -#endif -#else -#define RADIANT_DLLEXPORT +#define RADIANT_DLLEXPORT __attribute__((visibility("default"))) #define RADIANT_DLLIMPORT #endif @@ -42,14 +38,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 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) -{ - return module.getTable(); +inline void* Module_getTable( Module& module ){ + return module.getTable(); } class TextOutputStream; @@ -58,56 +53,51 @@ class DebugMessageHandler; class ModuleServer { public: - 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 TextOutputStream& getOutputStream() = 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; +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 TextOutputStream& getOutputStream() = 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; }; 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 GlobalModuleServer; -inline ModuleServer& globalModuleServer() -{ - return GlobalModuleServer::instance().get(); +inline ModuleServer& globalModuleServer(){ + return GlobalModuleServer::instance().get(); } -inline void initialiseModule(ModuleServer& server) -{ - GlobalErrorStream::instance().setOutputStream(server.getErrorStream()); - GlobalOutputStream::instance().setOutputStream(server.getOutputStream()); - GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler()); - GlobalModuleServer::instance().set(server); +inline void initialiseModule( ModuleServer& server ){ + GlobalErrorStream::instance().setOutputStream( server.getErrorStream() ); + GlobalOutputStream::instance().setOutputStream( server.getOutputStream() ); + GlobalDebugMessageHandler::instance().setHandler( server.getDebugMessageHandler() ); + GlobalModuleServer::instance().set( server ); } @@ -116,14 +106,14 @@ template class Modules { public: - 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; +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; }; #include "debugging/debugging.h" @@ -131,109 +121,91 @@ public: template 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(m_module->getTable()); - } - } - } - } - ~ModuleRef() - { - if(m_module != 0) - { - m_module->release(); - } - } - 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"); +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( m_module->getTable() ); + } + } + } +} +~ModuleRef(){ + if ( m_module != 0 ) { + m_module->release(); + } +} +Type* getTable(){ +#if GDEF_DEBUG + 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 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"; - } - } - - 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"); +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"; + } +} + +Type* getTable(){ +#if GDEF_DEBUG + 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(m_module->getTable()); - } - } - void release() - { - if(initialised()) - { - m_module->release(); - } - } + return m_table; +} +void capture(){ + if ( initialised() ) { + m_module->capture(); + m_table = static_cast( m_module->getTable() ); + } +} +void release(){ + if ( initialised() ) { + m_module->release(); + } +} }; template class GlobalModule { - static SingletonModuleRef m_instance; +static SingletonModuleRef m_instance; public: - static SingletonModuleRef& instance() - { - return m_instance; - } - static Type& getTable() - { - return *m_instance.getTable(); - } +static SingletonModuleRef& instance(){ + return m_instance; +} +static Type& getTable(){ + return *m_instance.getTable(); +} }; template @@ -244,22 +216,18 @@ template class GlobalModuleRef { public: - GlobalModuleRef(const char* name = "*") - { - if(!globalModuleServer().getError()) - { - GlobalModule::instance().initialise(name); - } - GlobalModule::instance().capture(); - } - ~GlobalModuleRef() - { - GlobalModule::instance().release(); - } - Type& getTable() - { - return GlobalModule::getTable(); - } +GlobalModuleRef( const char* name = "*" ){ + if ( !globalModuleServer().getError() ) { + GlobalModule::instance().initialise( name ); + } + GlobalModule::instance().capture(); +} +~GlobalModuleRef(){ + GlobalModule::instance().release(); +} +Type& getTable(){ + return GlobalModule::getTable(); +} }; #endif