Timer.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /* GG is a GUI for SDL and OpenGL.
00003    Copyright (C) 2003-2008 T. Zachary Laine
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public License
00007    as published by the Free Software Foundation; either version 2.1
00008    of the License, or (at your option) any later version.
00009    
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014     
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA
00019 
00020    If you do not wish to comply with the terms of the LGPL please
00021    contact the author as other terms are available for a fee.
00022     
00023    Zach Laine
00024    whatwasthataddress@gmail.com */
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&); // disabled
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 } // namespace GG
00098 
00099 // template implementations
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

Generated on Sat Mar 26 07:08:37 2011 for GG by  doxygen 1.5.9