Gnash  0.8.11dev
CharacterProxy.h
Go to the documentation of this file.
1 // CharacterProxy.h - rebindable DisplayObject reference, for Gnash
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 #ifndef GNASH_CHARACTER_PROXY_H
21 #define GNASH_CHARACTER_PROXY_H
22 
23 #include <string>
24 #include "dsodefs.h"
25 
26 // Forward declarations
27 namespace gnash {
28  class DisplayObject;
29  class movie_root;
30 }
31 
32 namespace gnash {
33 
34 DisplayObject* findDisplayObjectByTarget(const std::string& target,
35  movie_root& mr);
36 
38 //
44 {
45 public:
46 
49  :
50  _ptr(sp),
51  _mr(&mr)
52  {
53  checkDangling();
54  }
55 
57  //
67  :
68  _mr(sp._mr)
69  {
70  sp.checkDangling();
71  _ptr = sp._ptr;
72  if (!_ptr) _tgt = sp._tgt;
73  }
74 
76  //
85  {
86  sp.checkDangling();
87  _ptr = sp._ptr;
88  if (!_ptr) _tgt = sp._tgt;
89  _mr = sp._mr;
90  return *this;
91  }
92 
94  //
97  DisplayObject* get(bool skipRebinding = false) const
98  {
99  if (skipRebinding) return _ptr;
100 
101  // set _ptr to NULL and _tgt to original target if destroyed
102  checkDangling();
103  if (_ptr) return _ptr;
104  return findDisplayObjectByTarget(_tgt, *_mr);
105  }
106 
109  std::string getTarget() const;
110 
112  //
118  bool isDangling() const
119  {
120  checkDangling();
121  return !_ptr;
122  }
123 
128  bool operator==(const CharacterProxy& sp) const
129  {
130  return get() == sp.get();
131  }
132 
134  //
138  void setReachable() const;
139 
140 private:
141 
144  DSOEXPORT void checkDangling() const;
145 
146  mutable DisplayObject* _ptr;
147 
148  mutable std::string _tgt;
149 
150  movie_root* _mr;
151 
152 };
153 
154 } // end namespace gnash
155 
156 #endif // GNASH_CHARACTER_PROXY_H
157 
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:168
bool isDangling() const
Return true if this sprite is dangling.
Definition: CharacterProxy.h:118
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
CharacterProxy(DisplayObject *sp, movie_root &mr)
Construct a CharacterProxy pointing to the given sprite.
Definition: CharacterProxy.h:48
CharacterProxy & operator=(const CharacterProxy &sp)
Make this proxy a copy of the given one.
Definition: CharacterProxy.h:84
DisplayObject * findDisplayObjectByTarget(const std::string &tgtstr, movie_root &mr)
Definition: CharacterProxy.cpp:62
A proxy for DisplayObject pointers.
Definition: CharacterProxy.h:43
CharacterProxy(const CharacterProxy &sp)
Construct a copy of the given CharacterProxy.
Definition: CharacterProxy.h:66
bool operator==(const CharacterProxy &sp) const
Two sprite_proxies are equal if they point to the same sprite.
Definition: CharacterProxy.h:128
#define DSOEXPORT
Definition: dsodefs.h:55
std::string getTarget() const
bound one.
Definition: CharacterProxy.cpp:46
void setReachable() const
Set the original sprite (if any) as reachable.
Definition: CharacterProxy.cpp:55
DisplayObject * get(bool skipRebinding=false) const
Get the pointed sprite, either original or rebound.
Definition: CharacterProxy.h:97
This class represents the &#39;Stage&#39; and top-level movie.
Definition: movie_root.h:150