X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=radiant%2Ffiletypes.cpp;h=87cb205c15b4afd6fc7519b3458b08d380f717d7;hp=11c0a272eceb97788479abc36d0b4a3c93815e25;hb=92b301a7f2ac5fdb8eabd87a919552231e8c1f77;hpb=61c537beac8ac40367b16a2eec937712b04ad63e diff --git a/radiant/filetypes.cpp b/radiant/filetypes.cpp index 11c0a272..87cb205c 100644 --- a/radiant/filetypes.cpp +++ b/radiant/filetypes.cpp @@ -1,23 +1,23 @@ /* -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 + */ #include "filetypes.h" @@ -32,89 +32,83 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA class RadiantFileTypeRegistry : public IFileTypeRegistry { - struct filetype_copy_t - { - filetype_copy_t(const char* moduleName, const filetype_t other) - : m_moduleName(moduleName), m_name(other.name), m_pattern(other.pattern), m_can_load(other.can_load), m_can_import(other.can_import), m_can_save(other.can_save) - { - } - const char* getModuleName() const - { - return m_moduleName.c_str(); - } - filetype_t getType() const - { - return filetype_t(m_name.c_str(), m_pattern.c_str(), m_can_load, m_can_save, m_can_import); - } - bool m_can_load; - bool m_can_import; - bool m_can_save; - private: - CopiedString m_moduleName; - CopiedString m_name; - CopiedString m_pattern; - }; - typedef std::vector filetype_list_t; - std::map m_typelists; +struct filetype_copy_t +{ + filetype_copy_t( const char* moduleName, const filetype_t other ) + : m_moduleName( moduleName ), m_name( other.name ), m_pattern( other.pattern ), m_can_load( other.can_load ), m_can_import( other.can_import ), m_can_save( other.can_save ){ + } + const char* getModuleName() const { + return m_moduleName.c_str(); + } + filetype_t getType() const { + return filetype_t( m_name.c_str(), m_pattern.c_str(), m_can_load, m_can_save, m_can_import ); + } + bool m_can_load; + bool m_can_import; + bool m_can_save; +private: + CopiedString m_moduleName; + CopiedString m_name; + CopiedString m_pattern; +}; +typedef std::vector filetype_list_t; +std::map m_typelists; public: - RadiantFileTypeRegistry() - { - addType("*", "*", filetype_t("All Files", "*.*")); - } - void addType(const char* moduleType, const char* moduleName, filetype_t type) - { - m_typelists[moduleType].push_back(filetype_copy_t(moduleName, type)); - } - void getTypeList(const char* moduleType, IFileTypeList* typelist, bool want_load, bool want_import, bool want_save) - { - filetype_list_t& list_ref = m_typelists[moduleType]; - for(filetype_list_t::iterator i = list_ref.begin(); i != list_ref.end(); ++i) - { - if(want_load && !(*i).m_can_load) return; - if(want_import && !(*i).m_can_import) return; - if(want_save && !(*i).m_can_save) return; - typelist->addType((*i).getModuleName(), (*i).getType()); - } - } +RadiantFileTypeRegistry(){ + addType( "*", "*", filetype_t( "All Files", "*.*" ) ); +} +void addType( const char* moduleType, const char* moduleName, filetype_t type ){ + m_typelists[moduleType].push_back( filetype_copy_t( moduleName, type ) ); +} +void getTypeList( const char* moduleType, IFileTypeList* typelist, bool want_load, bool want_import, bool want_save ){ + filetype_list_t& list_ref = m_typelists[moduleType]; + for ( filetype_list_t::iterator i = list_ref.begin(); i != list_ref.end(); ++i ) + { + if ( want_load && !( *i ).m_can_load ) { + return; + } + if ( want_import && !( *i ).m_can_import ) { + return; + } + if ( want_save && !( *i ).m_can_save ) { + return; + } + typelist->addType( ( *i ).getModuleName(), ( *i ).getType() ); + } +} }; static RadiantFileTypeRegistry g_patterns; -IFileTypeRegistry* GetFileTypeRegistry() -{ - return &g_patterns; +IFileTypeRegistry* GetFileTypeRegistry(){ + return &g_patterns; } -const char* findModuleName(IFileTypeRegistry* registry, const char* moduleType, const char* extension) -{ - class SearchFileTypeList : public IFileTypeList - { - char m_pattern[128]; - const char* m_moduleName; - public: - SearchFileTypeList(const char* ext) - : m_moduleName("") - { - m_pattern[0] = '*'; - m_pattern[1] = '.'; - strncpy(m_pattern + 2, ext, 125); - m_pattern[127] = '\0'; - } - void addType(const char* moduleName, filetype_t type) - { - if(extension_equal(m_pattern, type.pattern)) - { - m_moduleName = moduleName; - } - } - - const char* getModuleName() - { - return m_moduleName; - } - } search(extension); - registry->getTypeList(moduleType, &search); - return search.getModuleName(); +const char* findModuleName( IFileTypeRegistry* registry, const char* moduleType, const char* extension ){ + class SearchFileTypeList : public IFileTypeList + { + char m_pattern[128]; + const char* m_moduleName; +public: + SearchFileTypeList( const char* ext ) + : m_moduleName( "" ){ + m_pattern[0] = '*'; + m_pattern[1] = '.'; + strncpy( m_pattern + 2, ext, 125 ); + m_pattern[127] = '\0'; + } + void addType( const char* moduleName, filetype_t type ){ + if ( extension_equal( m_pattern, type.pattern ) ) { + m_moduleName = moduleName; + } + } + + const char* getModuleName(){ + return m_moduleName; + } + } search( extension ); + registry->getTypeList( moduleType, &search ); + return search.getModuleName(); } @@ -123,23 +117,19 @@ const char* findModuleName(IFileTypeRegistry* registry, const char* moduleType, class FiletypesAPI { - IFileTypeRegistry* m_filetypes; +IFileTypeRegistry* m_filetypes; public: - typedef IFileTypeRegistry Type; - STRING_CONSTANT(Name, "*"); - - FiletypesAPI() - { - m_filetypes = GetFileTypeRegistry(); - } - IFileTypeRegistry* getTable() - { - return m_filetypes; - } +typedef IFileTypeRegistry Type; +STRING_CONSTANT( Name, "*" ); + +FiletypesAPI(){ + m_filetypes = GetFileTypeRegistry(); +} +IFileTypeRegistry* getTable(){ + return m_filetypes; +} }; typedef SingletonModule FiletypesModule; typedef Static StaticFiletypesModule; -StaticRegisterModule staticRegisterFiletypes(StaticFiletypesModule::instance()); - - +StaticRegisterModule staticRegisterFiletypes( StaticFiletypesModule::instance() );