action_buffer.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
00003 // 
00004 // This program is free software; you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation; either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 // 
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017 
00018 #ifndef GNASH_ACTION_BUFFER_H
00019 #define GNASH_ACTION_BUFFER_H
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #include "gnashconfig.h"
00023 #endif
00024 
00025 
00026 #include "gnash.h"
00027 #include "types.h"
00028 
00029 //#include <cwchar>
00030 #include <boost/cstdint.hpp> // for boost::uint8_t
00031 #include <vector> // for composition
00032 
00033 #include "smart_ptr.h"
00034 
00035 // Forward declarations
00036 namespace gnash {
00037         class as_environment;
00038         class as_value;
00039         class movie_definition;
00040 }
00041 
00042 
00043 namespace gnash {
00044 
00045 class ActionExec;
00046 
00048 //
00053 //
00054 class action_buffer
00055 {
00056 public:
00057         friend class ActionExec;
00058 
00059         action_buffer(const movie_definition& md);
00060 
00062         //
00069         void    read(stream& in, unsigned long endPos);
00070 
00071         bool is_null() const
00072         {
00073                 return m_buffer.size() < 1 || m_buffer[0] == 0;
00074         }
00075 
00076         // kept for backward compatibility, should drop and see
00077         // what breaks.
00078         size_t get_length() const { return size(); }
00079 
00080         size_t size() const { return m_buffer.size(); }
00081 
00082         boost::uint8_t operator[] (size_t off) const
00083         {
00084                 assert(off < m_buffer.size() );
00085                 return m_buffer[off];
00086         }
00087 
00089         std::string disasm(size_t pc) const;
00090 
00092         //
00095         const char* read_string(size_t pc) const
00096         {
00097                 //assert(pc < m_buffer.size() );
00098                 return (const char*)(&m_buffer[pc]);
00099         }
00100 
00103         boost::uint32_t read_V32(size_t pc, boost::uint8_t& length) const
00104         {
00105                 boost::uint32_t res = m_buffer[pc];
00106                 if (!(res & 0x00000080))
00107                 {
00108                         length = 1;
00109                         return res;
00110                 }
00111                 res = res & 0x0000007F | m_buffer[pc + 1] << 7;
00112                 if (!(res & 0x00004000))
00113                 {
00114                         length = 2;
00115                         return res;
00116                 }
00117                 res = res & 0x00003FFF | m_buffer[pc + 2] << 14;
00118                 if (!(res & 0x00200000))
00119                 {
00120                         length = 3;
00121                         return res;
00122                 }
00123                 res = res & 0x001FFFFF | m_buffer[pc + 3] << 21;
00124                 if (!(res & 0x10000000))
00125                 {
00126                         length = 4;
00127                         return res;
00128                 }
00129                 res = res & 0x0FFFFFFF | m_buffer[pc + 4] << 28;
00130                 length = 5;
00131                 return res;
00132         }
00133 
00135         const unsigned char* getFramePointer(size_t pc) const
00136         {
00137                 return reinterpret_cast<const unsigned char*>(&m_buffer[pc]);
00138         }
00139 
00141         const unsigned char* getCodeStart()
00142         {
00143                 return reinterpret_cast<const unsigned char*>(&m_buffer);
00144         }
00145 
00146         const unsigned char* get_buffer(size_t pc) const
00147         {
00148                 //assert(pc < m_buffer.size() );
00149                 return (const unsigned char*)(&m_buffer[pc]);
00150         }
00151 
00153         //
00156         boost::int16_t read_int16(size_t pc) const
00157         {
00158                 boost::int16_t ret = m_buffer[pc] | (m_buffer[pc + 1] << 8);
00159                 return ret;
00160         }
00161 
00163         //
00166         boost::uint16_t read_uint16(size_t pc) const
00167         {
00168                 return static_cast<boost::uint16_t>(read_int16(pc));
00169         }
00170 
00172         //
00175         boost::int32_t read_int32(size_t pc) const
00176         {
00177                 boost::int32_t  val = m_buffer[pc]
00178                       | (m_buffer[pc + 1] << 8)
00179                       | (m_buffer[pc + 2] << 16)
00180                       | (m_buffer[pc + 3] << 24);
00181                 return val;
00182         }
00183 
00185         //
00188         float read_float_little(size_t pc) const;
00189 
00191         //
00195         double read_double_wacky(size_t pc) const;
00196 
00198         size_t dictionary_size() const
00199         {
00200                 return m_dictionary.size();
00201         }
00202 
00204         const char* dictionary_get(size_t n) const
00205         {
00206                 return m_dictionary[n];
00207         }
00208 
00210         //
00231         void process_decl_dict(size_t start_pc, size_t stop_pc) const;
00232 
00233         const std::string& getDefinitionURL() const;
00234 
00235 private:
00236 
00237         // Don't put these as values in std::vector<>!  They contain
00238         // internal pointers and cannot be moved or copied.
00239         // If you need to keep an array of them, keep pointers
00240         // to new'd instances.
00241         action_buffer(const action_buffer& a) : _src(a._src) { abort(); }
00242 
00244         std::vector<boost::uint8_t> m_buffer;
00245 
00247         mutable std::vector<const char*> m_dictionary;
00248 
00250         mutable int m_decl_dict_processed_at;
00251 
00253         //
00257         const movie_definition& _src;
00258 };
00259 
00260 
00261 }       // end namespace gnash
00262 
00263 
00264 #endif // GNASH_ACTION_BUFFER_H
00265 
00266 
00267 // Local Variables:
00268 // mode: C++
00269 // indent-tabs-mode: t
00270 // End:

Generated on Thu Mar 6 18:25:06 2008 for Gnash by  doxygen 1.5.4