From: Mikko Rasa Date: Wed, 19 Mar 2014 16:56:01 +0000 (+0200) Subject: Save and load clock settings X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=9b07b35fd438f077896652258ac26453fc1c15dc;p=r2c2.git Save and load clock settings --- diff --git a/source/libr2c2/clock.cpp b/source/libr2c2/clock.cpp index 1f467e8..93828cb 100644 --- a/source/libr2c2/clock.cpp +++ b/source/libr2c2/clock.cpp @@ -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 &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(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 diff --git a/source/libr2c2/clock.h b/source/libr2c2/clock.h index 186e0ba..59bffe7 100644 --- a/source/libr2c2/clock.h +++ b/source/libr2c2/clock.h @@ -2,6 +2,7 @@ #define LIBR2C2_CLOCK_H_ #include +#include #include namespace R2C2 { @@ -9,6 +10,15 @@ namespace R2C2 { class Clock { public: + class Loader: public Msp::DataFile::ObjectLoader + { + public: + Loader(Clock &); + + private: + void time(Msp::Time::RawTime); + }; + sigc::signal 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 &) const; }; } // namespace R2C2 diff --git a/source/libr2c2/layout.cpp b/source/libr2c2/layout.cpp index 0025ec3..ac7101d 100644 --- a/source/libr2c2/layout.cpp +++ b/source/libr2c2/layout.cpp @@ -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 &tracks = objects.get(); for(set::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); diff --git a/source/libr2c2/layout.h b/source/libr2c2/layout.h index af06d4b..44c4cde 100644 --- a/source/libr2c2/layout.h +++ b/source/libr2c2/layout.h @@ -34,6 +34,7 @@ public: Loader(Layout &); private: void beamgate(); + void clock(); void route(); void signal(ArticleNumber); void terrain(ArticleNumber);