- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
// header
struct TMWFeatureSet
{
TMWFeatureSet();
~TMWFeatureSet();
enum TFeatureSetBitMask
{
EBackUpBitMask = 1,
ERestoreBitMask = 1 << 1,
EWipeBitMask = 1 << 2,
ELockBitMask = 1 << 3,
ELocateBitMask = 1 << 4,
EMessageBitMask = 1 << 5,
EScreamBitMask = 1 << 6,
EPrintBitMask = 1 << 7,
EShareBitMask = 1 << 8
};
enum TFeatureSet
{
EBackUp = 0,
ERestore,
EWipe,
ELock,
ELocate,
EMessage,
EScream,
EPrint,
EShare,
ECount
};
void SetFeatureAttr( TInt iIndex, TBool aValue );
void Reset( void );
void ExternalizeL( RWriteStream & aOutputStream );
void InternalizeL( RReadStream & aInputStream );
RArray<TFeatureSetBitMask> iBitMasks;
TFixedArray<TBool,ECount> iFeatureSetArr;
};
// implementation
TMWFeatureSet::TMWFeatureSet()
{
iBitMasks.Append( EBackUpBitMask );
iBitMasks.Append( ERestoreBitMask );
iBitMasks.Append( EWipeBitMask );
iBitMasks.Append( ELockBitMask );
iBitMasks.Append( ELocateBitMask );
iBitMasks.Append( EMessageBitMask );
iBitMasks.Append( EScreamBitMask );
iBitMasks.Append( EPrintBitMask );
iBitMasks.Append( EShareBitMask );
}
TMWFeatureSet::~TMWFeatureSet()
{
iBitMasks.Close();
}
void TMWFeatureSet::SetFeatureAttr( TInt iIndex, TBool aValue )
{
iFeatureSetArr[ iIndex ] = aValue;
}
void TMWFeatureSet::Reset( void )
{
for( TInt i = ( TInt ) TMWFeatureSet::EBackUp; i < ( TInt ) TMWFeatureSet::ECount; i++ )
{
SetFeatureAttr( i, EFalse );
}
}
void TMWFeatureSet::ExternalizeL( RWriteStream & aOutputStream )
{
for( TInt i = ( TInt ) TMWFeatureSet::EBackUp; i < ( TInt ) TMWFeatureSet::ECount; i++ )
{
aOutputStream.WriteUint8L((TUint)iFeatureSetArr[ i ]);
}
}
void TMWFeatureSet::InternalizeL( RReadStream & aInputStream )
{
for( TInt i = ( TInt ) TMWFeatureSet::EBackUp; i < ( TInt ) TMWFeatureSet::ECount; i++ )
{
iFeatureSetArr[ i ] = (TBool) aInputStream.ReadUint8L();
}
}
Это реализация битовой маски и по шаблону Simpleton: реализация простейшей функциональности самым сложным способом известным разработчику.
По идее надо было как то так:
int mask;
.....
bool IsFeatureAvailable( feature )
{
return ( ( mask & feature ) == feature );
}