Gnash 0.8.9
|
00001 // 00002 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 00003 // 2011 Free Software Foundation, Inc 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 00019 #ifndef GNASH_AS_ENVIRONMENT_H 00020 #define GNASH_AS_ENVIRONMENT_H 00021 00022 #include <string> 00023 #include <vector> 00024 #include <algorithm> 00025 00026 #include "smart_ptr.h" 00027 #include "as_value.h" 00028 #include "SafeStack.h" 00029 00030 // Forward declarations 00031 namespace gnash { 00032 class DisplayObject; 00033 class VM; 00034 class Global_as; 00035 class movie_root; 00036 class string_table; 00037 } 00038 00039 namespace gnash { 00040 00041 00043 // 00047 // 00050 class as_environment 00051 { 00052 public: 00053 00055 typedef std::vector<as_object*> ScopeStack; 00056 00057 as_environment(VM& vm); 00058 00059 VM& getVM() const { return _vm; } 00060 00061 DisplayObject* target() const { return _target; } 00062 00064 // 00068 void set_target(DisplayObject* target) { 00069 if (!_original_target) _original_target = target; 00070 _target = target; 00071 } 00072 00073 void set_original_target(DisplayObject* target) { 00074 _original_target = target; 00075 } 00076 00077 DisplayObject* get_original_target() const { return _original_target; } 00078 00079 // Reset target to its original value 00080 void reset_target() { _target = _original_target; } 00081 00083 void push(const as_value& val) { 00084 _stack.push(val); 00085 } 00086 00088 as_value pop() 00089 try { 00090 return _stack.pop(); 00091 } 00092 catch (const StackException&) { 00093 return as_value(); 00094 } 00095 00097 // 00102 as_value& top(size_t dist) const 00103 try { 00104 return _stack.top(dist); 00105 } 00106 catch (const StackException&) { 00107 return undefVal; 00108 } 00109 00111 void drop(size_t count) { 00112 // in case count > stack size, just drop all, forget about 00113 // exceptions... 00114 _stack.drop(std::min(count, _stack.size())); 00115 } 00116 00117 size_t stack_size() const { return _stack.size(); } 00118 00120 // 00122 void markReachableResources() const; 00123 00125 // 00127 int get_version() const; 00128 00129 private: 00130 00131 VM& _vm; 00132 00134 SafeStack<as_value>& _stack; 00135 00137 DisplayObject* _target; 00138 00140 DisplayObject* _original_target; 00141 00142 static as_value undefVal; 00143 00144 }; 00145 00147 // 00153 as_value getVariable(const as_environment& ctx, const std::string& varname, 00154 const as_environment::ScopeStack& scope, as_object** retTarget = 0); 00155 00157 // 00162 // 00167 void setVariable(const as_environment& ctx, const std::string& path, 00168 const as_value& val, const as_environment::ScopeStack& scope); 00169 00171 // 00175 bool delVariable(const as_environment& ctx, const std::string& varname, 00176 const as_environment::ScopeStack& scope); 00177 00196 bool parsePath(const std::string& var_path, std::string& path, 00197 std::string& var); 00198 00200 // 00202 // 00204 // 00208 as_object* findObject(const as_environment& ctx, const std::string& path, 00209 const as_environment::ScopeStack* scope = 0); 00210 00212 // 00215 // 00219 DisplayObject* findTarget(const as_environment& env, const std::string& path); 00220 00221 inline VM& 00222 getVM(const as_environment& env) 00223 { 00224 return env.getVM(); 00225 } 00226 00227 movie_root& getRoot(const as_environment& env); 00228 string_table& getStringTable(const as_environment& env); 00229 int getSWFVersion(const as_environment& env); 00230 Global_as& getGlobal(const as_environment &env); 00231 00232 } // namespace gnash 00233 00234 #endif 00235 00236 00237 // Local Variables: 00238 // mode: C++ 00239 // indent-tabs-mode: t 00240 // End: