[Orxonox-commit 2448] r7155 - in code/branches/presentation3/src/libraries: core util

rgrieder at orxonox.net rgrieder at orxonox.net
Tue Jul 20 14:08:28 CEST 2010


Author: rgrieder
Date: 2010-07-20 14:08:28 +0200 (Tue, 20 Jul 2010)
New Revision: 7155

Added:
   code/branches/presentation3/src/libraries/util/Convert.cc
Modified:
   code/branches/presentation3/src/libraries/core/ConfigFileManager.cc
   code/branches/presentation3/src/libraries/core/ConfigFileManager.h
   code/branches/presentation3/src/libraries/util/CMakeLists.txt
   code/branches/presentation3/src/libraries/util/Convert.h
Log:
Reduced a dependency in util.

Modified: code/branches/presentation3/src/libraries/core/ConfigFileManager.cc
===================================================================
--- code/branches/presentation3/src/libraries/core/ConfigFileManager.cc	2010-07-12 12:06:15 UTC (rev 7154)
+++ code/branches/presentation3/src/libraries/core/ConfigFileManager.cc	2010-07-20 12:08:28 UTC (rev 7155)
@@ -32,6 +32,7 @@
 
 #include "util/Convert.h"
 #include "util/Math.h"
+#include "util/StringUtils.h"
 #include "ConsoleCommand.h"
 #include "ConfigValueContainer.h"
 #include "PathConfig.h"

Modified: code/branches/presentation3/src/libraries/core/ConfigFileManager.h
===================================================================
--- code/branches/presentation3/src/libraries/core/ConfigFileManager.h	2010-07-12 12:06:15 UTC (rev 7154)
+++ code/branches/presentation3/src/libraries/core/ConfigFileManager.h	2010-07-20 12:08:28 UTC (rev 7155)
@@ -38,7 +38,6 @@
 #include <boost/array.hpp>
 
 #include "util/Singleton.h"
-#include "util/StringUtils.h"
 
 namespace orxonox // tolua_export
 { // tolua_export

Modified: code/branches/presentation3/src/libraries/util/CMakeLists.txt
===================================================================
--- code/branches/presentation3/src/libraries/util/CMakeLists.txt	2010-07-12 12:06:15 UTC (rev 7154)
+++ code/branches/presentation3/src/libraries/util/CMakeLists.txt	2010-07-20 12:08:28 UTC (rev 7155)
@@ -26,6 +26,7 @@
 COMPILATION_BEGIN StableCompilation.cc
   Clipboard.cc
   Clock.cc
+  Convert.cc
   CRC32.cc
   ExprParser.cc
   OutputHandler.cc

Copied: code/branches/presentation3/src/libraries/util/Convert.cc (from rev 7141, code/branches/presentation3/src/libraries/util/Convert.h)
===================================================================
--- code/branches/presentation3/src/libraries/util/Convert.cc	                        (rev 0)
+++ code/branches/presentation3/src/libraries/util/Convert.cc	2010-07-20 12:08:28 UTC (rev 7155)
@@ -0,0 +1,55 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   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 2
+ *   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, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ */
+
+#include "Convert.h"
+#include "StringUtils.h"
+
+namespace orxonox
+{
+    //template <class FromType, class ToType>
+    bool ConverterExplicit<std::string, bool>::convert(bool* output, const std::string& input)
+    {
+        const std::string& stripped = getLowercase(removeTrailingWhitespaces(input));
+        if (stripped == "true" || stripped == "on" || stripped == "yes")
+        {
+            *output = true;
+            return true;
+        }
+        else if (stripped == "false" || stripped == "off" || stripped == "no")
+        {
+            *output = false;
+            return true;
+        }
+
+        std::istringstream iss(input);
+        if (iss >> (*output))
+            return true;
+        else
+            return false;
+    }
+}

Modified: code/branches/presentation3/src/libraries/util/Convert.h
===================================================================
--- code/branches/presentation3/src/libraries/util/Convert.h	2010-07-12 12:06:15 UTC (rev 7154)
+++ code/branches/presentation3/src/libraries/util/Convert.h	2010-07-20 12:08:28 UTC (rev 7155)
@@ -63,13 +63,14 @@
     operator has to be declared BEFORE this file gets parsed.
 
     Defining your own functions:
-    There are obviously 4 ways to specifiy a user defined conversion. What should I use?
+    There are obviously 4 ways to specify a user defined conversion. What should you use?
 
     Usually, ConverterFallback fits quite well. You won't have to deal with the conversion from
     'MyClass' to 'MyClass' by using another explicit template specialisation to avoid ambiguities.
 
     However if you want to overwrite an implicit conversion or an iostream operator, you really need to
-    make use of ConverterExplicit.
+    make use of ConverterExplicit. We have to do this for the Ogre classes for instance because they
+    define stream operators we don't particulary like.
 */
 
 namespace orxonox
@@ -387,34 +388,11 @@
         }
     };
 
-    // Declarations to avoid StringUtils.h include
-    _UtilExport std::string removeTrailingWhitespaces(const std::string& str);
-    _UtilExport std::string getLowercase(const std::string& str);
-
     // std::string to bool
     template <>
-    struct ConverterExplicit<std::string, bool>
+    struct _UtilExport ConverterExplicit<std::string, bool>
     {
-        static bool convert(bool* output, const std::string& input)
-        {
-            const std::string& stripped = getLowercase(removeTrailingWhitespaces(input));
-            if (stripped == "true" || stripped == "on" || stripped == "yes")
-            {
-                *output = true;
-                return true;
-            }
-            else if (stripped == "false" || stripped == "off" || stripped == "no")
-            {
-                *output = false;
-                return true;
-            }
-
-            std::istringstream iss(input);
-            if (iss >> (*output))
-                return true;
-            else
-                return false;
-        }
+        static bool convert(bool* output, const std::string& input);
     };
 }
 




More information about the Orxonox-commit mailing list