Gnash  0.8.10
as_environment.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00003 //   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 "as_value.h" 
00027 #include "SafeStack.h"
00028 
00029 // Forward declarations
00030 namespace gnash {
00031     class DisplayObject;
00032     class VM;
00033     class Global_as;
00034     class movie_root;
00035     class string_table;
00036 }
00037 
00038 namespace gnash {
00039 
00040 
00042 //
00046 //
00049 class as_environment
00050 {
00051 public:
00052 
00054     typedef std::vector<as_object*> ScopeStack;
00055 
00056     as_environment(VM& vm);
00057 
00058     VM& getVM() const { return _vm; }
00059 
00060     DisplayObject* target() const { return _target; }
00061 
00063     //
00067     void set_target(DisplayObject* target) {
00068         if (!_original_target) _original_target = target;
00069         _target = target;
00070     }
00071 
00072     void set_original_target(DisplayObject* target) {
00073         _original_target = target;
00074     }
00075 
00076     DisplayObject* get_original_target() const { return _original_target; }
00077 
00078     // Reset target to its original value
00079     void reset_target() { _target = _original_target; }
00080 
00082     void push(const as_value& val) {
00083         _stack.push(val);
00084     }
00085 
00087     as_value pop()
00088     try {
00089         return _stack.pop();
00090     }
00091     catch (const StackException&) {
00092         return as_value();
00093     }
00094 
00096     //
00101     as_value& top(size_t dist) const 
00102     try {
00103         return _stack.top(dist);
00104     }
00105     catch (const StackException&) {
00106         return undefVal;
00107     }
00108 
00110     void drop(size_t count) {
00111         // in case count > stack size, just drop all, forget about
00112         // exceptions...
00113         _stack.drop(std::min(count, _stack.size()));
00114     }
00115 
00116     size_t stack_size() const { return _stack.size(); }
00117 
00119     //
00121     void markReachableResources() const;
00122     
00124     //
00126     int get_version() const;
00127 
00128 private:
00129 
00130     VM& _vm;
00131 
00133     SafeStack<as_value>& _stack;
00134 
00136     DisplayObject* _target;
00137 
00139     DisplayObject* _original_target;
00140 
00141     static as_value undefVal;
00142         
00143 };
00144 
00146 //
00152 as_value getVariable(const as_environment& ctx, const std::string& varname,
00153     const as_environment::ScopeStack& scope, as_object** retTarget = 0);
00154 
00156 //
00161 //
00166 void setVariable(const as_environment& ctx, const std::string& path,
00167     const as_value& val, const as_environment::ScopeStack& scope);
00168 
00170 //
00174 bool delVariable(const as_environment& ctx, const std::string& varname,
00175         const as_environment::ScopeStack& scope);
00176 
00195 bool parsePath(const std::string& var_path, std::string& path,
00196         std::string& var);
00197 
00199 //
00201 //
00203 //
00207 as_object* findObject(const as_environment& ctx, const std::string& path,
00208         const as_environment::ScopeStack* scope = 0);
00209 
00211 //
00214 //
00218 DisplayObject* findTarget(const as_environment& env, const std::string& path);
00219 
00220 inline VM&
00221 getVM(const as_environment& env)
00222 {
00223     return env.getVM();
00224 }
00225 
00226 movie_root& getRoot(const as_environment& env);
00227 string_table& getStringTable(const as_environment& env);
00228 int getSWFVersion(const as_environment& env);
00229 Global_as& getGlobal(const as_environment &env);
00230 
00231 } // namespace gnash
00232 
00233 #endif 
00234 
00235 
00236 // Local Variables:
00237 // mode: C++
00238 // indent-tabs-mode: t
00239 // End: