#include <vector>
#include <map>
-class RadiantFileTypeRegistry : public IFileTypeRegistry {
- struct filetype_copy_t {
- filetype_copy_t(const char *moduleName, const filetype_t other)
- : m_can_load(other.can_load), m_can_import(other.can_import), m_can_save(other.can_save),
- m_moduleName(moduleName), m_name(other.name), m_pattern(other.pattern)
- {
- }
-
- 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_copy_t> filetype_list_t;
- std::map<CopiedString, filetype_list_t> m_typelists;
+class RadiantFileTypeRegistry : public IFileTypeRegistry
+{
+struct filetype_copy_t
+{
+ filetype_copy_t( const char* moduleName, const filetype_t other )
+ : m_can_load( other.can_load ), m_can_import( other.can_import ), m_can_save( other.can_save ), m_moduleName( moduleName ), m_name( other.name ), m_pattern( other.pattern ) {
+ }
+ 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_copy_t> filetype_list_t;
+std::map<CopiedString, filetype_list_t> 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();
}
#include "modulesystem/singletonmodule.h"
#include "modulesystem/moduleregistry.h"
-class FiletypesAPI {
- IFileTypeRegistry *m_filetypes;
+class FiletypesAPI
+{
+IFileTypeRegistry* m_filetypes;
public:
- typedef IFileTypeRegistry Type;
-
- STRING_CONSTANT(Name, "*");
+typedef IFileTypeRegistry Type;
+STRING_CONSTANT( Name, "*" );
- FiletypesAPI()
- {
- m_filetypes = GetFileTypeRegistry();
- }
-
- IFileTypeRegistry *getTable()
- {
- return m_filetypes;
- }
+FiletypesAPI(){
+ m_filetypes = GetFileTypeRegistry();
+}
+IFileTypeRegistry* getTable(){
+ return m_filetypes;
+}
};
typedef SingletonModule<FiletypesAPI> FiletypesModule;
typedef Static<FiletypesModule> StaticFiletypesModule;
-StaticRegisterModule staticRegisterFiletypes(StaticFiletypesModule::instance());
+StaticRegisterModule staticRegisterFiletypes( StaticFiletypesModule::instance() );