• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

action_buffer.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   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 <boost/noncopyable.hpp>
00024 #include <boost/cstdint.hpp> // for boost::uint8_t
00025 #include <vector> // for composition
00026 
00027 #include "GnashException.h"
00028 #include "log.h" // For gettext macro
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 
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 }       // end namespace gnash
00224 
00225 
00226 #endif // GNASH_ACTION_BUFFER_H
00227 
00228 
00229 // Local Variables:
00230 // mode: C++
00231 // indent-tabs-mode: t
00232 // End:

Generated on Fri Mar 16 2012 15:46:08 for Gnash by  doxygen 1.7.1