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
Definition: GnashKey.h:147
void setCache(const as_value &v)
Set internal cached value of this property.
Definition: Property.cpp:172
Holder for getter/setter functions.
Definition: Property.h:44
SWFStream & s
Definition: DefineBitsTag.cpp:73
Property(const ObjectURI &uri, as_function *getter, as_function *setter, const PropFlags &flags, bool destroy=false)
Definition: Property.h:300
ActionScript value type.
Definition: as_value.h:95
Property(const ObjectURI &uri, const as_value &value, const PropFlags &flags)
Definition: Property.h:291
as_value(* as_c_function_ptr)(const fn_call &fn)
Definition: Property.h:34
An abstract property.
Definition: Property.h:275
DSOTEXPORT as_value getValue(const as_object &this_ptr) const
Get value of this property.
Definition: Property.cpp:98
Definition: GnashKey.h:131
GetterSetter(as_c_function_ptr getter, as_c_function_ptr setter)
Construct a native getter-setter.
Definition: Property.h:132
Flags defining the level of protection of a member.
Definition: PropFlags.h:28
as_value getCache() const
Get the cache value (for user-defined getter-setters)
Definition: Property.h:155
The base class for all ActionScript objects.
Definition: as_object.h:161
bool isGetterSetter() const
Is this a getter/setter property?
Definition: Property.h:385
void setCache(const as_value &v)
Set the cache value (for user-defined getter-setters)
Definition: Property.h:150
bool get_visible(int swfVersion) const
Get version-based visibility.
Definition: PropFlags.h:99
A URI for describing as_objects.
Definition: ObjectURI.h:44
as_value get(fn_call &fn) const
Invoke the getter.
Definition: Property.h:138
Definition: GnashKey.h:166
void setReachable() const
Mark this property as being reachable (for the GC)
Definition: Property.h:398
bool visible(const Property &prop, int version)
Is this member supposed to be visible by a VM of given version ?
Definition: Property.h:431
bool setValue(as_object &this_ptr, const as_value &value) const
Set value of this property.
Definition: Property.cpp:133
Property(const ObjectURI &uri, as_c_function_ptr getter, as_c_function_ptr setter, const PropFlags &flags, bool destroy=false)
Definition: Property.h:310
as_value getCache() const
Get internal cached value of this property.
Definition: Property.cpp:127
tuple v
Definition: test.py:11
const FillStyle::Fill & _a
Definition: FillStyle.cpp:59
bool readOnly(const Property &prop)
is this a read-only member ?
Definition: Property.h:425
void set(const fn_call &fn)
Invoke the setter.
Definition: Property.h:144
const PropFlags & getFlags() const
accessor to the properties flags
Definition: Property.h:330
Property(const Property &p)
Copy constructor.
Definition: Property.h:321
Definition: GnashKey.h:132
bool test() const
Definition: PropFlags.h:94
void markReachableResources() const
Definition: Property.h:159
Definition: GnashKey.h:162
const ObjectURI & uri() const
The name-namespace pair (ObjectURI) of this Property.
Definition: Property.h:393
#define DSOTEXPORT
Definition: dsodefs.h:63
void clearVisible(int swfVersion)
Clear visibility flags.
Definition: Property.h:390
Definition: GnashKey.h:95
Parameters/environment for builtin or user-defined functions callable from ActionScript.
Definition: fn_call.h:107
Protect from assigning a value.
Definition: PropFlags.h:42
void setFlags(const PropFlags &flags) const
Set the flags of the property.
Definition: Property.h:333
void setReachable() const
Set any object value as reachable (for the GC)
Definition: as_value.cpp:692
ActionScript Function, either builtin or SWF-defined.
Definition: as_function.h:62
GetterSetter(as_function *getter, as_function *setter)
Construct a user-defined getter-setter.
Definition: Property.h:126
void clear_visible(int swfVersion)
Definition: PropFlags.h:108