1 // CharacterProxy.h - rebindable DisplayObject reference, for Gnash
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
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
27 // Forward declarations
35 DisplayObject
* findDisplayObjectByTarget(const std::string
& target
,
38 /// A proxy for DisplayObject pointers.
40 /// The proxy will store a pointer to a DisplayObject until the
41 /// DisplayObject is destroyed, in which case it will only store the original
42 /// target path of it and always use that for rebinding when needed.
48 /// Construct a CharacterProxy pointing to the given sprite
49 CharacterProxy(DisplayObject
* sp
, movie_root
& mr
)
57 /// Construct a copy of the given CharacterProxy
60 /// The CharacterProxy to make a copy of.
61 /// NOTE: if the given proxy is dangling, this proxy
62 /// will also be dangling. If you want to
63 /// create a non-dangling proxy you can
64 /// use the constructor taking a DisplayObject
65 /// as in CharacterProxy newProxy(oldProxy.get())
67 CharacterProxy(const CharacterProxy
& sp
)
73 if (!_ptr
) _tgt
= sp
._tgt
;
76 /// Make this proxy a copy of the given one
79 /// The CharacterProxy to make a copy of.
80 /// NOTE: if the given proxy is dangling, this proxy
81 /// will also be dangling. If you want to
82 /// create a non-dangling proxy you can
83 /// use the constructor taking a DisplayObject
84 /// as in CharacterProxy newProxy(oldProxy.get())
85 CharacterProxy
& operator=(const CharacterProxy
& sp
)
89 if (!_ptr
) _tgt
= sp
._tgt
;
94 /// Get the pointed sprite, either original or rebound
96 /// @return the currently bound sprite, NULL if none
98 DisplayObject
* get(bool skipRebinding
= false) const
100 if (skipRebinding
) return _ptr
;
102 // set _ptr to NULL and _tgt to original target if destroyed
104 if (_ptr
) return _ptr
;
105 return findDisplayObjectByTarget(_tgt
, *_mr
);
108 /// Get the sprite target, either current (if not dangling) or
110 std::string
getTarget() const;
112 /// Return true if this sprite is dangling
114 /// Dangling means that it doesn't have a pointer to the original
115 /// sprite anymore, not that it doesn't point to anything.
116 /// To know if it points to something or not use get(), which will
117 /// return NULL if it doesn't point to anyhing.
119 bool isDangling() const
126 /// Two sprite_proxies are equal if they point to the
129 bool operator==(const CharacterProxy
& sp
) const
131 return get() == sp
.get();
134 /// Set the original sprite (if any) as reachable
136 /// NOTE: if this value is dangling, we won't keep anything
139 void setReachable() const;
143 /// If we still have a sprite pointer check if it was destroyed
144 /// in which case we drop the pointer and only keep the target.
145 DSOEXPORT
void checkDangling() const;
147 mutable DisplayObject
* _ptr
;
149 mutable std::string _tgt
;
155 } // end namespace gnash
157 #endif // GNASH_CHARACTER_PROXY_H