20 #ifndef GNASH_PROPERTY_H
21 #define GNASH_PROPERTY_H
23 #include <boost/variant.hpp>
25 #include <boost/bind.hpp>
45 class NativeGetterSetter;
56 template<
typename Arg,
typename S>
57 struct GetSetVisitor : boost::static_visitor<typename S::result_type>
59 GetSetVisitor(
const Arg& arg) : _arg(arg) {}
60 template<
typename T>
typename S::result_type operator()(
T&
t)
const {
70 typedef void result_type;
71 template<
typename T,
typename Arg>
72 result_type operator()(
T&
t, Arg&
a)
const {
81 template<
typename T,
typename Arg>
82 result_type operator()(
T&
t, Arg&
a)
const {
90 struct SetUnderlying : boost::static_visitor<>
93 result_type operator()(
T& gs,
const as_value& val)
const {
94 gs.setUnderlying(val);
96 result_type operator()(NativeGetterSetter&,
const as_value&)
const {}
102 struct GetUnderlying : boost::static_visitor<as_value>
105 result_type operator()(
const T& gs)
const {
106 return gs.getUnderlying();
108 result_type operator()(
const NativeGetterSetter&)
const {
109 return result_type();
114 struct MarkReachable : boost::static_visitor<>
117 result_type operator()(
const T& gs)
const {
118 gs.markReachableResources();
127 _getset(UserDefinedGetterSetter(getter, setter))
133 _getset(NativeGetterSetter(getter, setter))
138 GetSetVisitor<const fn_call, Get>
s(fn);
139 return boost::apply_visitor(s, _getset);
144 GetSetVisitor<fn_call, Set>
s(fn);
145 boost::apply_visitor(s, _getset);
150 boost::apply_visitor(boost::bind(SetUnderlying(),
_1, v), _getset);
155 return boost::apply_visitor(GetUnderlying(), _getset);
159 boost::apply_visitor(MarkReachable(), _getset);
165 class UserDefinedGetterSetter
174 _beingAccessed(false)
178 as_value
get(
const fn_call& fn)
const;
181 void set(
const fn_call& fn);
184 const as_value& getUnderlying()
const {
return _underlyingValue; }
187 void setUnderlying(
const as_value&
v) { _underlyingValue =
v; }
199 class ScopedLock : boost::noncopyable
203 explicit ScopedLock(
const UserDefinedGetterSetter& na)
206 _obtainedLock(
_a._beingAccessed ? false : true)
210 if (_obtainedLock)
_a._beingAccessed =
true;
213 ~ScopedLock() {
if ( _obtainedLock)
_a._beingAccessed =
false; }
221 bool obtainedLock()
const {
return _obtainedLock; }
225 const UserDefinedGetterSetter&
_a;
230 as_function* _getter;
231 as_function* _setter;
232 as_value _underlyingValue;
233 mutable bool _beingAccessed;
237 class NativeGetterSetter
243 _getter(
get), _setter(
set) {}
246 as_value
get(
const fn_call& fn)
const {
251 void set(
const fn_call& fn) {
263 boost::variant<UserDefinedGetterSetter, NativeGetterSetter> _getset;
278 struct SetReachable : boost::static_visitor<>
280 result_type operator()(
const as_value& val)
const {
301 const PropFlags& flags,
bool destroy =
false)
306 _destructive(destroy)
311 bool destroy =
false)
316 _destructive(destroy)
325 _destructive(p._destructive)
398 return boost::apply_visitor(SetReachable(), _bound);
404 typedef boost::variant<as_value, GetterSetter> BoundType;
407 mutable BoundType _bound;
418 mutable bool _destructive;
436 #endif // GNASH_PROPERTY_H