Gnash  0.8.10
PropFlags.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00003 //   Free Software Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #ifndef GNASH_AS_PROP_FLAGS_H
00020 #define GNASH_AS_PROP_FLAGS_H
00021 
00022 #include <ostream>
00023 #include <boost/cstdint.hpp>
00024 
00025 namespace gnash {
00026 
00028 class PropFlags
00029 {
00030 public:
00031 
00033         enum Flags {
00034 
00036                 dontEnum        = 1 << 0, // 1
00037 
00039                 dontDelete      = 1 << 1, // 2
00040 
00042                 readOnly        = 1 << 2, // 4
00043 
00045                 onlySWF6Up      = 1 << 7, // 128
00046 
00048                 ignoreSWF6      = 1 << 8, // 256
00049 
00051                 onlySWF7Up      = 1 << 10, // 1024
00052 
00054                 onlySWF8Up      = 1 << 12, // 4096
00055 
00057                 onlySWF9Up      = 1 << 13 // 8192
00058 
00059         };
00060 
00062         PropFlags()
00063         :
00064         _flags(0)
00065         {
00066         }
00067 
00069         PropFlags(const bool read_only, const bool dont_delete,
00070             const bool dont_enum)
00071                 :
00072                 _flags(((read_only) ? readOnly : 0) |
00073                                 ((dont_delete) ? dontDelete : 0) |
00074                                 ((dont_enum) ? dontEnum : 0))
00075         {
00076         }
00077 
00079         PropFlags(boost::uint16_t flags)
00080                 :
00081         _flags(flags)
00082         {
00083         }
00084 
00085         bool operator==(const PropFlags& o) const {
00086                 return (_flags == o._flags);
00087         }
00088 
00089         bool operator!=(const PropFlags& o) const {
00090         return !(*this == o);
00091         }
00092 
00093     template<Flags f>
00094     bool test() const {
00095         return (_flags & f);
00096     }
00097 
00099         bool get_visible(int swfVersion) const {
00100                 if (test<onlySWF6Up>() && swfVersion < 6) return false;
00101                 if (test<ignoreSWF6>() && swfVersion == 6) return false;
00102                 if (test<onlySWF7Up>() && swfVersion < 7) return false;
00103                 if (test<onlySWF8Up>() && swfVersion < 8) return false;
00104                 if (test<onlySWF9Up>() && swfVersion < 9) return false;
00105                 return true;
00106         }
00107 
00108         void clear_visible(int swfVersion) {
00109                 if (swfVersion == 6) {
00110                         // version 6, so let's forget onlySWF7Up flag!
00111                         // we will still set the value though, even if that flag is set
00112                         _flags &= ~(onlySWF6Up|ignoreSWF6|onlySWF8Up|onlySWF9Up);
00113                 }
00114                 else {
00115                         _flags &= ~(onlySWF6Up|ignoreSWF6|onlySWF7Up|onlySWF8Up|onlySWF9Up);
00116                 }
00117         }
00118 
00120     boost::uint16_t get_flags() const { return _flags; }
00121 
00130         bool set_flags(boost::uint16_t setTrue, boost::uint16_t setFalse = 0) {
00131                 _flags &= ~setFalse;
00132                 _flags |= setTrue;
00133                 return true;
00134         }
00135 
00136 private:
00137 
00139     boost::uint16_t _flags;
00140 
00141 };
00142 
00143 inline std::ostream&
00144 operator<<(std::ostream& os, const PropFlags& fl)
00145 {
00146         os << "(";
00147         if (fl.test<PropFlags::readOnly>()) os << " readonly";
00148         if (fl.test<PropFlags::dontDelete>()) os << " nodelete";
00149         if (fl.test<PropFlags::dontEnum>()) os << " noenum";
00150         os << " )";
00151         return os;
00152 }
00153 
00154 
00155 
00156 } // namespace gnash
00157 
00158 #endif // GNASH_AS_PROP_FLAGS_H