Porting a big array from Python to C++ (Any Ideas)

user2837329

So I'm porting a program from Python to c++ and I have this block of code here:

opcodes = [
        [0x1,'0x1',['b','b',]],
        [0x2,'call',['d',]],
        [0x3,'0x3',['w',]],
        [0x4,'0x4-return',[]],
        [0x5,'0x5',[]],
        [0x6,'0x6-condjump',['d']],
        [0x7,'0x7-condjump',['d']],
        [0x8,'0x8',[]],
        [0x9,'0x9',[]],
        [0xa,'0xa',['d',]],
        [0xb,'0xb',['w',]],
        [0xc,'0xc',['b',]],
        [0xe,'string',['str']],
        [0xf,'0xf',['w',]],
        [0x10,'0x10',['b',]],
        [0x11,'0x11',['w',]],
        [0x12,'0x12',['b',]],
        [0x14,'0x14',[]],
        [0x15,'0x15',['w',]],
        [0x16,'0x16',['b',]],
        [0x17,'0x17',['w',]],
        [0x18,'0x18',['b']],
        [0x19,'0x19',[]],
        [0x1a,'0x1a',[]],
      ]

I was wondering what would be the best way to convert this to a C++ array. I'm not too familiar with python sorry and heard this is called a nested list?

Thanks in advance for all answers, this is probably the biggest hurdle of the python code.

John Zwinck

This is C++11:

#include <string>
#include <vector>

struct OpCode {
  int code;
  const char* str;
  std::vector<const char*> extras;
};

OpCode opcodes[] = {
  {0x1,"0x1",{"b","b",}},
  {0x2,"call",{"d",}},
  {0x3,"0x3",{"w",}},
  {0x4,"0x4-return",{}},
  {0x5,"0x5",{}},
  {0x6,"0x6-condjump",{"d"}},
  {0x7,"0x7-condjump",{"d"}},
  {0x8,"0x8",{}},
  {0x9,"0x9",{}},
  {0xa,"0xa",{"d",}},
  {0xb,"0xb",{"w",}},
  {0xc,"0xc",{"b",}},
  {0xe,"string",{"str"}},
  {0xf,"0xf",{"w",}},
  {0x10,"0x10",{"b",}},
  {0x11,"0x11",{"w",}},
  {0x12,"0x12",{"b",}},
  {0x14,"0x14",{}},
  {0x15,"0x15",{"w",}},
  {0x16,"0x16",{"b",}},
  {0x17,"0x17",{"w",}},
  {0x18,"0x18",{"b"}},
  {0x19,"0x19",{}},
  {0x1a,"0x1a",{}},
};

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Porting a function and an array from C to Python

Any better options than porting from C# to Java?

Porting an app from Java to Python

Porting library from Java to Python

Porting algorithm from Python to Go

Google Material Icons as array - any ideas?

Unable To Scrape url from page using Python and BeautifulSoup. Any ideas?

Porting JavaScript to C# (functions stored in array)

Porting Bitwise Operations from C# To C

Porting #define from C++ to C#

Porting from C++ to C++/CLI

Porting uint from c to c#

C# Extracting data from Json or DataSets - Porting from Python (Json to Dict)

Porting a VBA Type / C struct to a Python ctypes.Structure: array of strings with fixed length

Porting polynomial regression from R to python

Porting from Ruby to Python: What to do with 'yield'

Porting encryption method from Java to Python

Porting duff's device from C to JavaScript

Porting OpenGL Programs from C to WebGL and Javascript

Porting from C# to Delphi, Regex incompatibility

Porting CRC Calculation algorithm from C to Java

Porting python line to c# code

How to generate random numbers fast from "An Extremely Big Array" in Python?

C - insert lines from very big file into array

How to get all Objects from a big Array by an API (C#)

Having issues loading sound in Java from a resource. Any ideas?

ExportAsFixedFileFormat is suddenly not exporting images and formatting from the Excel Document Any ideas?

Python is returning false to "1"=="1". Any ideas why?

Jira python runs very slowly, any ideas on why?