Gnash 0.8.10dev
action_buffer.h
Go to the documentation of this file.
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_value;
00033         class movie_definition;
00034         class SWFStream; // for read signature
00035 }
00036 
00037 namespace gnash {
00038 
00040 //
00045 //
00047 class action_buffer : boost::noncopyable
00048 {
00049 public:
00050 
00051         action_buffer(const movie_definition& md);
00052 
00054         //
00061         void read(SWFStream& in, unsigned long endPos);
00062 
00063         size_t size() const { return m_buffer.size(); }
00064 
00065         boost::uint8_t operator[] (size_t off) const
00066         {
00067                 if (off >= m_buffer.size()) {
00068                     throw ActionParserException (_("Attempt to read outside "
00069                                     "action buffer"));
00070                 }
00071                 return m_buffer[off];
00072         }
00073 
00075         std::string disasm(size_t pc) const;
00076 
00078         //
00081         const char* read_string(size_t pc) const
00082         {
00083                 assert(pc <= m_buffer.size() );
00084         if (pc == m_buffer.size())
00085         {
00086             throw ActionParserException(_("Asked to read string when only "
00087                 "1 byte remains in the buffer"));
00088         }
00089                 return reinterpret_cast<const char*>(&m_buffer[pc]);
00090         }
00091 
00093         const unsigned char* getFramePointer(size_t pc) const
00094         {
00095             assert (pc < m_buffer.size());
00096                 return reinterpret_cast<const unsigned char*>(&m_buffer.at(pc));
00097         }
00098 
00100         //
00103         boost::int16_t read_int16(size_t pc) const
00104         {
00105             if (pc + 1 >= m_buffer.size()) {
00106                 throw ActionParserException(_("Attempt to read outside action buffer limits"));
00107             }
00108                 boost::int16_t ret = (m_buffer[pc] | (m_buffer[pc + 1] << 8));
00109                 return ret;
00110         }
00111 
00114         boost::uint16_t read_uint16(size_t pc) const
00115         {
00116                 return static_cast<boost::uint16_t>(read_int16(pc));
00117         }
00118 
00120         //
00123         boost::int32_t read_int32(size_t pc) const
00124         {
00125                 if (pc + 3 >= m_buffer.size()) {
00126                 throw ActionParserException(_("Attempt to read outside action buffer limits"));
00127             }
00128             
00129                 boost::int32_t  val = m_buffer[pc]
00130                       | (m_buffer[pc + 1] << 8)
00131                       | (m_buffer[pc + 2] << 16)
00132                       | (m_buffer[pc + 3] << 24);
00133                 return val;
00134         }
00135 
00137         //
00140         float read_float_little(size_t pc) const;
00141 
00143         //
00147         double read_double_wacky(size_t pc) const;
00148 
00150         size_t dictionary_size() const
00151         {
00152                 return m_dictionary.size();
00153         }
00154 
00156         const char* dictionary_get(size_t n) const
00157         {
00158             assert (n < m_dictionary.size());
00159                 return m_dictionary[n];
00160         }
00161 
00163         //
00184         void process_decl_dict(size_t start_pc, size_t stop_pc) const;
00185 
00187         const std::string& getDefinitionURL() const;
00188 
00190         int getDefinitionVersion() const;
00191 
00192     const movie_definition& getMovieDefinition() const {
00193         return _src;
00194     }
00195 
00196 private:
00197 
00199         std::vector<boost::uint8_t> m_buffer;
00200 
00202         mutable std::vector<const char*> m_dictionary;
00203 
00205         mutable int m_decl_dict_processed_at;
00206 
00208         //
00212         const movie_definition& _src;
00213 };
00214 
00215 
00216 }       // end namespace gnash
00217 
00218 
00219 #endif // GNASH_ACTION_BUFFER_H
00220 
00221 
00222 // Local Variables:
00223 // mode: C++
00224 // indent-tabs-mode: t
00225 // End: