1 typedef unsigned int uint32_t;
2
3 enum MaskingOperator
4 {
5 eMaskingOperatorDefault = 0,
6 eMaskingOperatorAnd = 1,
7 eMaskingOperatorOr = 2,
8 eMaskingOperatorXor = 3,
9 eMaskingOperatorNand = 4,
10 eMaskingOperatorNor = 5
11 };
12
13 class MaskedData
14 {
15 private:
16 uint32_t value;
17 uint32_t mask;
18 MaskingOperator oper;
19 public:
MaskedData(uint32_t V=0,uint32_t M=0,MaskingOperator P=eMaskingOperatorDefault)20 MaskedData( uint32_t V = 0,
21 uint32_t M = 0,
22 MaskingOperator P = eMaskingOperatorDefault) :
23 value(V),
24 mask(M),
25 oper(P)
26 {
27 }
28
apply()29 uint32_t apply()
30 {
31 switch(oper)
32 {
33 case eMaskingOperatorAnd:
34 return value & mask;
35 case eMaskingOperatorOr:
36 return value | mask;
37 case eMaskingOperatorXor:
38 return value ^ mask;
39 case eMaskingOperatorNand:
40 return ~(value & mask);
41 case eMaskingOperatorNor:
42 return ~(value | mask);
43 case eMaskingOperatorDefault: // fall through
44 default:
45 return value;
46 }
47 }
48
setValue(uint32_t V)49 void setValue(uint32_t V)
50 {
51 value = V;
52 }
53
setMask(uint32_t M)54 void setMask (uint32_t M)
55 {
56 mask = M;
57 }
58
setOperator(MaskingOperator P)59 void setOperator(MaskingOperator P)
60 {
61 oper = P;
62 }
63 };
64
main()65 int main()
66 {
67 MaskedData data_1(0xFF0F,0xA01F,eMaskingOperatorAnd);
68 MaskedData data_2(data_1.apply(),0x1AFC,eMaskingOperatorXor);
69 MaskedData data_3(data_2.apply(),0xFFCF,eMaskingOperatorOr);
70 MaskedData data_4(data_3.apply(),0xAABC,eMaskingOperatorAnd);
71 MaskedData data_5(data_4.apply(),0xFFAC,eMaskingOperatorNor);
72 MaskedData data_6(data_5.apply(),0x0000BEEF,eMaskingOperatorAnd);
73 return data_6.apply(); // <-- what comes out of here?
74 }