Gnash  0.8.11dev
as_environment.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 #ifndef GNASH_AS_ENVIRONMENT_H
20 #define GNASH_AS_ENVIRONMENT_H
21 
22 #include <string>
23 #include <vector>
24 #include <algorithm>
25 
26 #include "as_value.h"
27 #include "SafeStack.h"
28 
29 // Forward declarations
30 namespace gnash {
31  class DisplayObject;
32  class VM;
33  class Global_as;
34  class movie_root;
35  class string_table;
36 }
37 
38 namespace gnash {
39 
40 
42 //
46 //
50 {
51 public:
52 
54  typedef std::vector<as_object*> ScopeStack;
55 
56  as_environment(VM& vm);
57 
58  VM& getVM() const { return _vm; }
59 
60  DisplayObject* target() const { return _target; }
61 
63  //
68  if (!_original_target) _original_target = target;
69  _target = target;
70  }
71 
73  _original_target = target;
74  }
75 
76  DisplayObject* get_original_target() const { return _original_target; }
77 
78  // Reset target to its original value
79  void reset_target() { _target = _original_target; }
80 
82  void push(const as_value& val) {
83  _stack.push(val);
84  }
85 
88  try {
89  return _stack.pop();
90  }
91  catch (const StackException&) {
92  return as_value();
93  }
94 
96  //
101  as_value& top(size_t dist) const
102  try {
103  return _stack.top(dist);
104  }
105  catch (const StackException&) {
106  return undefVal;
107  }
108 
110  void drop(size_t count) {
111  // in case count > stack size, just drop all, forget about
112  // exceptions...
113  _stack.drop(std::min(count, _stack.size()));
114  }
115 
116  size_t stack_size() const { return _stack.size(); }
117 
119  //
121  void markReachableResources() const;
122 
124  //
126  int get_version() const;
127 
128 private:
129 
130  VM& _vm;
131 
133  SafeStack<as_value>& _stack;
134 
136  DisplayObject* _target;
137 
139  DisplayObject* _original_target;
140 
141  static as_value undefVal;
142 
143 };
144 
146 //
152 as_value getVariable(const as_environment& ctx, const std::string& varname,
153  const as_environment::ScopeStack& scope, as_object** retTarget = 0);
154 
156 //
161 //
166 void setVariable(const as_environment& ctx, const std::string& path,
167  const as_value& val, const as_environment::ScopeStack& scope);
168 
170 //
174 bool delVariable(const as_environment& ctx, const std::string& varname,
175  const as_environment::ScopeStack& scope);
176 
195 DSOEXPORT bool parsePath(const std::string& var_path, std::string& path,
196  std::string& var);
197 
199 //
201 //
203 //
207 DSOEXPORT as_object* findObject(const as_environment& ctx, const std::string& path,
208  const as_environment::ScopeStack* scope = 0);
209 
211 //
214 //
218 DisplayObject* findTarget(const as_environment& env, const std::string& path);
219 
220 inline VM&
222 {
223  return env.getVM();
224 }
225 
226 movie_root& getRoot(const as_environment& env);
227 string_table& getStringTable(const as_environment& env);
228 int getSWFVersion(const as_environment& env);
229 Global_as& getGlobal(const as_environment &env);
230 
231 } // namespace gnash
232 
233 #endif
234 
235 
236 // Local Variables:
237 // mode: C++
238 // indent-tabs-mode: t
239 // End: