update copyright date
[gnash.git] / libcore / vm / ASHandlers.h
blob2483ac435940c6bac73ecb771313eca11d945bba
1 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
2 // 2011 Free Software Foundation, Inc
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #ifndef GNASH_ASHANDLERS_H
19 #define GNASH_ASHANDLERS_H
21 #include <string>
22 #include <vector>
24 #include "SWF.h"
26 // Forward declarations
27 namespace gnash {
28 class ActionExec;
29 class as_environment;
32 namespace gnash {
34 namespace SWF { // gnash::SWF
36 enum ArgumentType {
37 ARG_NONE = 0,
38 ARG_STR,
39 // default hex dump, in case the format is unknown or unsupported
40 ARG_HEX,
41 ARG_U8,
42 ARG_U16,
43 ARG_S16,
44 ARG_PUSH_DATA,
45 ARG_DECL_DICT,
46 ARG_FUNCTION2
50 class ActionHandler
52 typedef void (*ActionCallback)(ActionExec& thread);
54 public:
56 ActionHandler();
57 ActionHandler(ActionType type, ActionCallback func,
58 ArgumentType format = ARG_NONE);
60 /// Execute the action
61 void execute(ActionExec& thread) const;
63 ActionType getType() const { return _type; }
64 ArgumentType getArgFormat() const { return _arg_format; }
66 private:
68 ActionType _type;
69 ActionCallback _callback;
70 ArgumentType _arg_format;
73 /// A singleton containing the supported SWF Action handlers.
74 class SWFHandlers
76 public:
78 /// Return the singleton instance of SWFHandlers class
79 static const SWFHandlers& instance();
81 /// Execute the action identified by 'type' action type
82 void execute(ActionType type, ActionExec& thread) const;
84 size_t size() const { return _handlers.size(); }
86 ActionType lastType() const {
87 return ACTION_GOTOEXPRESSION;
90 const ActionHandler& operator[](ActionType x) const {
91 return _handlers[x];
94 private:
96 // Use the ::instance() method to get a reference
97 SWFHandlers();
99 // You won't destroy a singleton
100 ~SWFHandlers();
102 // Indexed by action id
103 typedef std::vector<ActionHandler> container_type;
105 container_type _handlers;
110 } // namespace SWF
111 } // namespace gnash
113 #endif