00001 00002 // 00003 // This file is part of Common Text Transformation Library. 00004 // Copyright (C) 1997-2009 by Igor Kholodov. 00005 // 00006 // Common Text Transformation Library is free software: you can 00007 // redistribute it and/or modify it under the terms of the 00008 // GNU Lesser General Public License as published by 00009 // the Free Software Foundation, either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // Common Text Transformation Library is distributed in the hope 00013 // that it will be useful, but WITHOUT ANY WARRANTY; without even 00014 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00015 // PURPOSE. See the GNU Lesser General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU Lesser General Public 00018 // License along with Common Text Transformation Library. 00019 // If not, see <http://www.gnu.org/licenses/>. 00020 // 00021 // mailto:cttl@users.sourceforge.net 00022 // http://cttl.sourceforge.net/ 00023 // http://sourceforge.net/projects/cttl/ 00024 // 00026 00036 #ifndef _CTTL_XTL_BITFLAGS_H_INCLUDED_ 00037 #define _CTTL_XTL_BITFLAGS_H_INCLUDED_ 00038 00042 namespace cttl_impl { 00043 00053 struct xtl_bitflags 00054 { 00056 typedef unsigned int value_type; 00057 00064 xtl_bitflags( value_type flags_ = 0 ) 00065 : bits( flags_ ) 00066 { 00067 } 00068 00078 value_type clear( value_type flags_ ) 00079 { 00080 value_type old_value = bits; 00081 bits &= ~flags_; 00082 return old_value; 00083 } 00084 00094 value_type set( value_type flags_ ) 00095 { 00096 value_type old_value = bits; 00097 bits |= flags_; 00098 return old_value; 00099 } 00100 00110 value_type test( value_type flags_ ) const 00111 { 00112 return bits & flags_; 00113 } 00114 00124 bool exact_test( value_type flags_ ) const 00125 { 00126 return ( bits & flags_ ) == flags_; 00127 } 00128 00130 operator value_type() const 00131 { 00132 return bits; 00133 } 00134 00136 value_type bits; 00137 00138 }; // struct xtl_bitflags 00139 00140 } // namespace cttl_impl 00141 00142 #endif //_CTTL_XTL_BITFLAGS_H_INCLUDED_