]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/modulesystem/modulesmap.h
fixed eol-style
[xonotic/netradiant.git] / libs / modulesystem / modulesmap.h
index 3af2f972165c8c958ad8da81b08fc4b7e9088dbc..44b62bdb33bc11379ff48b67ef826a47e3af9eff 100644 (file)
-/*\r
-Copyright (C) 2001-2006, William Joseph.\r
-All Rights Reserved.\r
-\r
-This file is part of GtkRadiant.\r
-\r
-GtkRadiant is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU General Public License as published by\r
-the Free Software Foundation; either version 2 of the License, or\r
-(at your option) any later version.\r
-\r
-GtkRadiant is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-GNU General Public License for more details.\r
-\r
-You should have received a copy of the GNU General Public License\r
-along with GtkRadiant; if not, write to the Free Software\r
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
-*/\r
-\r
-#if !defined(INCLUDED_MODULESYSTEM_MODULESMAP_H)\r
-#define INCLUDED_MODULESYSTEM_MODULESMAP_H\r
-\r
-#include "modulesystem.h"\r
-#include "string/string.h"\r
-#include <map>\r
-#include <set>\r
-\r
-template<typename Type>\r
-class ModulesMap : public Modules<Type>\r
-{\r
-  typedef std::map<CopiedString, Module*> modules_t;\r
-  modules_t m_modules;\r
-public:\r
-  ~ModulesMap()\r
-  {\r
-    for(modules_t::iterator i = m_modules.begin(); i != m_modules.end(); ++i) \r
-    {\r
-      (*i).second->release();\r
-    }\r
-  }\r
-\r
-  typedef modules_t::const_iterator iterator;\r
-\r
-  iterator begin() const\r
-  {\r
-    return m_modules.begin();\r
-  }\r
-  iterator end() const\r
-  {\r
-    return m_modules.end();\r
-  }\r
-\r
-  void insert(const char* name, Module& module)\r
-  {\r
-    module.capture();\r
-    if(globalModuleServer().getError())\r
-    {\r
-      module.release();\r
-      globalModuleServer().setError(false);\r
-    }\r
-    else\r
-    {\r
-      m_modules.insert(modules_t::value_type(name, &module));\r
-    }\r
-  }\r
-\r
-  Type* find(const char* name)\r
-  {\r
-    modules_t::iterator i = m_modules.find(name);\r
-    if(i != m_modules.end())\r
-    {\r
-      return static_cast<Type*>(Module_getTable(*(*i).second));\r
-    }\r
-    return 0;\r
-  }\r
-\r
-  Type* findModule(const char* name)\r
-  {\r
-    return find(name);\r
-  }\r
-  void foreachModule(typename Modules<Type>::Visitor& visitor)\r
-  {\r
-    for(modules_t::iterator i = m_modules.begin(); i != m_modules.end(); ++i)\r
-    {\r
-      visitor.visit((*i).first.c_str(), *static_cast<const Type*>(Module_getTable(*(*i).second)));\r
-    }\r
-  }\r
-};\r
-\r
-template<typename Type>\r
-class InsertModules : public ModuleServer::Visitor\r
-{\r
-  ModulesMap<Type>& m_modules;\r
-public:\r
-  InsertModules(ModulesMap<Type>& modules)\r
-    : m_modules(modules)\r
-  {\r
-  }\r
-  void visit(const char* name, Module& module)\r
-  {\r
-    m_modules.insert(name, module);\r
-  }\r
-};\r
-\r
-template<typename Type>\r
-class ModulesRef\r
-{\r
-  ModulesMap<Type> m_modules;\r
-public:\r
-  ModulesRef(const char* names)\r
-  {\r
-    if(!globalModuleServer().getError())\r
-    {\r
-      if(string_equal(names, "*"))\r
-      {\r
-        InsertModules<Type> visitor(m_modules);\r
-        globalModuleServer().foreachModule(typename Type::Name(), typename Type::Version(), visitor);\r
-      }\r
-      else\r
-      {\r
-        StringTokeniser tokeniser(names);\r
-        for(;;)\r
-        {\r
-          const char* name = tokeniser.getToken();\r
-          if(string_empty(name))\r
-          {\r
-            break;\r
-          }\r
-          Module* module = globalModuleServer().findModule(typename Type::Name(), typename Type::Version(), name);\r
-          if(module == 0)\r
-          {\r
-            globalModuleServer().setError(true);\r
-            globalErrorStream() << "ModulesRef::initialise: type=" << makeQuoted(typename Type::Name()) << " version=" << makeQuoted(typename Type::Version()) << " name=" << makeQuoted(name) << " - not found\n";\r
-            break;\r
-          }\r
-          else\r
-          {\r
-            m_modules.insert(name, *module);\r
-          }\r
-        }\r
-      }\r
-    }\r
-  }\r
-  ModulesMap<Type>& get()\r
-  {\r
-    return m_modules;\r
-  }\r
-};\r
-\r
-#endif\r
+/*
+Copyright (C) 2001-2006, William Joseph.
+All Rights Reserved.
+
+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 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
+*/
+
+#if !defined(INCLUDED_MODULESYSTEM_MODULESMAP_H)
+#define INCLUDED_MODULESYSTEM_MODULESMAP_H
+
+#include "modulesystem.h"
+#include "string/string.h"
+#include <map>
+#include <set>
+
+template<typename Type>
+class ModulesMap : public Modules<Type>
+{
+  typedef std::map<CopiedString, Module*> modules_t;
+  modules_t m_modules;
+public:
+  ~ModulesMap()
+  {
+    for(modules_t::iterator i = m_modules.begin(); i != m_modules.end(); ++i) 
+    {
+      (*i).second->release();
+    }
+  }
+
+  typedef modules_t::const_iterator iterator;
+
+  iterator begin() const
+  {
+    return m_modules.begin();
+  }
+  iterator end() const
+  {
+    return m_modules.end();
+  }
+
+  void insert(const char* name, Module& module)
+  {
+    module.capture();
+    if(globalModuleServer().getError())
+    {
+      module.release();
+      globalModuleServer().setError(false);
+    }
+    else
+    {
+      m_modules.insert(modules_t::value_type(name, &module));
+    }
+  }
+
+  Type* find(const char* name)
+  {
+    modules_t::iterator i = m_modules.find(name);
+    if(i != m_modules.end())
+    {
+      return static_cast<Type*>(Module_getTable(*(*i).second));
+    }
+    return 0;
+  }
+
+  Type* findModule(const char* name)
+  {
+    return find(name);
+  }
+  void foreachModule(typename Modules<Type>::Visitor& visitor)
+  {
+    for(modules_t::iterator i = m_modules.begin(); i != m_modules.end(); ++i)
+    {
+      visitor.visit((*i).first.c_str(), *static_cast<const Type*>(Module_getTable(*(*i).second)));
+    }
+  }
+};
+
+template<typename Type>
+class InsertModules : public ModuleServer::Visitor
+{
+  ModulesMap<Type>& m_modules;
+public:
+  InsertModules(ModulesMap<Type>& modules)
+    : m_modules(modules)
+  {
+  }
+  void visit(const char* name, Module& module)
+  {
+    m_modules.insert(name, module);
+  }
+};
+
+template<typename Type>
+class ModulesRef
+{
+  ModulesMap<Type> m_modules;
+public:
+  ModulesRef(const char* names)
+  {
+    if(!globalModuleServer().getError())
+    {
+      if(string_equal(names, "*"))
+      {
+        InsertModules<Type> visitor(m_modules);
+        globalModuleServer().foreachModule(typename Type::Name(), typename Type::Version(), visitor);
+      }
+      else
+      {
+        StringTokeniser tokeniser(names);
+        for(;;)
+        {
+          const char* name = tokeniser.getToken();
+          if(string_empty(name))
+          {
+            break;
+          }
+          Module* module = globalModuleServer().findModule(typename Type::Name(), typename Type::Version(), name);
+          if(module == 0)
+          {
+            globalModuleServer().setError(true);
+            globalErrorStream() << "ModulesRef::initialise: type=" << makeQuoted(typename Type::Name()) << " version=" << makeQuoted(typename Type::Version()) << " name=" << makeQuoted(name) << " - not found\n";
+            break;
+          }
+          else
+          {
+            m_modules.insert(name, *module);
+          }
+        }
+      }
+    }
+  }
+  ModulesMap<Type>& get()
+  {
+    return m_modules;
+  }
+};
+
+#endif