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 (const std::string& the_export : _exports) {
57  const std::uint16_t id = mov->definition()->exportID(the_export);
58 
59  // We exported it, so we assume it is known.
60  assert(id);
61  mov->addCharacter(id);
62  }
63  }
64 
65 private:
66 
68  {
69  read(in, m);
70  }
71 
72  void read(SWFStream& in, movie_definition& m) {
73 
74  in.ensureBytes(2);
75  const std::uint16_t count = in.read_u16();
76 
78  log_parse(_(" export: count = %d"), count);
79  );
80 
81  // Read the exports.
82  for (size_t i = 0; i < count; ++i) {
83  in.ensureBytes(2);
84  const std::uint16_t id = in.read_u16();
85 
86  if (!id) continue;
87 
88  std::string symbolName;
89  in.read_string(symbolName);
90 
92  log_parse(_(" export: id = %d, name = %s"), id, symbolName);
93  );
94 
95  // Register export with global map
96  m.registerExport(symbolName, id);
97 
98  // Store export for later execution.
99  _exports.push_back(symbolName);
100  }
101 
102  }
103 
104 private:
105 
106  Exports _exports;
107 
108 };
109 
110 } // namespace SWF
111 } // namespace gnash
112 
113 #endif
virtual void registerExport(const std::string &, std::uint16_t)
Register a symbol to refer to a character id.
Definition: movie_definition.h:390
virtual void addCharacter(std::uint16_t)
Add a character to the list of known characters.
Definition: Movie.h:97
std::uint16_t read_u16()
Read a aligned unsigned 16-bit value from the stream.
Definition: SWFStream.cpp:332
Client program&#39;s interface to the definition of a movie or sprite.
Definition: movie_definition.h:95
A MovieClip is a container for DisplayObjects.
Definition: MovieClip.h:83
static void loader(SWFStream &in, TagType tag, movie_definition &m, const RunResources &)
Definition: ExportAssetsTag.h:43
void read_string(std::string &to)
Reads a null-terminated string from the given file and assigns it to the given std::string, overriding any previous value of it.
Definition: SWFStream.cpp:395
TagType
SWF tag types. Symbolic names copied from Ming.
Definition: SWF.h:30
virtual Movie * get_root() const
Return the relative root of this DisplayObject.
Definition: MovieClip.cpp:2049
virtual const movie_definition * definition() const =0
A top-level, standalone Movie that can be loaded and played.
Definition: Movie.h:46
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
Definition: SWF.h:86
#define IF_VERBOSE_PARSE(x)
Definition: log.h:378
Control tags are swf tags that control the operation of the movie.
Definition: ControlTag.h:43
void log_parse(StringType msg, Args... args)
Definition: log.h:313
Definition: ExportAssetsTag.h:36
virtual std::uint16_t exportID(const std::string &) const
Get the id that corresponds to a symbol.
Definition: movie_definition.h:396
Definition: GnashKey.h:166
#define _(String)
Definition: log.h:44
std::vector< std::string > Exports
Definition: ExportAssetsTag.h:40
Class to group together per-run and external resources for Gnash.
Definition: RunResources.h:53
virtual void executeState(MovieClip *m, DisplayList &) const
Execute "state" or "DisplayList" tags.
Definition: ExportAssetsTag.h:54
Definition: GnashKey.h:155
Definition: GnashKey.h:159
virtual void addControlTag(boost::intrusive_ptr< SWF::ControlTag >)
Add an ControlTag to this movie_definition&#39;s playlist.
Definition: movie_definition.h:273
A list of on-stage DisplayObjects, ordered by depth.
Definition: DisplayList.h:64
Definition: GnashKey.h:331
SWF stream wrapper class.
Definition: SWFStream.h:58
void ensureBytes(unsigned long needed)
Ensure the requested number of bytes are available for an aligned read in the currently opened tag...
Definition: SWFStream.cpp:50