2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011 Free Software Foundation, Inc
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.
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.
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
19 #ifndef GNASH_AS_PROP_FLAGS_H
20 #define GNASH_AS_PROP_FLAGS_H
23 #include <boost/cstdint.hpp>
27 /// Flags defining the level of protection of a member
35 /// Protect from enumeration
36 dontEnum
= 1 << 0, // 1
38 /// Protect from deletion
39 dontDelete
= 1 << 1, // 2
41 /// Protect from assigning a value
42 readOnly
= 1 << 2, // 4
44 /// Only visible by VM initialized for version 6 or higher
45 onlySWF6Up
= 1 << 7, // 128
47 /// Ignore in SWF6-initialized VM
48 ignoreSWF6
= 1 << 8, // 256
50 /// Only visible by VM initialized for version 7 or higher
51 onlySWF7Up
= 1 << 10, // 1024
53 /// Only visible by VM initialized for version 8 or higher
54 onlySWF8Up
= 1 << 12, // 4096
56 /// Only visible by VM initialized for version 9 or higher
57 onlySWF9Up
= 1 << 13 // 8192
61 /// Default constructor
69 PropFlags(const bool read_only
, const bool dont_delete
,
72 _flags(((read_only
) ? readOnly
: 0) |
73 ((dont_delete
) ? dontDelete
: 0) |
74 ((dont_enum
) ? dontEnum
: 0))
78 /// Constructor, from numerical value
79 PropFlags(boost::uint16_t flags
)
85 bool operator==(const PropFlags
& o
) const {
86 return (_flags
== o
._flags
);
89 bool operator!=(const PropFlags
& o
) const {
98 /// Get version-based visibility
99 bool get_visible(int swfVersion
) const {
100 if (test
<onlySWF6Up
>() && swfVersion
< 6) return false;
101 if (test
<ignoreSWF6
>() && swfVersion
== 6) return false;
102 if (test
<onlySWF7Up
>() && swfVersion
< 7) return false;
103 if (test
<onlySWF8Up
>() && swfVersion
< 8) return false;
104 if (test
<onlySWF9Up
>() && swfVersion
< 9) return false;
108 void clear_visible(int swfVersion
) {
109 if (swfVersion
== 6) {
110 // version 6, so let's forget onlySWF7Up flag!
111 // we will still set the value though, even if that flag is set
112 _flags
&= ~(onlySWF6Up
|ignoreSWF6
|onlySWF8Up
|onlySWF9Up
);
115 _flags
&= ~(onlySWF6Up
|ignoreSWF6
|onlySWF7Up
|onlySWF8Up
|onlySWF9Up
);
119 /// accessor to the numerical flags value
120 boost::uint16_t get_flags() const { return _flags
; }
122 /// set the numerical flags value (return the new value )
123 /// If unlocked is false, you cannot un-protect from over-write,
124 /// you cannot un-protect from deletion and you cannot
125 /// un-hide from the for..in loop construct
127 /// @param setTrue the set of flags to set
128 /// @param setFalse the set of flags to clear
129 /// @return true on success, false on failure (is protected)
130 bool set_flags(boost::uint16_t setTrue
, boost::uint16_t setFalse
= 0) {
139 boost::uint16_t _flags
;
144 operator<<(std::ostream
& os
, const PropFlags
& fl
)
147 if (fl
.test
<PropFlags::readOnly
>()) os
<< " readonly";
148 if (fl
.test
<PropFlags::dontDelete
>()) os
<< " nodelete";
149 if (fl
.test
<PropFlags::dontEnum
>()) os
<< " noenum";
158 #endif // GNASH_AS_PROP_FLAGS_H