[Orxonox-commit 5685] r10345 - in code/branches/core7/src: libraries/core libraries/core/commandline libraries/core/input orxonox orxonox/gamestates
landauf at orxonox.net
landauf at orxonox.net
Sun Apr 5 17:32:40 CEST 2015
Author: landauf
Date: 2015-04-05 17:32:40 +0200 (Sun, 05 Apr 2015)
New Revision: 10345
Added:
code/branches/core7/src/libraries/core/commandline/CommandLineIncludes.h
Modified:
code/branches/core7/src/libraries/core/Core.cc
code/branches/core7/src/libraries/core/PathConfig.cc
code/branches/core7/src/libraries/core/commandline/CommandLineParser.cc
code/branches/core7/src/libraries/core/commandline/CommandLineParser.h
code/branches/core7/src/libraries/core/input/InputManager.cc
code/branches/core7/src/orxonox/LevelManager.cc
code/branches/core7/src/orxonox/Main.cc
code/branches/core7/src/orxonox/gamestates/GSClient.cc
code/branches/core7/src/orxonox/gamestates/GSServer.cc
Log:
wrap CommandLineArguments in StaticallyInitializedInstances
Modified: code/branches/core7/src/libraries/core/Core.cc
===================================================================
--- code/branches/core7/src/libraries/core/Core.cc 2015-04-05 15:29:21 UTC (rev 10344)
+++ code/branches/core7/src/libraries/core/Core.cc 2015-04-05 15:32:40 UTC (rev 10345)
@@ -59,7 +59,7 @@
#include "util/ScopedSingletonManager.h"
#include "util/SignalHandler.h"
#include "PathConfig.h"
-#include "commandline/CommandLineParser.h"
+#include "commandline/CommandLineIncludes.h"
#include "config/ConfigFileManager.h"
#include "config/ConfigValueIncludes.h"
#include "CoreIncludes.h"
@@ -139,6 +139,7 @@
}
}
+ // TODO: initialize CommandLineParser here
ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances();
// Parse command line arguments AFTER the modules have been loaded (static code!)
Modified: code/branches/core7/src/libraries/core/PathConfig.cc
===================================================================
--- code/branches/core7/src/libraries/core/PathConfig.cc 2015-04-05 15:29:21 UTC (rev 10344)
+++ code/branches/core7/src/libraries/core/PathConfig.cc 2015-04-05 15:32:40 UTC (rev 10345)
@@ -52,7 +52,7 @@
#include "SpecialConfig.h"
#include "util/Output.h"
#include "util/Exception.h"
-#include "commandline/CommandLineParser.h"
+#include "commandline/CommandLineIncludes.h"
// Differentiate Boost Filesystem v2 and v3
#if (BOOST_FILESYSTEM_VERSION < 3)
Added: code/branches/core7/src/libraries/core/commandline/CommandLineIncludes.h
===================================================================
--- code/branches/core7/src/libraries/core/commandline/CommandLineIncludes.h (rev 0)
+++ code/branches/core7/src/libraries/core/commandline/CommandLineIncludes.h 2015-04-05 15:32:40 UTC (rev 10345)
@@ -0,0 +1,73 @@
+/*
+ * 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
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @defgroup CmdArgs Commandline arguments
+ @ingroup Config
+ @brief For a reference of all commandline arguments see @ref cmdargspage
+*/
+
+/**
+ @file
+ @ingroup Config CmdArgs
+ @brief Declaration of CommandLineParser and CommandLineArgument, definition of the SetCommandLineArgument() macros.
+*/
+
+#ifndef _CommandLineIncludes_H__
+#define _CommandLineIncludes_H__
+
+#include "core/CorePrereqs.h"
+
+#include "CommandLineParser.h"
+#include "core/module/StaticallyInitializedInstance.h"
+
+#define SetCommandLineArgument(name, defaultValue) \
+ orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
+ = (new orxonox::StaticallyInitializedCommandLineArgument(new orxonox::CommandLineArgument(#name, defaultValue)))->getArgument()
+#define SetCommandLineSwitch(name) \
+ SetCommandLineArgument(name, false)
+
+namespace orxonox
+{
+ class _CoreExport StaticallyInitializedCommandLineArgument : public StaticallyInitializedInstance
+ {
+ public:
+ StaticallyInitializedCommandLineArgument(CommandLineArgument* argument) : argument_(argument) {}
+
+ virtual void load()
+ { CommandLineParser::addArgument(this->argument_); }
+
+ inline CommandLineArgument& getArgument()
+ { return *this->argument_; }
+
+ private:
+ CommandLineArgument* argument_;
+ };
+}
+
+#endif /* _CommandLineIncludes_H__ */
Property changes on: code/branches/core7/src/libraries/core/commandline/CommandLineIncludes.h
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: code/branches/core7/src/libraries/core/commandline/CommandLineParser.cc
===================================================================
--- code/branches/core7/src/libraries/core/commandline/CommandLineParser.cc 2015-04-05 15:29:21 UTC (rev 10344)
+++ code/branches/core7/src/libraries/core/commandline/CommandLineParser.cc 2015-04-05 15:32:40 UTC (rev 10345)
@@ -337,4 +337,20 @@
return it->second;
}
}
+
+ /**
+ @brief
+ Adds a new CommandLineArgument to the internal map.
+ Note that only such arguments are actually valid.
+ */
+ void CommandLineParser::addArgument(CommandLineArgument* argument)
+ {
+ OrxAssert(!_getInstance().existsArgument(argument->getName()),
+ "Cannot add a command line argument with name '" + argument->getName() + "' twice.");
+ OrxAssert(!argument->getDefaultValue().isType<bool>() || argument->getDefaultValue().get<bool>() != true,
+ "Boolean command line arguments with positive default values are not supported." << endl
+ << "Please use SetCommandLineSwitch and adjust your argument: " << argument->getName());
+
+ _getInstance().cmdLineArgs_[argument->getName()] = argument;
+ }
}
Modified: code/branches/core7/src/libraries/core/commandline/CommandLineParser.h
===================================================================
--- code/branches/core7/src/libraries/core/commandline/CommandLineParser.h 2015-04-05 15:29:21 UTC (rev 10344)
+++ code/branches/core7/src/libraries/core/commandline/CommandLineParser.h 2015-04-05 15:32:40 UTC (rev 10345)
@@ -48,13 +48,6 @@
#include "util/OrxAssert.h"
#include "util/MultiType.h"
-#define SetCommandLineArgument(name, defaultValue) \
- orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
- = orxonox::CommandLineParser::addArgument(#name, defaultValue)
-#define SetCommandLineSwitch(name) \
- orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
- = orxonox::CommandLineParser::addArgument(#name, false)
-
namespace orxonox
{
/**
@@ -79,6 +72,15 @@
friend class CommandLineParser;
public:
+ //! Constructor initialises both value_ and defaultValue_ with defaultValue.
+ CommandLineArgument(const std::string& name, const MultiType& defaultValue)
+ : bHasDefaultValue_(true)
+ , name_(name)
+ , value_(defaultValue)
+ , defaultValue_(defaultValue)
+ { }
+ ~CommandLineArgument() { }
+
//! Tells whether the value has been changed by the command line.
bool hasDefaultValue() const { return bHasDefaultValue_; }
//! Returns the name of the argument.
@@ -103,17 +105,8 @@
const MultiType& getDefaultValue() const { return defaultValue_; }
private:
- //! Constructor initialises both value_ and defaultValue_ with defaultValue.
- CommandLineArgument(const std::string& name, const MultiType& defaultValue)
- : bHasDefaultValue_(true)
- , name_(name)
- , value_(defaultValue)
- , defaultValue_(defaultValue)
- { }
-
//! Undefined copy constructor
CommandLineArgument(const CommandLineArgument& instance);
- ~CommandLineArgument() { }
//! Parses the value string of a command line argument.
void parse(const std::string& value);
@@ -157,8 +150,7 @@
{ *value = (T)(getArgument(name)->getValue()); }
static const MultiType& getValue(const std::string& name)
{ return getArgument(name)->getValue(); }
- template <class T>
- static CommandLineArgument& addArgument(const std::string& name, T defaultValue);
+ static void addArgument(CommandLineArgument* argument);
static bool existsArgument(const std::string& name)
{
@@ -201,27 +193,6 @@
{
*value = getArgument(name)->getValue().get<std::string>();
}
-
- /**
- @brief
- Adds a new CommandLineArgument to the internal map.
- Note that only such arguments are actually valid.
- @param name
- Name of the argument. Shortcut can be added later.
- @param defaultValue
- Default value that is used when argument was not given.
- */
- template <class T>
- CommandLineArgument& CommandLineParser::addArgument(const std::string& name, T defaultValue)
- {
- OrxAssert(!_getInstance().existsArgument(name),
- "Cannot add a command line argument with name '" + name + "' twice.");
- OrxAssert(!MultiType(defaultValue).isType<bool>() || MultiType(defaultValue).get<bool>() != true,
- "Boolean command line arguments with positive default values are not supported." << endl
- << "Please use SetCommandLineSwitch and adjust your argument: " << name);
-
- return *(_getInstance().cmdLineArgs_[name] = new CommandLineArgument(name, defaultValue));
- }
}
#endif /* _CommandLine_H__ */
Modified: code/branches/core7/src/libraries/core/input/InputManager.cc
===================================================================
--- code/branches/core7/src/libraries/core/input/InputManager.cc 2015-04-05 15:29:21 UTC (rev 10344)
+++ code/branches/core7/src/libraries/core/input/InputManager.cc 2015-04-05 15:32:40 UTC (rev 10345)
@@ -47,7 +47,7 @@
#include "core/CoreIncludes.h"
#include "core/GraphicsManager.h"
#include "core/config/ConfigValueIncludes.h"
-#include "core/commandline/CommandLineParser.h"
+#include "core/commandline/CommandLineIncludes.h"
#include "core/command/ConsoleCommand.h"
#include "core/command/Functor.h"
Modified: code/branches/core7/src/orxonox/LevelManager.cc
===================================================================
--- code/branches/core7/src/orxonox/LevelManager.cc 2015-04-05 15:29:21 UTC (rev 10344)
+++ code/branches/core7/src/orxonox/LevelManager.cc 2015-04-05 15:32:40 UTC (rev 10345)
@@ -36,7 +36,7 @@
#include <map>
#include "util/ScopedSingletonManager.h"
-#include "core/commandline/CommandLineParser.h"
+#include "core/commandline/CommandLineIncludes.h"
#include "core/config/ConfigValueIncludes.h"
#include "core/CoreIncludes.h"
#include "core/ClassTreeMask.h"
Modified: code/branches/core7/src/orxonox/Main.cc
===================================================================
--- code/branches/core7/src/orxonox/Main.cc 2015-04-05 15:29:21 UTC (rev 10344)
+++ code/branches/core7/src/orxonox/Main.cc 2015-04-05 15:32:40 UTC (rev 10345)
@@ -35,7 +35,7 @@
#include "Main.h"
-#include "core/commandline/CommandLineParser.h"
+#include "core/commandline/CommandLineIncludes.h"
#include "core/Game.h"
#include "core/LuaState.h"
Modified: code/branches/core7/src/orxonox/gamestates/GSClient.cc
===================================================================
--- code/branches/core7/src/orxonox/gamestates/GSClient.cc 2015-04-05 15:29:21 UTC (rev 10344)
+++ code/branches/core7/src/orxonox/gamestates/GSClient.cc 2015-04-05 15:32:40 UTC (rev 10345)
@@ -29,7 +29,7 @@
#include "GSClient.h"
#include "util/Exception.h"
-#include "core/commandline/CommandLineParser.h"
+#include "core/commandline/CommandLineIncludes.h"
#include "core/Game.h"
#include "core/GameMode.h"
#include "network/Client.h"
Modified: code/branches/core7/src/orxonox/gamestates/GSServer.cc
===================================================================
--- code/branches/core7/src/orxonox/gamestates/GSServer.cc 2015-04-05 15:29:21 UTC (rev 10344)
+++ code/branches/core7/src/orxonox/gamestates/GSServer.cc 2015-04-05 15:32:40 UTC (rev 10345)
@@ -29,7 +29,7 @@
#include "GSServer.h"
#include "util/Output.h"
-#include "core/commandline/CommandLineParser.h"
+#include "core/commandline/CommandLineIncludes.h"
#include "core/Game.h"
#include "core/GameMode.h"
#include "network/Server.h"
More information about the Orxonox-commit
mailing list