Make automated FSCommand invocation tests show player-side output.
[gnash.git] / libcore / PropFlags.h
blob0b586e5d482441e39db5820cbbf9ec2d4549cc7a
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
19 #ifndef GNASH_AS_PROP_FLAGS_H
20 #define GNASH_AS_PROP_FLAGS_H
22 #include <ostream>
23 #include <cstdint>
25 namespace gnash {
27 /// Flags defining the level of protection of a member
28 class PropFlags
30 public:
32 /// Actual flags
33 enum Flags {
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
62 PropFlags()
64 _flags(0)
68 /// Constructor
69 PropFlags(const bool read_only, const bool dont_delete,
70 const bool dont_enum)
72 _flags(((read_only) ? readOnly : 0) |
73 ((dont_delete) ? dontDelete : 0) |
74 ((dont_enum) ? dontEnum : 0))
78 /// Constructor, from numerical value
79 PropFlags(std::uint16_t flags)
81 _flags(flags)
85 bool operator==(const PropFlags& o) const {
86 return (_flags == o._flags);
89 bool operator!=(const PropFlags& o) const {
90 return !(*this == o);
93 template<Flags f>
94 bool test() const {
95 return (_flags & f);
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;
105 return true;
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);
114 else {
115 _flags &= ~(onlySWF6Up|ignoreSWF6|onlySWF7Up|onlySWF8Up|onlySWF9Up);
119 /// accessor to the numerical flags value
120 std::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(std::uint16_t setTrue, std::uint16_t setFalse = 0) {
131 _flags &= ~setFalse;
132 _flags |= setTrue;
133 return true;
136 private:
138 /// Numeric flags
139 std::uint16_t _flags;
143 inline std::ostream&
144 operator<<(std::ostream& os, const PropFlags& fl)
146 os << "(";
147 if (fl.test<PropFlags::readOnly>()) os << " readonly";
148 if (fl.test<PropFlags::dontDelete>()) os << " nodelete";
149 if (fl.test<PropFlags::dontEnum>()) os << " noenum";
150 os << " )";
151 return os;
156 } // namespace gnash
158 #endif // GNASH_AS_PROP_FLAGS_H