Gnash 0.8.10dev
|
00001 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 00002 // 2011 Free Software Foundation, Inc 00003 // 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software 00016 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00017 00018 #ifndef GNASH_ASHANDLERS_H 00019 #define GNASH_ASHANDLERS_H 00020 00021 #include <string> 00022 #include <vector> 00023 00024 #include "SWF.h" 00025 00026 // Forward declarations 00027 namespace gnash { 00028 class ActionExec; 00029 } 00030 00031 namespace gnash { 00032 00033 namespace SWF { // gnash::SWF 00034 00035 enum ArgumentType { 00036 ARG_NONE = 0, 00037 ARG_STR, 00038 // default hex dump, in case the format is unknown or unsupported 00039 ARG_HEX, 00040 ARG_U8, 00041 ARG_U16, 00042 ARG_S16, 00043 ARG_PUSH_DATA, 00044 ARG_DECL_DICT, 00045 ARG_FUNCTION2 00046 }; 00047 00048 00049 class ActionHandler 00050 { 00051 typedef void (*ActionCallback)(ActionExec& thread); 00052 00053 public: 00054 00055 ActionHandler(); 00056 ActionHandler(ActionType type, ActionCallback func, 00057 ArgumentType format = ARG_NONE); 00058 00060 void execute(ActionExec& thread) const; 00061 00062 ActionType getType() const { return _type; } 00063 ArgumentType getArgFormat() const { return _arg_format; } 00064 00065 private: 00066 00067 ActionType _type; 00068 ActionCallback _callback; 00069 ArgumentType _arg_format; 00070 }; 00071 00073 class SWFHandlers 00074 { 00075 public: 00076 00078 static const SWFHandlers& instance(); 00079 00081 void execute(ActionType type, ActionExec& thread) const; 00082 00083 size_t size() const { return _handlers.size(); } 00084 00085 ActionType lastType() const { 00086 return ACTION_GOTOEXPRESSION; 00087 } 00088 00089 const ActionHandler& operator[](ActionType x) const { 00090 return _handlers[x]; 00091 } 00092 00093 private: 00094 00095 // Use the ::instance() method to get a reference 00096 SWFHandlers(); 00097 00098 // You won't destroy a singleton 00099 ~SWFHandlers(); 00100 00101 // Indexed by action id 00102 typedef std::vector<ActionHandler> container_type; 00103 00104 container_type _handlers; 00105 00106 }; 00107 00108 00109 } // namespace SWF 00110 } // namespace gnash 00111 00112 #endif