]> git.tdb.fi Git - r2c2.git/commitdiff
Save and load clock settings
authorMikko Rasa <tdb@tdb.fi>
Wed, 19 Mar 2014 16:56:01 +0000 (18:56 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 19 Mar 2014 20:21:05 +0000 (22:21 +0200)
source/libr2c2/clock.cpp
source/libr2c2/clock.h
source/libr2c2/layout.cpp
source/libr2c2/layout.h

index 1f467e81ba32369d3640693f24acf7e0b2c4e81c..93828cb90e5d87f728b4265a3bbed3f48ca03405 100644 (file)
@@ -1,5 +1,6 @@
 #include "clock.h"
 
+using namespace std;
 using namespace Msp;
 
 namespace R2C2 {
@@ -29,4 +30,23 @@ void Clock::tick(const Time::TimeDelta &dt)
                signal_minute.emit();
 }
 
+void Clock::save(list<DataFile::Statement> &st) const
+{
+       st.push_back((DataFile::Statement("rate"), rate));
+       st.push_back((DataFile::Statement("time"), current_time.raw()));
+}
+
+
+Clock::Loader::Loader(Clock &c):
+       DataFile::ObjectLoader<Clock>(c)
+{
+       add("rate", &Clock::rate);
+       add("time", &Loader::time);
+}
+
+void Clock::Loader::time(Time::RawTime t)
+{
+       obj.set_current_time(Time::TimeDelta(t));
+}
+
 } // namespace R2C2
index 186e0baab0181b6dfa7947f53ca82ce24a40fc36..59bffe70f0f3871ff4c469fbc73456bd301db2a5 100644 (file)
@@ -2,6 +2,7 @@
 #define LIBR2C2_CLOCK_H_
 
 #include <sigc++/signal.h>
+#include <msp/datafile/objectloader.h>
 #include <msp/time/timedelta.h>
 
 namespace R2C2 {
@@ -9,6 +10,15 @@ namespace R2C2 {
 class Clock
 {
 public:
+       class Loader: public Msp::DataFile::ObjectLoader<Clock>
+       {
+       public:
+               Loader(Clock &);
+
+       private:
+               void time(Msp::Time::RawTime);
+       };
+
        sigc::signal<void> signal_minute;
 
 private:
@@ -23,6 +33,7 @@ public:
        void set_current_time(const Msp::Time::TimeDelta &);
        const Msp::Time::TimeDelta &get_current_time() const { return current_time; }
        void tick(const Msp::Time::TimeDelta &);
+       void save(std::list<Msp::DataFile::Statement> &) const;
 };
 
 } // namespace R2C2
index 0025ec3b5b3adcd305ebd08ec8b8a9c44b8622ac..ac7101dfcf4e49708f8571a0f62bc4a9df292db4 100644 (file)
@@ -463,6 +463,12 @@ void Layout::save_dynamic(const string &fn) const
        IO::BufferedFile out(fn, IO::M_WRITE);
        DataFile::Writer writer(out);
 
+       {
+               DataFile::Statement st("clock");
+               clock.save(st.sub);
+               writer.write(st);
+       }
+
        const set<Track *> &tracks = objects.get<Track>();
        for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
                if(unsigned taddr = (*i)->get_turnout_address())
@@ -548,6 +554,7 @@ Layout::Loader::Loader(Layout &l):
 {
        add("base",  &Layout::base);
        add("beamgate", &Loader::beamgate);
+       add("clock", &Loader::clock);
        add("route", &Loader::route);
        add("signal", &Loader::signal);
        add("terrain", &Loader::terrain);
@@ -563,6 +570,11 @@ void Layout::Loader::beamgate()
        load_sub(*gate);
 }
 
+void Layout::Loader::clock()
+{
+       load_sub(obj.clock);
+}
+
 void Layout::Loader::route()
 {
        Route *rte = new Route(obj);
index af06d4ba7eb017b81aaccd6343a8fd8206e01462..44c4cde42efd861b804c3008525bc33ee62d0ef5 100644 (file)
@@ -34,6 +34,7 @@ public:
                Loader(Layout &);
        private:
                void beamgate();
+               void clock();
                void route();
                void signal(ArticleNumber);
                void terrain(ArticleNumber);