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 
gnash::CharacterProxy
A proxy for DisplayObject pointers.
Definition: CharacterProxy.h:44
gnash::DisplayObject::getOrigTarget
const std::string & getOrigTarget() const
Definition: DisplayObject.h:829
movie_root.h
gnash::CharacterProxy::get
DisplayObject * get(bool skipRebinding=false) const
Get the pointed sprite, either original or rebound.
Definition: CharacterProxy.h:97
gnash::findDisplayObjectByTarget
DisplayObject * findDisplayObjectByTarget(const std::string &tgtstr, movie_root &mr)
Definition: CharacterProxy.cpp:62
dsodefs.h
gnash::movie_root::findCharacterByTarget
DisplayObject * findCharacterByTarget(const std::string &tgtstr) const
Definition: movie_root.cpp:2142
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
gnash::typeName
std::string typeName(const T &inst)
Definition: utility.h:93
gnash::DisplayObject::isDestroyed
bool isDestroyed() const
Return true if this DisplayObject was destroyed.
Definition: DisplayObject.h:807
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::CharacterProxy::operator=
CharacterProxy & operator=(const CharacterProxy &sp)
Make this proxy a copy of the given one.
Definition: CharacterProxy.h:84
utility.h
gnash::DisplayObject::getTarget
std::string DSOEXPORT getTarget() const
Return full path to this object, in dot notation.
Definition: DisplayObject.cpp:621
gnash::CharacterProxy::CharacterProxy
CharacterProxy(const CharacterProxy &sp)
Construct a copy of the given CharacterProxy.
Definition: CharacterProxy.h:66
gnash::CharacterProxy::CharacterProxy
CharacterProxy(DisplayObject *sp, movie_root &mr)
Construct a CharacterProxy pointing to the given sprite.
Definition: CharacterProxy.h:48
VM.h
DisplayObject.h
gnash::CharacterProxy::operator==
bool operator==(const CharacterProxy &sp) const
Two sprite_proxies are equal if they point to the same sprite.
Definition: CharacterProxy.h:128
gnash::movie_root
This class represents the 'Stage' and top-level movie.
Definition: movie_root.h:151
DSOEXPORT
#define DSOEXPORT
Definition: dsodefs.h:55
gnash::DisplayObject
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:169
gnash::CharacterProxy::setReachable
void setReachable() const
Set the original sprite (if any) as reachable.
Definition: CharacterProxy.cpp:55
gnash::CharacterProxy::getTarget
std::string getTarget() const
bound one.
Definition: CharacterProxy.cpp:46
CharacterProxy.h
gnash::CharacterProxy::isDangling
bool isDangling() const
Return true if this sprite is dangling.
Definition: CharacterProxy.h:118
gnash::GcResource::setReachable
void setReachable() const
Mark this resource as being reachable.
Definition: GC.h:92