X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=libs%2Ftypesystem.h;h=4ceca552e23a936ea11cd8ea40cd2ab01539b9cc;hb=1ddc08ec7e251c504a55d5f33170cec680da24f1;hp=67c0680f38c63d13e7d5c32b2196a27fb04bc728;hpb=98da1e8a2e2bdc917376d2fe802e4f09a6241d23;p=xonotic%2Fnetradiant.git diff --git a/libs/typesystem.h b/libs/typesystem.h index 67c0680f..4ceca552 100644 --- a/libs/typesystem.h +++ b/libs/typesystem.h @@ -1,25 +1,25 @@ /* -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_TYPESYSTEM_H) +#if !defined( INCLUDED_TYPESYSTEM_H ) #define INCLUDED_TYPESYSTEM_H @@ -30,29 +30,25 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA class InitialiserList { - typedef std::list Initialisers; - Initialisers m_initialisers; - mutable bool m_initialised; +typedef std::list> Initialisers; +Initialisers m_initialisers; +mutable bool m_initialised; public: - InitialiserList() : m_initialised(false) - { - } - void addInitialiser(const Callback& callback) - { - m_initialisers.push_back(callback); - } - void initialise() const - { - if(!m_initialised) - { - m_initialised = true; - - for(Initialisers::const_iterator i = m_initialisers.begin(); i != m_initialisers.end(); ++i) - { - (*i)(); - } - } - } +InitialiserList() : m_initialised( false ){ +} +void addInitialiser( const Callback& callback ){ + m_initialisers.push_back( callback ); +} +void initialise() const { + if ( !m_initialised ) { + m_initialised = true; + + for ( Initialisers::const_iterator i = m_initialisers.begin(); i != m_initialisers.end(); ++i ) + { + ( *i )( ); + } + } +} }; //--Type System------------------- @@ -66,69 +62,61 @@ typedef SmartStatic StaticTypeSystemInitialiser; class TypeSystemRef : public StaticTypeSystemInitialiser { public: - TypeSystemRef() - { - StaticTypeSystemInitialiser::instance().initialise(); - } +TypeSystemRef(){ + StaticTypeSystemInitialiser::instance().initialise(); +} }; typedef std::size_t TypeId; -typedef void*(*TypeCast)(void*); +typedef void*( *TypeCast )( void* ); template class TypeCastTable { - TypeCast m_casts[SIZE]; +TypeCast m_casts[SIZE]; public: - TypeCastTable() - { - std::uninitialized_fill(m_casts, m_casts + SIZE, TypeCast(0)); - } - void install(TypeId typeId, TypeCast typeCast) - { - m_casts[typeId] = typeCast; - } - void* cast(TypeId typeId, void* p) - { - TypeCast typeCast = m_casts[typeId]; - if(typeCast != 0) - { - return typeCast(p); - } - return 0; - } +TypeCastTable(){ + std::uninitialized_fill( m_casts, m_casts + SIZE, TypeCast( 0 ) ); +} +void install( TypeId typeId, TypeCast typeCast ){ + m_casts[typeId] = typeCast; +} +void* cast( TypeId typeId, void* p ){ + TypeCast typeCast = m_casts[typeId]; + if ( typeCast != 0 ) { + return typeCast( p ); + } + return 0; +} }; template class CastInstaller { public: - static void install(TypeCastTable& table) - { - table.install(Type::getTypeId(), Cast::cast); - } +static void install( TypeCastTable& table ){ + table.install( Type::getTypeId(), Cast::cast ); +} }; template class IdentityCast { public: - static void* cast(void* p) - { - return p; - } +static void* cast( void* p ){ + return p; +} }; template class StaticCast { public: - static void* cast(void* p) - { - return static_cast(reinterpret_cast(p)); - } +static void* cast( void* p ){ + return static_cast( reinterpret_cast( p ) ); +} }; template @@ -140,10 +128,9 @@ template class ContainedCast { public: - static void* cast(void* p) - { - return &reinterpret_cast(p)->get(NullType()); - } +static void* cast( void* p ){ + return &reinterpret_cast( p )->get( NullType() ); +} };