Timer.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00029 #ifndef _GG_Timer_h_
00030 #define _GG_Timer_h_
00031
00032 #include <GG/Base.h>
00033
00034 #include <set>
00035
00036
00037 namespace GG {
00038
00039 class Wnd;
00040
00049 class GG_API Timer
00050 {
00051 public:
00053 typedef boost::signal<void (unsigned int, Timer*)> FiredSignalType;
00054
00055
00057
00059 explicit Timer(unsigned int interval, unsigned int start_time = 0);
00060
00061 ~Timer();
00062
00063
00065 unsigned int Interval() const;
00066 bool Running() const;
00067
00068
00070 void Reset(unsigned int start_time = 0);
00071 void SetInterval(unsigned int interval);
00072 void Connect(Wnd* wnd);
00073 void Disconnect(Wnd* wnd);
00074 void Start();
00075 void Stop();
00076 void Update(unsigned int ticks);
00077
00078
00079 mutable FiredSignalType FiredSignal;
00080
00081 private:
00082 typedef std::map<Wnd*, boost::signals::connection> ConnectionMap;
00083
00084 Timer();
00085 Timer(const Timer&);
00086
00087 ConnectionMap m_wnd_connections;
00088 unsigned int m_interval;
00089 bool m_running;
00090 unsigned int m_last_fire;
00091
00092 friend class boost::serialization::access;
00093 template <class Archive>
00094 void serialize(Archive& ar, const unsigned int version);
00095 };
00096
00097 }
00098
00099
00100 template <class Archive>
00101 void GG::Timer::serialize(Archive& ar, const unsigned int version)
00102 {
00103 std::set<Wnd*> wnds;
00104 for (ConnectionMap::iterator it = m_wnd_connections.begin();
00105 it != m_wnd_connections.end();
00106 ++it)
00107 {
00108 wnds.insert(it->first);
00109 }
00110
00111 ar & BOOST_SERIALIZATION_NVP(wnds)
00112 & BOOST_SERIALIZATION_NVP(m_interval)
00113 & BOOST_SERIALIZATION_NVP(m_last_fire)
00114 & BOOST_SERIALIZATION_NVP(m_running);
00115
00116 if (Archive::is_loading::value) {
00117 for (std::set<Wnd*>::iterator it = wnds.begin(); it != wnds.end(); ++it) {
00118 Connect(*it);
00119 }
00120 }
00121 }
00122
00123 #endif