Bromeon
Events/ActionMap.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011-2012 Jan Haller
00005 // 
00006 // This software is provided 'as-is', without any express or implied
00007 // warranty. In no event will the authors be held liable for any damages
00008 // arising from the use of this software.
00009 // 
00010 // Permission is granted to anyone to use this software for any purpose,
00011 // including commercial applications, and to alter it and redistribute it
00012 // freely, subject to the following restrictions:
00013 // 
00014 // 1. The origin of this software must not be misrepresented; you must not
00015 //    claim that you wrote the original software. If you use this software
00016 //    in a product, an acknowledgment in the product documentation would be
00017 //    appreciated but is not required.
00018 // 
00019 // 2. Altered source versions must be plainly marked as such, and must not be
00020 //    misrepresented as being the original software.
00021 // 
00022 // 3. This notice may not be removed or altered from any source distribution.
00023 //
00025 
00028 
00029 #ifndef THOR_ACTIONMAP_HPP
00030 #define THOR_ACTIONMAP_HPP
00031 
00032 #include <Thor/Events/Action.hpp>
00033 #include <Thor/Events/ActionContext.hpp>
00034 #include <Thor/Tools/NonCopyable.hpp>
00035 #include <Thor/Tools/ForEach.hpp>
00036 #include <Thor/Detail/ActionOperations.hpp>
00037 
00038 #include <map>
00039 
00040 
00041 namespace thor
00042 {
00043 
00044 template <typename Event, typename EventIdentifier>
00045 class EventSystem;
00046 
00047 
00050 
00058 template <typename ActionIdentifier>
00059 class ActionMap : private NonCopyable
00060 {
00061     // ---------------------------------------------------------------------------------------------------------------------------
00062     // Public types
00063     public:
00066         typedef EventSystem< ActionContext<ActionIdentifier>, ActionIdentifier > CallbackSystem;
00067 
00068 
00069     // ---------------------------------------------------------------------------------------------------------------------------
00070     // Public member functions
00071     public:
00074         explicit                    ActionMap(sf::Window& window);
00075 
00090         void                        Update();
00091 
00095         void                        PushEvent(const sf::Event& event);
00096 
00100         void                        ClearEvents();
00101 
00109         Action&                     operator[] (const ActionIdentifier& id);
00110 
00113         void                        RemoveAction(const ActionIdentifier& id);
00114 
00117         void                        ClearActions();
00118 
00127         bool                        IsActive(const ActionIdentifier& id) const;
00128 
00148         void                        InvokeCallbacks(CallbackSystem& system) const;
00149 
00150 
00151     // ---------------------------------------------------------------------------------------------------------------------------
00152     // Private types
00153     private:
00154         typedef std::map<ActionIdentifier, Action> Map;
00155 
00156 
00157     // ---------------------------------------------------------------------------------------------------------------------------
00158     // Private variables
00159     private:
00160         Map                         mActionMap;
00161         detail::EventBuffer         mEventBuffer;
00162 };
00163 
00165 
00166 } // namespace thor
00167 
00168 #include <Thor/Detail/ActionMap.inl>
00169 #endif // THOR_ACTIONMAP_HPP