reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   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
typedef unsigned int uint32_t;

enum MaskingOperator {
  eMaskingOperatorDefault = 0,
  eMaskingOperatorAnd = 1,
  eMaskingOperatorOr = 2,
  eMaskingOperatorXor = 3,
  eMaskingOperatorNand = 4,
  eMaskingOperatorNor = 5
};

class MaskedData {
private:
  uint32_t value;
  uint32_t mask;
  MaskingOperator oper;

public:
  MaskedData(uint32_t V = 0, uint32_t M = 0,
             MaskingOperator P = eMaskingOperatorDefault)
      : value(V), mask(M), oper(P) {}

  uint32_t apply() {
    switch (oper) {
    case eMaskingOperatorAnd:
      return value & mask;
    case eMaskingOperatorOr:
      return value | mask;
    case eMaskingOperatorXor:
      return value ^ mask;
    case eMaskingOperatorNand:
      return ~(value & mask);
    case eMaskingOperatorNor:
      return ~(value | mask);
    case eMaskingOperatorDefault: // fall through
    default:
      return value;
    }
  }

  void setValue(uint32_t V) { value = V; }

  void setMask(uint32_t M) { mask = M; }

  void setOperator(MaskingOperator P) { oper = P; }
};

int main() {
  MaskedData data_1(0xFF0F, 0xA01F, eMaskingOperatorAnd);
  MaskedData data_2(data_1.apply(), 0x1AFC, eMaskingOperatorXor);
  MaskedData data_3(data_2.apply(), 0xFFCF, eMaskingOperatorOr);
  MaskedData data_4(data_3.apply(), 0xAABC, eMaskingOperatorAnd);
  MaskedData data_5(data_4.apply(), 0xFFAC, eMaskingOperatorNor);
  MaskedData data_6(data_5.apply(), 0x0000BEEF, eMaskingOperatorAnd);
  return data_6.apply(); // <-- what comes out of here?
}