tahoma2d/toonz/sources/include/ttimer.h

112 lines
2.5 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef TTIMER_INCLUDED
#define TTIMER_INCLUDED
2016-04-14 22:15:09 +12:00
#include <memory>
2016-03-19 06:57:51 +13:00
#include "tcommon.h"
#undef DVAPI
#undef DVVAR
#ifdef TAPPTOOLS_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI TGenericTimerAction {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
virtual ~TGenericTimerAction() {}
virtual void sendCommand(TUINT64 tick) = 0;
2016-03-19 06:57:51 +13:00
};
//-------------------------------------------------------------------
template <class T>
class TTimerAction final : public TGenericTimerAction {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
typedef void (T::*Method)(TUINT64 tick);
TTimerAction(T *target, Method method) : m_target(target), m_method(method) {}
2016-06-19 20:06:29 +12:00
void sendCommand(TUINT64 tick) override { (m_target->*m_method)(tick); }
2016-06-15 18:43:10 +12:00
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
T *m_target;
Method m_method;
2016-03-19 06:57:51 +13:00
};
//------------------------------------------------------------------------------
//! THis class is manages general time events.
/*!
2016-06-15 18:43:10 +12:00
This class defines a timer,
i.e a system which, at user defined time steps, sends events
through a callback function.
*/
class DVAPI TTimer {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
/*!
Specifies which is the type of timer of this object.
*/
enum Type {
OneShot, /*!< This type of timer sends timer events only at a single time.
*/
Periodic /*!< This type of timer sends timer events periodically. */
};
/*!
Creates a timer with name \p name, resolution \p timerRes and type \p
type.
Resolution is expressed in milliseconds.
*/
TTimer(const std::string &name, UINT timerRes, Type type);
/*!
Deletes the timer.
*/
~TTimer();
/*!
Starts the timer after \p delay milliseconds.
*/
void start(UINT delay); // delay expressed in milliseconds
/*!
Stops the timer immediately.
Doesn't delete the timer.
*/
void stop();
/*!
Returns \p true if the timer is started.
*/
bool isStarted() const;
/*!
Returns the name of the timer.
*/
std::string getName() const;
/*!
Asks the timer for number of events so far.
*/
TUINT64 getTicks() const;
/*!
Returns the initial start delay of the timer.
*/
UINT getDelay() const;
/*!
Sets the callback function, i.e. the function to be called every
timer's shot.
*/
void setAction(TGenericTimerAction *action);
class Imp;
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
std::unique_ptr<Imp> m_imp;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TTimer(const TTimer &);
void operator=(const TTimer &);
2016-03-19 06:57:51 +13:00
};
#endif