00001 /*---------------------------------------------------------------------\ 00002 | | 00003 | __ __ ____ _____ ____ | 00004 | \ \ / /_ _/ ___|_ _|___ \ | 00005 | \ V / _` \___ \ | | __) | | 00006 | | | (_| |___) || | / __/ | 00007 | |_|\__,_|____/ |_| |_____| | 00008 | | 00009 | core system | 00010 | (C) SuSE GmbH | 00011 \----------------------------------------------------------------------/ 00012 00013 File: SelState.h 00014 00015 Author: Michael Andres <ma@suse.de> 00016 Maintainer: Michael Andres <ma@suse.de> 00017 00018 Purpose: Bits representing a PMSelectables state 00019 00020 /-*/ 00021 #ifndef SelState_h 00022 #define SelState_h 00023 00024 #include <stdint.h> 00025 00026 #include <iosfwd> 00027 00029 // 00030 // CLASS NAME : SelState 00039 class SelState { 00040 00041 private: 00042 00046 typedef uint8_t bits; 00047 00048 private: 00049 00050 static const bits B_IS_I = 0x01; // installed object present 00051 static const bits B_IS_C = 0x02; // candidate object present 00052 00053 // next two are mutual exclusive, both unset means no modification 00054 static const bits B_TO_DEL = 0x04; // request to delete installed object 00055 static const bits B_TO_INS = 0x08; // request to install candidate object 00056 00057 // next two are mutual exclusive, both unset means requested by auto (Solver) 00058 static const bits B_BY_USER = 0x10; // modification requested by user 00059 static const bits B_BY_APPL = 0x20; // modification requested by application 00060 00061 static const bits B_F_TABOO = 0x40; // no modification allowed by user 00062 00063 static const bits B_F_SRCINS = 0x80; // Installation of sources desired 00064 00065 00066 static const bits M_IS = B_IS_I | B_IS_C; 00067 00068 static const bits M_TO = B_TO_DEL | B_TO_INS; 00069 00070 static const bits M_BY = B_BY_USER | B_BY_APPL; 00071 00072 private: 00073 00077 bits _bits; 00078 00082 void set( const bits mask_r ) { _bits |= mask_r; } 00086 void clr( const bits mask_r ) { _bits &= ~mask_r; } 00087 00088 public: 00089 00090 SelState(); 00091 ~SelState(); 00092 00093 public: 00094 00101 void set_has_installed( bool b = true ); 00102 00106 void set_has_candidate( bool b = true ); 00107 00108 public: 00109 00113 bool has_object() const { return( _bits & M_IS ); } 00114 00118 bool has_installed() const { return( _bits & B_IS_I ); } 00119 00123 bool has_candidate() const { return( _bits & B_IS_C ); } 00124 00128 bool has_both_objects() const { return( _bits & M_IS ) == M_IS; } 00129 00133 bool has_installed_only() const { return( _bits & M_IS ) == B_IS_I; } 00134 00138 bool has_candidate_only() const { return( _bits & M_IS ) == B_IS_C; } 00139 00140 public: 00141 00145 bool to_modify() const { return( _bits & M_TO ); } 00146 00150 bool to_delete() const { return( _bits & B_TO_DEL ); } 00151 00155 bool to_install() const { return( _bits & B_TO_INS ); } 00156 00157 public: 00158 00162 bool by_user() const { return( _bits & B_BY_USER ); } 00163 00167 bool by_appl() const { return( _bits & B_BY_APPL ); } 00168 00172 bool by_auto() const { return( !( _bits & M_BY ) && to_modify() ); } 00173 00177 bool is_taboo() const { return( _bits & B_F_TABOO ); } 00178 00182 bool is_srcins() const { return( _bits & B_F_SRCINS ); } 00183 00184 public: 00185 00190 bool user_unset( const bool doit ); 00191 00196 bool user_set_delete( const bool doit ); 00197 00202 bool user_set_install( const bool doit ); 00203 00207 bool user_set_taboo( const bool doit ); 00208 00212 bool user_clr_taboo( const bool doit ); 00213 00217 bool user_set_srcins( const bool doit ); 00218 00222 bool user_clr_srcins( const bool doit ); 00223 00224 public: 00225 00230 bool appl_unset( const bool doit ); 00231 00236 bool appl_set_delete( const bool doit ); 00237 00242 bool appl_set_install( const bool doit ); 00243 00244 public: 00245 00250 bool auto_unset( const bool doit ); 00251 00256 bool auto_set_delete( const bool doit ); 00257 00262 bool auto_set_install( const bool doit ); 00263 00264 public: 00265 00266 friend std::ostream & operator<<( std::ostream & str, const SelState & obj ); 00267 00268 friend bool operator==( const SelState & lhs, const SelState & rhs ) { 00269 return( lhs._bits == rhs._bits ); 00270 } 00271 friend bool operator!=( const SelState & lhs, const SelState & rhs ) { 00272 return !operator==( lhs, rhs ); 00273 } 00274 }; 00275 00277 00278 #endif // SelState_h