Gnash  0.8.11dev
ExportAssetsTag.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 #ifndef GNASH_SWF_EXPORTASSETSTAG_H
20 #define GNASH_SWF_EXPORTASSETSTAG_H
21 
22 #include <vector>
23 #include <utility>
24 #include <string>
25 #include <memory>
26 
27 #include "ControlTag.h"
28 #include "Movie.h"
29 #include "MovieClip.h"
30 #include "SWFStream.h"
31 #include "log.h"
32 
33 namespace gnash {
34 namespace SWF {
35 
37 {
38 public:
39 
40  typedef std::vector<std::string> Exports;
41 
42  // Load an export tag (for exposing internal resources of m)
43  static void loader(SWFStream& in, TagType tag, movie_definition& m,
44  const RunResources& /*r*/)
45  {
46  assert(tag == SWF::EXPORTASSETS); // 56
47 
48  boost::intrusive_ptr<ControlTag> t(new ExportAssetsTag(in, m));
49  m.addControlTag(t);
50  }
51 
52 
53  // TODO: use Movie to store the actual exports.
54  virtual void executeState(MovieClip* m, DisplayList& /*l*/) const {
55  Movie* mov = m->get_root();
56  for (Exports::const_iterator it = _exports.begin(), e = _exports.end();
57  it != e; ++it) {
58  const boost::uint16_t id = mov->definition()->exportID(*it);
59 
60  // We exported it, so we assume it is known.
61  assert(id);
62  mov->addCharacter(id);
63  }
64  }
65 
66 private:
67 
69  {
70  read(in, m);
71  }
72 
73  void read(SWFStream& in, movie_definition& m) {
74 
75  in.ensureBytes(2);
76  const boost::uint16_t count = in.read_u16();
77 
79  log_parse(_(" export: count = %d"), count);
80  );
81 
82  // Read the exports.
83  for (size_t i = 0; i < count; ++i) {
84  in.ensureBytes(2);
85  const boost::uint16_t id = in.read_u16();
86 
87  if (!id) continue;
88 
89  std::string symbolName;
90  in.read_string(symbolName);
91 
93  log_parse(_(" export: id = %d, name = %s"), id, symbolName);
94  );
95 
96  // Register export with global map
97  m.registerExport(symbolName, id);
98 
99  // Store export for later execution.
100  _exports.push_back(symbolName);
101  }
102 
103  }
104 
105 private:
106 
107  Exports _exports;
108 
109 };
110 
111 } // namespace SWF
112 } // namespace gnash
113 
114 #endif