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

ExportAssetsTag.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_SWF_EXPORTASSETSTAG_H
00020 #define GNASH_SWF_EXPORTASSETSTAG_H
00021 
00022 #include <vector>
00023 #include <utility>
00024 #include <string>
00025 #include <memory>
00026 
00027 #include "ControlTag.h"
00028 #include "Movie.h"
00029 #include "MovieClip.h"
00030 #include "SWFStream.h"
00031 #include "MovieFactory.h"
00032 #include "log.h"
00033 
00034 namespace gnash {
00035 namespace SWF {
00036 
00037 class ExportAssetsTag : public ControlTag
00038 {
00039 public:
00040 
00041     typedef std::vector<std::string> Exports;
00042 
00043     // Load an export tag (for exposing internal resources of m)
00044     static void loader(SWFStream& in, TagType tag, movie_definition& m,
00045             const RunResources& /*r*/)
00046     {
00047         assert(tag == SWF::EXPORTASSETS); // 56
00048 
00049         std::auto_ptr<ControlTag> t(new ExportAssetsTag(in, m));
00050         m.addControlTag(t.release());
00051     }
00052 
00053 
00054     // TODO: use Movie to store the actual exports.
00055     virtual void executeState(MovieClip* m, DisplayList& /*l*/) const {
00056         Movie* mov = m->get_root();
00057         for (Exports::const_iterator it = _exports.begin(), e = _exports.end();
00058                 it != e; ++it) {
00059             const boost::uint16_t id = mov->definition()->exportID(*it);
00060 
00061             // We exported it, so we assume it is known.
00062             assert(id);
00063             mov->addCharacter(id);
00064         }
00065     }
00066 
00067 private:
00068 
00069     ExportAssetsTag(SWFStream& in, movie_definition& m)
00070     {
00071         read(in, m);
00072     }
00073 
00074     void read(SWFStream& in, movie_definition& m) {
00075         
00076         in.ensureBytes(2);
00077         const boost::uint16_t count = in.read_u16();
00078 
00079         IF_VERBOSE_PARSE(
00080             log_parse(_("  export: count = %d"), count);
00081         );
00082 
00083         // Read the exports.
00084         for (size_t i = 0; i < count; ++i) {
00085             in.ensureBytes(2);
00086             const boost::uint16_t id = in.read_u16();
00087 
00088             if (!id) continue;
00089 
00090             std::string symbolName;
00091             in.read_string(symbolName);
00092 
00093             IF_VERBOSE_PARSE (
00094                 log_parse(_("  export: id = %d, name = %s"), id, symbolName);
00095             );
00096 
00097             // Register export with global map
00098             m.registerExport(symbolName, id);
00099 
00100             // Store export for later execution.
00101             _exports.push_back(symbolName);
00102         }
00103 
00104     }
00105 
00106 private:
00107 
00108     Exports _exports;
00109 
00110 };
00111 
00112 } // namespace SWF
00113 } // namespace gnash
00114 
00115 #endif

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