2 Copyright (C) 2001-2006, William Joseph.
\r
5 This file is part of GtkRadiant.
\r
7 GtkRadiant is free software; you can redistribute it and/or modify
\r
8 it under the terms of the GNU General Public License as published by
\r
9 the Free Software Foundation; either version 2 of the License, or
\r
10 (at your option) any later version.
\r
12 GtkRadiant is distributed in the hope that it will be useful,
\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 GNU General Public License for more details.
\r
17 You should have received a copy of the GNU General Public License
\r
18 along with GtkRadiant; if not, write to the Free Software
\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\r
22 #if !defined(INCLUDED_MODULESYSTEM_MODULESMAP_H)
\r
23 #define INCLUDED_MODULESYSTEM_MODULESMAP_H
\r
25 #include "modulesystem.h"
\r
26 #include "string/string.h"
\r
30 template<typename Type>
\r
31 class ModulesMap : public Modules<Type>
\r
33 typedef std::map<CopiedString, Module*> modules_t;
\r
34 modules_t m_modules;
\r
38 for(modules_t::iterator i = m_modules.begin(); i != m_modules.end(); ++i)
\r
40 (*i).second->release();
\r
44 typedef modules_t::const_iterator iterator;
\r
46 iterator begin() const
\r
48 return m_modules.begin();
\r
50 iterator end() const
\r
52 return m_modules.end();
\r
55 void insert(const char* name, Module& module)
\r
58 if(globalModuleServer().getError())
\r
61 globalModuleServer().setError(false);
\r
65 m_modules.insert(modules_t::value_type(name, &module));
\r
69 Type* find(const char* name)
\r
71 modules_t::iterator i = m_modules.find(name);
\r
72 if(i != m_modules.end())
\r
74 return static_cast<Type*>(Module_getTable(*(*i).second));
\r
79 Type* findModule(const char* name)
\r
83 void foreachModule(typename Modules<Type>::Visitor& visitor)
\r
85 for(modules_t::iterator i = m_modules.begin(); i != m_modules.end(); ++i)
\r
87 visitor.visit((*i).first.c_str(), *static_cast<const Type*>(Module_getTable(*(*i).second)));
\r
92 template<typename Type>
\r
93 class InsertModules : public ModuleServer::Visitor
\r
95 ModulesMap<Type>& m_modules;
\r
97 InsertModules(ModulesMap<Type>& modules)
\r
98 : m_modules(modules)
\r
101 void visit(const char* name, Module& module)
\r
103 m_modules.insert(name, module);
\r
107 template<typename Type>
\r
110 ModulesMap<Type> m_modules;
\r
112 ModulesRef(const char* names)
\r
114 if(!globalModuleServer().getError())
\r
116 if(string_equal(names, "*"))
\r
118 InsertModules<Type> visitor(m_modules);
\r
119 globalModuleServer().foreachModule(typename Type::Name(), typename Type::Version(), visitor);
\r
123 StringTokeniser tokeniser(names);
\r
126 const char* name = tokeniser.getToken();
\r
127 if(string_empty(name))
\r
131 Module* module = globalModuleServer().findModule(typename Type::Name(), typename Type::Version(), name);
\r
134 globalModuleServer().setError(true);
\r
135 globalErrorStream() << "ModulesRef::initialise: type=" << makeQuoted(typename Type::Name()) << " version=" << makeQuoted(typename Type::Version()) << " name=" << makeQuoted(name) << " - not found\n";
\r
140 m_modules.insert(name, *module);
\r
146 ModulesMap<Type>& get()
\r