SDLPP: Visitor pattern

This commit is contained in:
zv0n 2021-04-25 13:57:33 +02:00
parent ee82430f82
commit 87970bfc4b
3 changed files with 25 additions and 2 deletions

View File

@ -237,4 +237,7 @@ void RenderObject::setAnimationSpeed( const double fps ) {
animation_fps = fps;
animation_next_frame = animation_next_frame_base = 1000 / fps;
}
void RenderObject::visit( Visitor &visitor ) {
visitor.visit( *this );
}
} // namespace SDLPP

View File

@ -6,6 +6,7 @@
#include "sdlpp_renderer.hpp"
#include "sdlpp_texture.hpp"
#include "sdlpp_vector.hpp"
#include "sdlpp_visitor.hpp"
#include <memory>
#include <vector>
@ -101,6 +102,7 @@ public:
void resumeAnimation();
void removeAnimation();
void animate( int ticks );
void visit( Visitor &visitor );
protected:
virtual void copyTo( std::shared_ptr< RenderObject > other );

18
sdlpp/sdlpp_visitor.hpp Normal file
View File

@ -0,0 +1,18 @@
#ifndef SDLPP_HPP_VISITOR
#define SDLPP_HPP_VISITOR
#include "sdlpp_common.hpp"
namespace SDLPP {
class SDLPPSCOPE RenderObject;
class SDLPPSCOPE Visitor {
public:
Visitor() {}
virtual void visit( const RenderObject &obj );
};
} // namespace SDLPP
#endif