1 // CharacterProxy.h - rebindable DisplayObject reference, for Gnash
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
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.
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.
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
20 #ifndef GNASH_CHARACTER_PROXY_H
21 #define GNASH_CHARACTER_PROXY_H
26 // Forward declarations
34 DisplayObject
* findDisplayObjectByTarget(const std::string
& target
,
37 /// A proxy for DisplayObject pointers.
39 /// The proxy will store a pointer to a DisplayObject until the
40 /// DisplayObject is destroyed, in which case it will only store the original
41 /// target path of it and always use that for rebinding when needed.
47 /// Construct a CharacterProxy pointing to the given sprite
48 CharacterProxy(DisplayObject
* sp
, movie_root
& mr
)
56 /// Construct a copy of the given CharacterProxy
59 /// The CharacterProxy to make a copy of.
60 /// NOTE: if the given proxy is dangling, this proxy
61 /// will also be dangling. If you want to
62 /// create a non-dangling proxy you can
63 /// use the constructor taking a DisplayObject
64 /// as in CharacterProxy newProxy(oldProxy.get())
66 CharacterProxy(const CharacterProxy
& sp
)
72 if (!_ptr
) _tgt
= sp
._tgt
;
75 /// Make this proxy a copy of the given one
78 /// The CharacterProxy to make a copy of.
79 /// NOTE: if the given proxy is dangling, this proxy
80 /// will also be dangling. If you want to
81 /// create a non-dangling proxy you can
82 /// use the constructor taking a DisplayObject
83 /// as in CharacterProxy newProxy(oldProxy.get())
84 CharacterProxy
& operator=(const CharacterProxy
& sp
)
88 if (!_ptr
) _tgt
= sp
._tgt
;
93 /// Get the pointed sprite, either original or rebound
95 /// @return the currently bound sprite, NULL if none
97 DisplayObject
* get(bool skipRebinding
= false) const
99 if (skipRebinding
) return _ptr
;
101 // set _ptr to NULL and _tgt to original target if destroyed
103 if (_ptr
) return _ptr
;
104 return findDisplayObjectByTarget(_tgt
, *_mr
);
107 /// Get the sprite target, either current (if not dangling) or
109 std::string
getTarget() const;
111 /// Return true if this sprite is dangling
113 /// Dangling means that it doesn't have a pointer to the original
114 /// sprite anymore, not that it doesn't point to anything.
115 /// To know if it points to something or not use get(), which will
116 /// return NULL if it doesn't point to anyhing.
118 bool isDangling() const
125 /// Two sprite_proxies are equal if they point to the
128 bool operator==(const CharacterProxy
& sp
) const
130 return get() == sp
.get();
133 /// Set the original sprite (if any) as reachable
135 /// NOTE: if this value is dangling, we won't keep anything
138 void setReachable() const;
142 /// If we still have a sprite pointer check if it was destroyed
143 /// in which case we drop the pointer and only keep the target.
144 DSOEXPORT
void checkDangling() const;
146 mutable DisplayObject
* _ptr
;
148 mutable std::string _tgt
;
154 } // end namespace gnash
156 #endif // GNASH_CHARACTER_PROXY_H