Gnash
0.8.10
|
00001 // CharacterProxy.h - rebindable DisplayObject reference, for Gnash 00002 // 00003 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 00004 // Free Software Foundation, Inc 00005 // 00006 // This program is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 3 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with this program; if not, write to the Free Software 00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 00020 #ifndef GNASH_CHARACTER_PROXY_H 00021 #define GNASH_CHARACTER_PROXY_H 00022 00023 #include <string> 00024 #include <cassert> 00025 #include "dsodefs.h" 00026 00027 // Forward declarations 00028 namespace gnash { 00029 class DisplayObject; 00030 class movie_root; 00031 } 00032 00033 namespace gnash { 00034 00035 DisplayObject* findDisplayObjectByTarget(const std::string& target, 00036 movie_root& mr); 00037 00039 // 00044 class CharacterProxy 00045 { 00046 public: 00047 00049 CharacterProxy(DisplayObject* sp, movie_root& mr) 00050 : 00051 _ptr(sp), 00052 _mr(&mr) 00053 { 00054 checkDangling(); 00055 } 00056 00058 // 00067 CharacterProxy(const CharacterProxy& sp) 00068 : 00069 _mr(sp._mr) 00070 { 00071 sp.checkDangling(); 00072 _ptr = sp._ptr; 00073 if (!_ptr) _tgt = sp._tgt; 00074 } 00075 00077 // 00085 CharacterProxy& operator=(const CharacterProxy& sp) 00086 { 00087 sp.checkDangling(); 00088 _ptr = sp._ptr; 00089 if (!_ptr) _tgt = sp._tgt; 00090 _mr = sp._mr; 00091 return *this; 00092 } 00093 00095 // 00098 DisplayObject* get(bool skipRebinding = false) const 00099 { 00100 if (skipRebinding) return _ptr; 00101 00102 // set _ptr to NULL and _tgt to original target if destroyed 00103 checkDangling(); 00104 if (_ptr) return _ptr; 00105 return findDisplayObjectByTarget(_tgt, *_mr); 00106 } 00107 00110 std::string getTarget() const; 00111 00113 // 00119 bool isDangling() const 00120 { 00121 checkDangling(); 00122 return !_ptr; 00123 } 00124 00129 bool operator==(const CharacterProxy& sp) const 00130 { 00131 return get() == sp.get(); 00132 } 00133 00135 // 00139 void setReachable() const; 00140 00141 private: 00142 00145 DSOEXPORT void checkDangling() const; 00146 00147 mutable DisplayObject* _ptr; 00148 00149 mutable std::string _tgt; 00150 00151 movie_root* _mr; 00152 00153 }; 00154 00155 } // end namespace gnash 00156 00157 #endif // GNASH_CHARACTER_PROXY_H 00158