• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

as_environment.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   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 "smart_ptr.h" // GNASH_USE_GC
00023 #include "as_value.h" // for composition (vector + frame_slot)
00024 #include "SafeStack.h"
00025 
00026 #include <string> // for frame_slot name
00027 #include <vector>
00028 
00029 namespace gnash {
00030 
00031 // Forward declarations
00032 class DisplayObject;
00033 class VM;
00034 class Global_as;
00035 class movie_root;
00036 class string_table;
00037 class UserFunction;
00038 
00040 class as_environment
00041 {
00042 
00043 public:
00044 
00046     typedef std::vector<as_object*> ScopeStack;
00047 
00048     as_environment(VM& vm);
00049 
00050     VM& getVM() const { return _vm; }
00051 
00052     DisplayObject* get_target() const { return m_target; }
00053 
00055     //
00061     void set_target(DisplayObject* target);
00062 
00063     void set_original_target(DisplayObject* target) {
00064         _original_target = target;
00065     }
00066 
00067     DisplayObject* get_original_target() { return _original_target; }
00068 
00069     // Reset target to its original value
00070     void reset_target() { m_target = _original_target; }
00071 
00073     void push(const as_value& val) {
00074         _stack.push(val);
00075     }
00076 
00078     as_value pop()
00079     {
00080         try {
00081             return _stack.pop();
00082         } catch (StackException&) {
00083             return undefVal;
00084         }
00085     }
00086 
00088     //
00093     as_value& top(size_t dist)
00094     {
00095         try {
00096             return _stack.top(dist);
00097         } catch (StackException&) {
00098             return undefVal;
00099         }
00100     }
00101 
00103     //
00108     as_value& bottom(size_t index) const
00109     {
00110         try {
00111             return _stack.value(index);
00112         } catch (StackException&) {
00113             return undefVal;
00114         }
00115     }
00116 
00118     void drop(size_t count)
00119     {
00120         // in case count > stack size, just drop all, forget about
00121         // exceptions...
00122         _stack.drop(std::min(count, _stack.size()));
00123     }
00124 
00125     size_t stack_size() const { return _stack.size(); }
00126 
00130     //
00141     bool delVariableRaw(const std::string& varname,
00142             const ScopeStack& scopeStack);
00143 
00145     //
00161     as_value get_variable(const std::string& varname,
00162         const ScopeStack& scopeStack, as_object** retTarget=NULL) const;
00163 
00166     //
00182     void set_variable(const std::string& path, const as_value& val,
00183         const ScopeStack& scopeStack);
00184 
00185 #ifdef GNASH_USE_GC
00186 
00187     //
00192     void markReachableResources() const;
00193 #endif
00194 
00196     //
00200     DisplayObject* find_target(const std::string& path) const;
00201 
00203     //
00207     as_object* find_object(const std::string& path,
00208             const ScopeStack* scopeStack = 0) const;
00209     
00211     //
00216     int get_version() const;
00217 
00218 private:
00219 
00220     VM& _vm;
00221 
00223     SafeStack<as_value>& _stack;
00224 
00226     DisplayObject* m_target;
00227 
00229     DisplayObject* _original_target;
00230 
00232     //
00242     void set_variable_raw(const std::string& path, const as_value& val,
00243         const ScopeStack& scopeStack);
00244 
00251     as_value get_variable_raw(const std::string& varname,
00252         const ScopeStack& scopeStack, as_object** retTarget=NULL) const;
00253 
00254     static as_value undefVal;
00255         
00256 };
00257 
00277 bool parsePath(const std::string& var_path, std::string& path,
00278         std::string& var);
00279 
00280 inline VM&
00281 getVM(const as_environment& env)
00282 {
00283     return env.getVM();
00284 }
00285 
00286 movie_root& getRoot(const as_environment& env);
00287 string_table& getStringTable(const as_environment& env);
00288 int getSWFVersion(const as_environment& env);
00289 Global_as& getGlobal(const as_environment &env);
00290 
00291 } // end namespace gnash
00292 
00293 
00294 #endif // GNASH_AS_ENVIRONMENT_H
00295 
00296 
00297 // Local Variables:
00298 // mode: C++
00299 // indent-tabs-mode: t
00300 // End:

Generated on Fri Mar 16 2012 15:46:08 for Gnash by  doxygen 1.7.1