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