Claw  1.7.3
base_tweener.cpp
Go to the documentation of this file.
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22  contact: julien.jorge@gamned.org
23 */
30 
31 #include <claw/assert.hpp>
32 
33 /*----------------------------------------------------------------------------*/
38 {
39 
40 } // base_tweener::~base_tweener()
41 
42 /*----------------------------------------------------------------------------*/
47 {
48  return do_clone();
49 } // base_tweener::clone()
50 
51 /*----------------------------------------------------------------------------*/
56 {
57  return do_is_finished();
58 } // base_tweener::is_finished()
59 
60 /*----------------------------------------------------------------------------*/
67 {
68  CLAW_PRECOND( dt >= 0 );
69 
70  const double result = do_update(dt);
71 
72  if ( is_finished() )
73  notify_finished();
74 
75  CLAW_POSTCOND( result <= dt );
76  CLAW_POSTCOND( result >= 0 );
77 
78  return result;
79 } // base_tweener::update()
80 
81 /*----------------------------------------------------------------------------*/
86 {
87  m_on_finished.push_back(f);
88 } // base_tweener::on_finished()
89 
90 /*----------------------------------------------------------------------------*/
94 void claw::tween::base_tweener::notify_finished() const
95 {
96  // If one of the callbacks deletes the tweener, then m_on_finished will not be
97  // available. Since we still want to execute all the callbacks, we iterate on
98  // a copy of it.
99  const std::list<finish_callback> callbacks(m_on_finished);
100 
101  for ( std::list<finish_callback>::const_iterator it=callbacks.begin();
102  it!=callbacks.end(); ++it )
103  (*it)();
104 } // base_tweener::notify_finished()
boost::function< void()> finish_callback
The type of the function called to notify the end of the tweener.
virtual ~base_tweener()
Destructor.
Common interface for all tweeners.
void on_finished(finish_callback f)
Execute the callbacks notifying about the finish of the tweener.
base_tweener * clone() const
Create a copy of this allocated with new.
Common interface for all tweeners.
bool is_finished() const
Tell if the tweener has reached his total duration.
#define CLAW_POSTCOND(b)
Abort the program if a postcondition is not true.
Definition: assert.hpp:101
Some assert macros to strengthen you code.
#define CLAW_PRECOND(b)
Abort the program if a precondition is not true.
Definition: assert.hpp:98
double update(double dt)
Update the base_tweener of a given amount of time.