Author: zaroth
Date: Thu Jun  9 11:52:30 2011
New Revision: 49803

URL: http://svn.gna.org/viewcvs/wesnoth?rev=49803&view=rev
Log:
started using boost::tuple to group logically bound variables in 
commandline_options, dropped use of std::pair

Modified:
    trunk/src/commandline_options.cpp
    trunk/src/commandline_options.hpp

Modified: trunk/src/commandline_options.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/commandline_options.cpp?rev=49803&r1=49802&r2=49803&view=diff
==============================================================================
--- trunk/src/commandline_options.cpp (original)
+++ trunk/src/commandline_options.cpp Thu Jun  9 11:52:30 2011
@@ -14,6 +14,9 @@
 */
 
 #include "commandline_options.hpp"
+#include "foreach.hpp"
+#include "serialization/string_utils.hpp"
+#include "util.hpp"
 
 namespace po = boost::program_options;
 
@@ -110,10 +113,11 @@
                ("fps", "displays the number of frames per second the game is 
currently running at, in a corner of the screen.")
                ("max-fps", "the maximum fps the game tries to run at. Values 
should be between 1 and 1000, the default is 50.")
                ;
-       
+
        po::options_description multiplayer_opts("Multiplayer options");
        multiplayer_opts.add_options()
                ("multiplayer,m", "Starts a multiplayer game. There are 
additional options that can be used as explained below:")
+               ("ai-config", po::value<std::vector<std::string> 
>()->composing(), "arg should have format side:value\nselects a configuration 
file to load for this side.")
                ;
 
        hidden_.add_options()
@@ -126,6 +130,9 @@
 
        po::variables_map vm;
        po::store(po::parse_command_line(argc_,argv_,all_),vm);
+
+       if (vm.count("ai-config"))
+               multiplayer_ai_config = 
parse_to_int_string_tuples_(vm["ai-config"].as<std::vector<std::string> >());
 
        if (vm.count("bpp"))
                bpp = vm["bpp"].as<int>();
@@ -143,6 +150,8 @@
                load = vm["load"].as<std::string>();
        if (vm.count("max-fps"))
                max_fps = vm["max-fps"].as<int>();
+       if (vm.count("multiplayer"))
+               multiplayer = true;
        if (vm.count("new-storyscreens"))
                new_storyscreens = true;
        if (vm.count("new-syntax"))
@@ -161,6 +170,25 @@
                with_replay = true;
 }
 
+std::vector<boost::tuple<int,std::string> > 
commandline_options::parse_to_int_string_tuples_(const std::vector<std::string> 
&strings)
+{
+       std::vector<boost::tuple<int,std::string> > vec;
+       boost::tuple<int,std::string> elem;
+       foreach(const std::string &s, strings)
+       {
+               const std::vector<std::string> tokens = utils::split(s, ':');
+               if (tokens.size()!=2)
+               {
+                        //TODO throw meaningful exception
+               }
+               elem.get<0>() = lexical_cast<int>(tokens[0]);
+                       //TODO catch exception and pack in meaningful something
+               elem.get<1>() = tokens[1];
+               vec.push_back(elem);
+       }
+       return vec;
+}
+
 std::ostream& operator<<(std::ostream &os, const commandline_options& 
cmdline_opts)
 {
        os << "Usage: " << cmdline_opts.argv_[0] << " [<options>] 
[<data-directory>]\n";

Modified: trunk/src/commandline_options.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/commandline_options.hpp?rev=49803&r1=49802&r2=49803&view=diff
==============================================================================
--- trunk/src/commandline_options.hpp (original)
+++ trunk/src/commandline_options.hpp Thu Jun  9 11:52:30 2011
@@ -18,9 +18,9 @@
 
 #include <boost/optional.hpp>
 #include <boost/program_options.hpp>
+#include <boost/tuple/tuple.hpp>
 
 #include <string>
-#include <utility>
 #include <vector>
 
 class commandline_options
@@ -69,7 +69,7 @@
        bool help;
        /// Contains parsed arguments of --log-* (e.g. --log-debug).
        /// Vector of pairs (severity, log domain).
-       boost::optional<std::vector<std::pair<int, std::string> > > log;
+       boost::optional<std::vector<boost::tuple<int, std::string> > > log;
        /// Non-empty if --load was given on the command line. Savegame 
specified to load after start.
        boost::optional<std::string> load;
        /// Non-empty if --logdomains was given on the command line. Prints 
possible logdomains filtered by given string and exits.
@@ -77,19 +77,19 @@
        /// True if --multiplayer was given on the command line. Goes directly 
into multiplayer mode.
        bool multiplayer;
        /// Non-empty if --ai-config was given on the command line. Vector of 
pairs (side number, value). Dependant on --multiplayer.
-       boost::optional<std::vector<std::pair<int, std::string> > > 
multiplayer_ai_config;
+       boost::optional<std::vector<boost::tuple<int, std::string> > > 
multiplayer_ai_config;
        /// Non-empty if --algorithm was given on the command line. Vector of 
pairs (side number, value). Dependant on --multiplayer.
-       boost::optional<std::vector<std::pair<int, std::string> > > 
multiplayer_algorithm;
+       boost::optional<std::vector<boost::tuple<int, std::string> > > 
multiplayer_algorithm;
        /// Non-empty if --controller was given on the command line. Vector of 
pairs (side number, controller). Dependant on --multiplayer.
-       boost::optional<std::vector<std::pair<int, std::string> > > 
multiplayer_controller;
+       boost::optional<std::vector<boost::tuple<int, std::string> > > 
multiplayer_controller;
        /// Non-empty if --era was given on the command line. Dependant on 
--multiplayer.
        boost::optional<std::string> multiplayer_era;
        /// Non-empty if --label was given on the command line. Dependant on 
--multiplayer.
        boost::optional<std::string> multiplayer_label;
-       /// Non-empty if --parm was given on the command line. Vector of pairs 
(side number, (parm name, parm value)). Dependant on --multiplayer.
-       boost::optional<std::vector<std::pair<int, std::pair<std::string, 
std::string> > > > multiplayer_parm;
+       /// Non-empty if --parm was given on the command line. Vector of pairs 
(side number, parm name, parm value). Dependant on --multiplayer.
+       boost::optional<std::vector<boost::tuple<int, std::string, std::string> 
> > multiplayer_parm;
        /// Non-empty if --side was given on the command line. Vector of pairs 
(side number, faction id). Dependant on --multiplayer.
-       boost::optional<std::vector<std::pair<int, std::string> > > 
multiplayer_side;
+       boost::optional<std::vector<boost::tuple<int, std::string> > > 
multiplayer_side;
        /// Non-empty if --turns was given on the command line. Dependant on 
--multiplayer.
        boost::optional<std::string> multiplayer_turns;
        /// Max FPS specified by --max-fps option.
@@ -135,7 +135,7 @@
        /// Non-empty if --proxy-user was given on the command line.
        boost::optional<std::string> proxy_user;
        /// Pair of AxB values specified after --resolution. Changes Wesnoth 
resolution.
-       boost::optional<std::pair<int,int> > resolution;
+       boost::optional<boost::tuple<int,int> > resolution;
        /// RNG seed specified by --rng-seed option. Initializes RNG with given 
seed.
        boost::optional<int> rng_seed;
        /// Non-empty if --server was given on the command line.  Connects 
Wesnoth to specified server. If no server was specified afterwards, contains an 
empty string.
@@ -159,6 +159,7 @@
        /// True if --with-replay was given on the command line. Shows replay 
of the loaded file.
        bool with_replay;
 private:
+       std::vector<boost::tuple<int,std::string> > 
parse_to_int_string_tuples_(const std::vector<std::string> &strings);
        int argc_;
        char **argv_;
        boost::program_options::options_description all_;


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to