20 #ifndef GNASH_PROPERTY_H
21 #define GNASH_PROPERTY_H
23 #include <boost/variant.hpp>
25 #include <boost/bind.hpp>
46 class NativeGetterSetter;
57 template<
typename Arg,
typename S>
58 struct GetSetVisitor : boost::static_visitor<typename S::result_type>
60 GetSetVisitor(
const Arg& arg) : _arg(arg) {}
61 template<
typename T>
typename S::result_type operator()(
T&
t)
const {
71 typedef void result_type;
72 template<
typename T,
typename Arg>
73 result_type operator()(
T&
t, Arg&
a)
const {
82 template<
typename T,
typename Arg>
83 result_type operator()(
T&
t, Arg&
a)
const {
91 struct SetUnderlying : boost::static_visitor<>
94 result_type operator()(
T& gs,
const as_value& val)
const {
95 gs.setUnderlying(val);
97 result_type operator()(NativeGetterSetter&,
const as_value&)
const {}
103 struct GetUnderlying : boost::static_visitor<as_value>
106 result_type operator()(
const T& gs)
const {
107 return gs.getUnderlying();
109 result_type operator()(
const NativeGetterSetter&)
const {
110 return result_type();
115 struct MarkReachable : boost::static_visitor<>
118 result_type operator()(
const T& gs)
const {
119 gs.markReachableResources();
128 _getset(UserDefinedGetterSetter(getter, setter))
134 _getset(NativeGetterSetter(getter, setter))
139 GetSetVisitor<const fn_call, Get>
s(fn);
140 return boost::apply_visitor(s, _getset);
145 GetSetVisitor<fn_call, Set>
s(fn);
146 boost::apply_visitor(s, _getset);
151 boost::apply_visitor(boost::bind(SetUnderlying(),
_1, v), _getset);
156 return boost::apply_visitor(GetUnderlying(), _getset);
160 boost::apply_visitor(MarkReachable(), _getset);
166 class UserDefinedGetterSetter
175 _beingAccessed(false)
179 as_value
get(
const fn_call& fn)
const;
182 void set(
const fn_call& fn);
185 const as_value& getUnderlying()
const {
return _underlyingValue; }
188 void setUnderlying(
const as_value&
v) { _underlyingValue =
v; }
200 class ScopedLock : boost::noncopyable
204 explicit ScopedLock(
const UserDefinedGetterSetter& na)
207 _obtainedLock(
_a._beingAccessed ? false : true)
211 if (_obtainedLock)
_a._beingAccessed =
true;
214 ~ScopedLock() {
if ( _obtainedLock)
_a._beingAccessed =
false; }
222 bool obtainedLock()
const {
return _obtainedLock; }
226 const UserDefinedGetterSetter&
_a;
231 as_function* _getter;
232 as_function* _setter;
233 as_value _underlyingValue;
234 mutable bool _beingAccessed;
238 class NativeGetterSetter
244 _getter(
get), _setter(
set) {}
247 as_value
get(
const fn_call& fn)
const {
252 void set(
const fn_call& fn) {
264 boost::variant<UserDefinedGetterSetter, NativeGetterSetter> _getset;
279 struct SetReachable : boost::static_visitor<>
281 result_type operator()(
const as_value& val)
const {
302 const PropFlags& flags,
bool destroy =
false)
307 _destructive(destroy)
312 bool destroy =
false)
317 _destructive(destroy)
326 _destructive(p._destructive)
399 return boost::apply_visitor(SetReachable(), _bound);
405 typedef boost::variant<as_value, GetterSetter> BoundType;
408 mutable BoundType _bound;
419 mutable bool _destructive;
437 #endif // GNASH_PROPERTY_H