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