Gnash 0.8.9
|
00001 // 00002 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 00003 // 2011 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_ACTION_BUFFER_H 00020 #define GNASH_ACTION_BUFFER_H 00021 00022 #include <string> 00023 #include <vector> 00024 #include <boost/noncopyable.hpp> 00025 #include <boost/cstdint.hpp> 00026 00027 #include "GnashException.h" 00028 #include "log.h" 00029 00030 // Forward declarations 00031 namespace gnash { 00032 class as_environment; 00033 class as_value; 00034 class movie_definition; 00035 class SWFStream; // for read signature 00036 } 00037 00038 namespace gnash { 00039 00041 // 00046 // 00048 class action_buffer : boost::noncopyable 00049 { 00050 public: 00051 00052 action_buffer(const movie_definition& md); 00053 00055 // 00062 void read(SWFStream& in, unsigned long endPos); 00063 00064 size_t size() const { return m_buffer.size(); } 00065 00066 boost::uint8_t operator[] (size_t off) const 00067 { 00068 if (off >= m_buffer.size()) { 00069 throw ActionParserException (_("Attempt to read outside " 00070 "action buffer")); 00071 } 00072 return m_buffer[off]; 00073 } 00074 00076 std::string disasm(size_t pc) const; 00077 00079 // 00082 const char* read_string(size_t pc) const 00083 { 00084 assert(pc <= m_buffer.size() ); 00085 if (pc == m_buffer.size()) 00086 { 00087 throw ActionParserException(_("Asked to read string when only " 00088 "1 byte remains in the buffer")); 00089 } 00090 return reinterpret_cast<const char*>(&m_buffer[pc]); 00091 } 00092 00094 const unsigned char* getFramePointer(size_t pc) const 00095 { 00096 assert (pc < m_buffer.size()); 00097 return reinterpret_cast<const unsigned char*>(&m_buffer.at(pc)); 00098 } 00099 00101 // 00104 boost::int16_t read_int16(size_t pc) const 00105 { 00106 if (pc + 1 >= m_buffer.size()) { 00107 throw ActionParserException(_("Attempt to read outside action buffer limits")); 00108 } 00109 boost::int16_t ret = (m_buffer[pc] | (m_buffer[pc + 1] << 8)); 00110 return ret; 00111 } 00112 00115 boost::uint16_t read_uint16(size_t pc) const 00116 { 00117 return static_cast<boost::uint16_t>(read_int16(pc)); 00118 } 00119 00121 // 00124 boost::int32_t read_int32(size_t pc) const 00125 { 00126 if (pc + 3 >= m_buffer.size()) { 00127 throw ActionParserException(_("Attempt to read outside action buffer limits")); 00128 } 00129 00130 boost::int32_t val = m_buffer[pc] 00131 | (m_buffer[pc + 1] << 8) 00132 | (m_buffer[pc + 2] << 16) 00133 | (m_buffer[pc + 3] << 24); 00134 return val; 00135 } 00136 00138 // 00141 float read_float_little(size_t pc) const; 00142 00144 // 00148 double read_double_wacky(size_t pc) const; 00149 00151 size_t dictionary_size() const 00152 { 00153 return m_dictionary.size(); 00154 } 00155 00157 const char* dictionary_get(size_t n) const 00158 { 00159 assert (n < m_dictionary.size()); 00160 return m_dictionary[n]; 00161 } 00162 00164 // 00185 void process_decl_dict(size_t start_pc, size_t stop_pc) const; 00186 00188 const std::string& getDefinitionURL() const; 00189 00191 int getDefinitionVersion() const; 00192 00193 const movie_definition& getMovieDefinition() const { 00194 return _src; 00195 } 00196 00197 private: 00198 00200 std::vector<boost::uint8_t> m_buffer; 00201 00203 mutable std::vector<const char*> m_dictionary; 00204 00206 mutable int m_decl_dict_processed_at; 00207 00209 // 00213 const movie_definition& _src; 00214 }; 00215 00216 00217 } // end namespace gnash 00218 00219 00220 #endif // GNASH_ACTION_BUFFER_H 00221 00222 00223 // Local Variables: 00224 // mode: C++ 00225 // indent-tabs-mode: t 00226 // End: