]> git.tdb.fi Git - r2c2.git/commitdiff
Use per-layout state files
authorMikko Rasa <tdb@tdb.fi>
Tue, 19 Oct 2010 16:34:25 +0000 (16:34 +0000)
committerMikko Rasa <tdb@tdb.fi>
Tue, 19 Oct 2010 16:34:25 +0000 (16:34 +0000)
Add command line option to specify state file

source/engineer/engineer.cpp
source/engineer/options.cpp
source/engineer/options.h

index 5cf22ba0f2f9c8390f557a26fb000bd1f5a6c23d..9db63fe0c70c22f81eb68074e88067fb6ade1fd6 100644 (file)
@@ -84,8 +84,8 @@ Engineer::Engineer(int argc, char **argv):
        layout.signal_block_reserved.connect(sigc::mem_fun(this, &Engineer::block_reserved));
        layout.signal_emergency.connect(sigc::mem_fun(this, &Engineer::set_status));
        layout.get_driver().signal_sensor.connect(sigc::mem_fun(this, &Engineer::sensor_event));
-       if(FS::exists("engineer.state"))
-               DataFile::load(layout, "engineer.state");
+       if(FS::exists(options.state_fn))
+               DataFile::load(layout, options.state_fn);
 
        if(options.network)
        {
@@ -131,7 +131,7 @@ Engineer::~Engineer()
        layout.get_driver().flush();
 
        if(!options.simulate)
-               layout.save_trains("engineer.state");
+               layout.save_trains(options.state_fn);
 
        delete overlay;
        delete root;
index 9861c10e7e6230f282f8f1f4aaa6159c0e3d76c5..fc7516c16cc2405d91c7e92cf0944d9be07400f3 100644 (file)
@@ -6,6 +6,7 @@ Distributed under the GPL
 */
 
 #include <msp/core/getopt.h>
+#include <msp/fs/utils.h>
 #include <msp/strings/lexicalcast.h>
 #include <msp/strings/regex.h>
 #include "options.h"
@@ -30,6 +31,7 @@ Options::Options(int argc, char **argv):
        getopt.add_option('d', "driver",      driver,      GetOpt::REQUIRED_ARG);
        getopt.add_option('s', "simulate",    simulate,    GetOpt::NO_ARG);
        getopt.add_option('n', "network",     network,     GetOpt::NO_ARG);
+       getopt.add_option(     "state",       state_fn,    GetOpt::REQUIRED_ARG);
        getopt(argc, argv);
 
        if(!res.empty())
@@ -48,4 +50,7 @@ Options::Options(int argc, char **argv):
                throw UsageError("No layout given");
 
        layout_fn = args[0];
+
+       if(state_fn.empty())
+               state_fn = FS::basepart(layout_fn)+".state";
 }
index e842c254fbb6c2a7b937765dca4182a841d9a439..689b22a7bdbb9be16289a175ff6d2c493b78bd07 100644 (file)
@@ -20,6 +20,7 @@ struct Options
        bool network;
        bool simulate;
        std::string layout_fn;
+       std::string state_fn;
 
        Options(int, char **);
 };