pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r4082 - trunk/pingus/src/engine/input


From: grumbel at BerliOS
Subject: [Pingus-CVS] r4082 - trunk/pingus/src/engine/input
Date: Sun, 8 Nov 2009 20:30:05 +0100

Author: grumbel
Date: 2009-11-08 20:30:04 +0100 (Sun, 08 Nov 2009)
New Revision: 4082

Added:
   trunk/pingus/src/engine/input/driver_factory.cpp
   trunk/pingus/src/engine/input/driver_factory.hpp
Modified:
   trunk/pingus/src/engine/input/manager.cpp
Log:
Moved driver creation into DriverFactory


Added: trunk/pingus/src/engine/input/driver_factory.cpp
===================================================================
--- trunk/pingus/src/engine/input/driver_factory.cpp    2009-11-08 19:29:39 UTC 
(rev 4081)
+++ trunk/pingus/src/engine/input/driver_factory.cpp    2009-11-08 19:30:04 UTC 
(rev 4082)
@@ -0,0 +1,83 @@
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 1998-2009 Ingo Ruhnke <address@hidden>
+//
+//  This program 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 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "driver_factory.hpp"
+
+#include "engine/input/core_driver.hpp"
+#include "engine/input/sdl_driver.hpp"
+
+#ifdef HAVE_CWIID
+#  include "engine/input/wiimote/wiimote_driver.hpp"
+#endif 
+
+#ifdef HAVE_XINPUT
+#  include "engine/input/xinput/xinput_driver.hpp"
+#endif
+
+#ifdef HAVE_LINUXUSBMOUSE
+#  include "engine/input/usbmouse/usbmouse_driver.hpp"
+#endif
+
+#ifdef HAVE_LINUXEVDEV
+#  include "engine/input/evdev/evdev_driver.hpp"
+#endif
+
+namespace Input {
+
+Driver*
+DriverFactory::create(const std::string& name, Manager* manager)
+{
+  if (name == "sdl") 
+  {
+    return new SDLDriver;
+  }
+  else if (name == "core") 
+  {
+    return new CoreDriver(manager);
+  }
+#ifdef HAVE_LINUXUSBMOUSE
+  else if (name == "usbmouse") 
+  {
+    return new USBMouseDriver();
+  } 
+#endif
+#ifdef HAVE_LINUXEVDEV
+  else if (name == "evdev") 
+  {
+    return new EvdevDriver();
+  }
+#endif
+#ifdef HAVE_XINPUT
+  else if (name == "xinput") 
+  {
+    return new XInputDriver();
+  } 
+#endif
+#ifdef HAVE_CWIID
+  else if (name == "wiimote") 
+  {
+    return new WiimoteDriver();
+  } 
+#endif
+  else 
+  {
+    return 0;
+  }
+}
+
+} // namespace Input
+
+/* EOF */


Property changes on: trunk/pingus/src/engine/input/driver_factory.cpp
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/pingus/src/engine/input/driver_factory.hpp
===================================================================
--- trunk/pingus/src/engine/input/driver_factory.hpp    2009-11-08 19:29:39 UTC 
(rev 4081)
+++ trunk/pingus/src/engine/input/driver_factory.hpp    2009-11-08 19:30:04 UTC 
(rev 4082)
@@ -0,0 +1,42 @@
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 1998-2009 Ingo Ruhnke <address@hidden>
+//
+//  This program 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 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_PINGUS_ENGINE_INPUT_DRIVER_FACTORY_HPP
+#define HEADER_PINGUS_ENGINE_INPUT_DRIVER_FACTORY_HPP
+
+#include <string>
+
+namespace Input {
+
+class Driver;
+class Manager;
+
+class DriverFactory
+{
+private:
+public:
+  static Driver* create(const std::string& name, Manager* manager);
+
+private:
+  DriverFactory(const DriverFactory&);
+  DriverFactory& operator=(const DriverFactory&);
+};
+
+} // namespace Input
+
+#endif
+
+/* EOF */


Property changes on: trunk/pingus/src/engine/input/driver_factory.hpp
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: trunk/pingus/src/engine/input/manager.cpp
===================================================================
--- trunk/pingus/src/engine/input/manager.cpp   2009-11-08 19:29:39 UTC (rev 
4081)
+++ trunk/pingus/src/engine/input/manager.cpp   2009-11-08 19:30:04 UTC (rev 
4082)
@@ -18,22 +18,9 @@
 
 #include <stdexcept>
 
-#include "engine/input/core_driver.hpp"
-#include "engine/input/sdl_driver.hpp"
+#include "engine/input/driver_factory.hpp"
 #include "util/pathname.hpp"
 #include "util/string_util.hpp"
-#ifdef HAVE_CWIID
-#  include "engine/input/wiimote/wiimote_driver.hpp"
-#endif 
-#ifdef HAVE_XINPUT
-#  include "engine/input/xinput/xinput_driver.hpp"
-#endif
-#ifdef HAVE_LINUXUSBMOUSE
-#  include "engine/input/usbmouse/usbmouse_driver.hpp"
-#endif
-#ifdef HAVE_LINUXEVDEV
-#  include "engine/input/evdev/evdev_driver.hpp"
-#endif
 
 namespace Input {
 
@@ -231,33 +218,17 @@
   {
     std::cout << "Manager: Loading driver '" << name << "'" << std::endl;
 
-    if (name == "sdl") {
-      driver = new SDLDriver();
-    } else if (name == "core") {
-      driver = new CoreDriver(this);
-#ifdef HAVE_LINUXUSBMOUSE
-    } else if (name == "usbmouse") {
-      driver = new USBMouseDriver();
-#endif
-#ifdef HAVE_LINUXEVDEV
-    } else if (name == "evdev") {
-      driver = new EvdevDriver();
-#endif
-#ifdef HAVE_XINPUT
-    } else if (name == "xinput") {
-      driver = new XInputDriver();
-#endif
-#ifdef HAVE_CWIID
-    } else if (name == "wiimote") {
-      driver = new WiimoteDriver();
-#endif
-    } else {
+    driver = DriverFactory::create(name, this);
+    if (!driver)
+    {
       std::cout << "Manager: Unknown driver: " << name << std::endl;
       return 0;
     }
-
-    drivers.push_back(driver);
-    return driver;
+    else
+    {
+      drivers.push_back(driver);
+      return driver;
+    }
   }
 }
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]