Gnash  0.8.11dev
PropFlags.h
Go to the documentation of this file.
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
18 
19 #ifndef GNASH_AS_PROP_FLAGS_H
20 #define GNASH_AS_PROP_FLAGS_H
21 
22 #include <ostream>
23 #include <cstdint>
24 
25 namespace gnash {
26 
28 class PropFlags
29 {
30 public:
31 
33  enum Flags {
34 
36  dontEnum = 1 << 0, // 1
37 
39  dontDelete = 1 << 1, // 2
40 
42  readOnly = 1 << 2, // 4
43 
45  onlySWF6Up = 1 << 7, // 128
46 
48  ignoreSWF6 = 1 << 8, // 256
49 
51  onlySWF7Up = 1 << 10, // 1024
52 
54  onlySWF8Up = 1 << 12, // 4096
55 
57  onlySWF9Up = 1 << 13 // 8192
58 
59  };
60 
63  :
64  _flags(0)
65  {
66  }
67 
69  PropFlags(const bool read_only, const bool dont_delete,
70  const bool dont_enum)
71  :
72  _flags(((read_only) ? readOnly : 0) |
73  ((dont_delete) ? dontDelete : 0) |
74  ((dont_enum) ? dontEnum : 0))
75  {
76  }
77 
79  PropFlags(std::uint16_t flags)
80  :
81  _flags(flags)
82  {
83  }
84 
85  bool operator==(const PropFlags& o) const {
86  return (_flags == o._flags);
87  }
88 
89  bool operator!=(const PropFlags& o) const {
90  return !(*this == o);
91  }
92 
93  template<Flags f>
94  bool test() const {
95  return (_flags & f);
96  }
97 
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;
106  }
107 
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
113  }
114  else {
116  }
117  }
118 
120  std::uint16_t get_flags() const { return _flags; }
121 
130  bool set_flags(std::uint16_t setTrue, std::uint16_t setFalse = 0) {
131  _flags &= ~setFalse;
132  _flags |= setTrue;
133  return true;
134  }
135 
136 private:
137 
139  std::uint16_t _flags;
140 
141 };
142 
143 inline std::ostream&
144 operator<<(std::ostream& os, const PropFlags& fl)
145 {
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;
152 }
153 
154 
155 
156 } // namespace gnash
157 
158 #endif // GNASH_AS_PROP_FLAGS_H
Only visible by VM initialized for version 9 or higher.
Definition: PropFlags.h:57
bool set_flags(std::uint16_t setTrue, std::uint16_t setFalse=0)
Definition: PropFlags.h:130
bool test() const
Definition: PropFlags.h:94
Protect from deletion.
Definition: PropFlags.h:39
Only visible by VM initialized for version 7 or higher.
Definition: PropFlags.h:51
Only visible by VM initialized for version 6 or higher.
Definition: PropFlags.h:45
bool operator==(const PropFlags &o) const
Definition: PropFlags.h:85
Flags defining the level of protection of a member.
Definition: PropFlags.h:28
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
bool get_visible(int swfVersion) const
Get version-based visibility.
Definition: PropFlags.h:99
Definition: GnashKey.h:152
Definition: GnashKey.h:161
PropFlags()
Default constructor.
Definition: PropFlags.h:62
Ignore in SWF6-initialized VM.
Definition: PropFlags.h:48
std::uint16_t get_flags() const
accessor to the numerical flags value
Definition: PropFlags.h:120
std::ostream & operator<<(std::ostream &o, const URL &u)
Definition: URL.cpp:447
Flags
Actual flags.
Definition: PropFlags.h:33
Only visible by VM initialized for version 8 or higher.
Definition: PropFlags.h:54
bool operator!=(const PropFlags &o) const
Definition: PropFlags.h:89
PropFlags(const bool read_only, const bool dont_delete, const bool dont_enum)
Constructor.
Definition: PropFlags.h:69
PropFlags(std::uint16_t flags)
Constructor, from numerical value.
Definition: PropFlags.h:79
Protect from assigning a value.
Definition: PropFlags.h:42
void clear_visible(int swfVersion)
Definition: PropFlags.h:108
Protect from enumeration.
Definition: PropFlags.h:36