| 28 | |
| 29 | public: |
| 30 | OpCodeParser() |
| 31 | { |
| 32 | for (unsigned int op = 0; op <= MAX_OPCODE; ++op) { |
| 33 | // Allow OP_RESERVED to get into mapOpNames |
| 34 | if (op < OP_NOP && op != OP_RESERVED) { |
| 35 | continue; |
| 36 | } |
| 37 | |
| 38 | std::string strName = GetOpName(static_cast<opcodetype>(op)); |
| 39 | if (strName == "OP_UNKNOWN") { |
| 40 | continue; |
| 41 | } |
| 42 | mapOpNames[strName] = static_cast<opcodetype>(op); |
| 43 | // Convenience: OP_ADD and just ADD are both recognized: |
| 44 | if (strName.compare(0, 3, "OP_") == 0) { // strName starts with "OP_" |
| 45 | mapOpNames[strName.substr(3)] = static_cast<opcodetype>(op); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | opcodetype Parse(const std::string& s) const |
| 50 | { |
| 51 | auto it = mapOpNames.find(s); |