• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

PropFlags.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   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 
00024 namespace gnash {
00025 
00027 class PropFlags
00028 {
00029 
00031         int _flags;
00032 
00034         //bool _protected;
00035 
00036 public:
00037 
00039         enum Flags {
00040 
00042                 dontEnum        = 1 << 0, // 1
00043 
00045                 dontDelete      = 1 << 1, // 2
00046 
00048                 readOnly        = 1 << 2, // 4
00049 
00051                 onlySWF6Up      = 1 << 7, // 128
00052 
00054                 ignoreSWF6      = 1 << 8, // 256
00055 
00057                 onlySWF7Up      = 1 << 10, // 1024
00058 
00060                 onlySWF8Up      = 1 << 12, // 4096
00061 
00063                 onlySWF9Up      = 1 << 13 // 8192
00064 
00065         };
00066 
00068         PropFlags() : _flags(0)
00069         {
00070         }
00071 
00073         PropFlags(const bool read_only, const bool dont_delete,
00074             const bool dont_enum)
00075                 :
00076                 _flags(((read_only) ? readOnly : 0) |
00077                                 ((dont_delete) ? dontDelete : 0) |
00078                                 ((dont_enum) ? dontEnum : 0))
00079         {
00080         }
00081 
00083         PropFlags(const int flags)
00084                 : _flags(flags)
00085         {
00086         }
00087 
00088         bool operator== (const PropFlags& o) const
00089         {
00090                 return ( _flags == o._flags );
00091         }
00092 
00093         bool operator!= (const PropFlags& o) const
00094         {
00095                 return ( _flags != o._flags );
00096         }
00097 
00099         bool get_read_only() const
00100         {
00101             return (_flags & readOnly);
00102         }
00103 
00105         void set_read_only() { _flags |= readOnly; }
00106 
00108         void clear_read_only() { _flags &= ~readOnly; }
00109 
00111         bool get_dont_delete() const
00112         {
00113             return (_flags & dontDelete);
00114         }
00115 
00117         void set_dont_delete() { _flags |= dontDelete; }
00118 
00120         void clear_dont_delete() { _flags &= ~dontDelete; }
00121 
00123         bool get_dont_enum() const
00124         {
00125             return (_flags & dontEnum);
00126         }
00127 
00129         void set_dont_enum() { _flags |= dontEnum; }
00130 
00132         void clear_dont_enum() { _flags &= ~dontEnum; }
00133 
00135         bool get_visible(int swfVersion) const
00136         {
00137                 if ( _flags & onlySWF6Up && swfVersion < 6 ) return false;
00138                 if ( _flags & ignoreSWF6 && swfVersion == 6 ) return false;
00139                 if ( _flags & onlySWF7Up && swfVersion < 7 ) return false;
00140                 if ( _flags & onlySWF8Up && swfVersion < 8 ) return false;
00141                 if ( _flags & onlySWF9Up && swfVersion < 9 ) return false;
00142                 return true;
00143         }
00144 
00145         void clear_visible(int swfVersion) 
00146         {
00147                 if ( swfVersion == 6)
00148                 {
00149                         // version 6, so let's forget onlySWF7Up flag!
00150                         // we will still set the value though, even if that flag is set
00151                         _flags &= ~(onlySWF6Up|ignoreSWF6|onlySWF8Up|onlySWF9Up);
00152                 }
00153                 else
00154                 {
00155                         _flags &= ~(onlySWF6Up|ignoreSWF6|onlySWF7Up|onlySWF8Up|onlySWF9Up);
00156                 }
00157                 
00158         }
00159 
00161         int get_flags() const { return _flags; }
00162 
00176         bool set_flags(const int setTrue, const int setFalse = 0)
00177         {
00178                 _flags &= ~setFalse;
00179                 _flags |= setTrue;
00180                 return true;
00181         }
00182 };
00183 
00184 inline std::ostream&
00185 operator << (std::ostream& os, const PropFlags& fl)
00186 {
00187         os << "(";
00188         if ( fl.get_read_only() ) os << " readonly";
00189         if ( fl.get_dont_delete() ) os << " nodelete";
00190         if ( fl.get_dont_enum() ) os << " noenum";
00191         os << " )";
00192         // TODO: visibility flags
00193         return os;
00194 }
00195 
00196 
00197 
00198 } // namespace gnash
00199 
00200 #endif // GNASH_AS_PROP_FLAGS_H

Generated on Fri Mar 16 2012 15:46:11 for Gnash by  doxygen 1.7.1