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 <cassert>
25 #include "dsodefs.h"
26 
27 // Forward declarations
28 namespace gnash {
29  class DisplayObject;
30  class movie_root;
31 }
32 
33 namespace gnash {
34 
35 DisplayObject* findDisplayObjectByTarget(const std::string& target,
36  movie_root& mr);
37 
39 //
45 {
46 public:
47 
50  :
51  _ptr(sp),
52  _mr(&mr)
53  {
54  checkDangling();
55  }
56 
58  //
68  :
69  _mr(sp._mr)
70  {
71  sp.checkDangling();
72  _ptr = sp._ptr;
73  if (!_ptr) _tgt = sp._tgt;
74  }
75 
77  //
86  {
87  sp.checkDangling();
88  _ptr = sp._ptr;
89  if (!_ptr) _tgt = sp._tgt;
90  _mr = sp._mr;
91  return *this;
92  }
93 
95  //
98  DisplayObject* get(bool skipRebinding = false) const
99  {
100  if (skipRebinding) return _ptr;
101 
102  // set _ptr to NULL and _tgt to original target if destroyed
103  checkDangling();
104  if (_ptr) return _ptr;
105  return findDisplayObjectByTarget(_tgt, *_mr);
106  }
107 
110  std::string getTarget() const;
111 
113  //
119  bool isDangling() const
120  {
121  checkDangling();
122  return !_ptr;
123  }
124 
129  bool operator==(const CharacterProxy& sp) const
130  {
131  return get() == sp.get();
132  }
133 
135  //
139  void setReachable() const;
140 
141 private:
142 
145  DSOEXPORT void checkDangling() const;
146 
147  mutable DisplayObject* _ptr;
148 
149  mutable std::string _tgt;
150 
151  movie_root* _mr;
152 
153 };
154 
155 } // end namespace gnash
156 
157 #endif // GNASH_CHARACTER_PROXY_H
158 
std::string getTarget() const
bound one.
Definition: CharacterProxy.cpp:46
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:168
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
bool isDangling() const
Return true if this sprite is dangling.
Definition: CharacterProxy.h:119
CharacterProxy(DisplayObject *sp, movie_root &mr)
Construct a CharacterProxy pointing to the given sprite.
Definition: CharacterProxy.h:49
bool operator==(const CharacterProxy &sp) const
Two sprite_proxies are equal if they point to the same sprite.
Definition: CharacterProxy.h:129
void setReachable() const
Set the original sprite (if any) as reachable.
Definition: CharacterProxy.cpp:55
CharacterProxy & operator=(const CharacterProxy &sp)
Make this proxy a copy of the given one.
Definition: CharacterProxy.h:85
DisplayObject * findDisplayObjectByTarget(const std::string &tgtstr, movie_root &mr)
Definition: CharacterProxy.cpp:62
A proxy for DisplayObject pointers.
Definition: CharacterProxy.h:44
CharacterProxy(const CharacterProxy &sp)
Construct a copy of the given CharacterProxy.
Definition: CharacterProxy.h:67
#define DSOEXPORT
Definition: dsodefs.h:55
DisplayObject * get(bool skipRebinding=false) const
Get the pointed sprite, either original or rebound.
Definition: CharacterProxy.h:98
This class represents the 'Stage' and top-level movie.
Definition: movie_root.h:150