Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GNASH_ACTION_BUFFER_H
00020 #define GNASH_ACTION_BUFFER_H
00021
00022 #include <string>
00023 #include <boost/noncopyable.hpp>
00024 #include <boost/cstdint.hpp>
00025 #include <vector>
00026
00027 #include "GnashException.h"
00028 #include "log.h"
00029
00030
00031 namespace gnash {
00032 class as_environment;
00033 class as_value;
00034 class movie_definition;
00035 class SWFStream;
00036 }
00037
00038
00039 namespace gnash {
00040
00041 class ActionExec;
00042
00043 double convert_double_wacky(const void *p);
00044
00046
00051
00053 class action_buffer : boost::noncopyable
00054 {
00055 public:
00056 friend class ActionExec;
00057
00058 action_buffer(const movie_definition& md);
00059
00061
00068 void read(SWFStream& in, unsigned long endPos);
00069
00070 size_t size() const { return m_buffer.size(); }
00071
00072 boost::uint8_t operator[] (size_t off) const
00073 {
00074 if (off >= m_buffer.size()) {
00075 throw ActionParserException (_("Attempt to read outside "
00076 "action buffer"));
00077 }
00078 return m_buffer[off];
00079 }
00080
00082 std::string disasm(size_t pc) const;
00083
00085
00088 const char* read_string(size_t pc) const
00089 {
00090 assert(pc <= m_buffer.size() );
00091 if (pc == m_buffer.size())
00092 {
00093 throw ActionParserException(_("Asked to read string when only "
00094 "1 byte remains in the buffer"));
00095 }
00096 return reinterpret_cast<const char*>(&m_buffer[pc]);
00097 }
00098
00100 const unsigned char* getFramePointer(size_t pc) const
00101 {
00102 assert (pc < m_buffer.size());
00103 return reinterpret_cast<const unsigned char*>(&m_buffer.at(pc));
00104 }
00105
00107
00110 boost::int16_t read_int16(size_t pc) const
00111 {
00112 if (pc + 1 >= m_buffer.size()) {
00113 throw ActionParserException(_("Attempt to read outside action buffer limits"));
00114 }
00115 boost::int16_t ret = (m_buffer[pc] | (m_buffer[pc + 1] << 8));
00116 return ret;
00117 }
00118
00121 boost::uint16_t read_uint16(size_t pc) const
00122 {
00123 return static_cast<boost::uint16_t>(read_int16(pc));
00124 }
00125
00127
00130 boost::int32_t read_int32(size_t pc) const
00131 {
00132 if (pc + 3 >= m_buffer.size()) {
00133 throw ActionParserException(_("Attempt to read outside action buffer limits"));
00134 }
00135
00136 boost::int32_t val = m_buffer[pc]
00137 | (m_buffer[pc + 1] << 8)
00138 | (m_buffer[pc + 2] << 16)
00139 | (m_buffer[pc + 3] << 24);
00140 return val;
00141 }
00142
00144
00147 float read_float_little(size_t pc) const;
00148
00150
00154 double read_double_wacky(size_t pc) const;
00155
00157 size_t dictionary_size() const
00158 {
00159 return m_dictionary.size();
00160 }
00161
00163 const char* dictionary_get(size_t n) const
00164 {
00165 assert (n < m_dictionary.size());
00166 return m_dictionary[n];
00167 }
00168
00170
00191 void process_decl_dict(size_t start_pc, size_t stop_pc) const;
00192
00194 const std::string& getDefinitionURL() const;
00195
00197 int getDefinitionVersion() const;
00198
00199 const movie_definition& getMovieDefinition() const {
00200 return _src;
00201 }
00202
00203 private:
00204
00206 std::vector<boost::uint8_t> m_buffer;
00207
00209 mutable std::vector<const char*> m_dictionary;
00210
00212 mutable int m_decl_dict_processed_at;
00213
00215
00219 const movie_definition& _src;
00220 };
00221
00222
00223 }
00224
00225
00226 #endif // GNASH_ACTION_BUFFER_H
00227
00228
00229
00230
00231
00232