Moving heavily templatized C ++ code in Java

I have an application written in C ++ (heavily uses templates) that I need to take on the Java ME platform.

I have two questions:

  • Are there any good tools for converting C ++ code to Java - do some basic things so that I have a platform to start with. I found this - http://tangiblesoftwaresolutions.com/Product_Details/CPlusPlus_to_Java_Converter_Details.html . This at least eliminates the need for simple but time-consuming materials, such as moving classes to different files, namespaces in packages, etc. Has anyone tried this? Or knows about the best?

  • The big problem is how to deal with templates - the code uses them very much. Any suggestions on how to do this? Are there any tools for expanding templates, for example, I have a rudimentary database, and then I could work on writing modules in Java?

Any help would be appreciated.

+6
java c ++ templates
source share
5 answers

For all marketing, Sun Java is not just the best C ++, but actually does not support many of the idioms and paradigms supported by C ++. This makes automatic translation difficult. How should you automatically turn a multi-legacy hierarchy into a Java single inheritance hierarchy? (Note, I'm not saying that a hierarchy with multiple heirs is good, just that it is explicitly allowed in C ++). More fundamentally, how would you represent a member function of a member in Java? Or handle the differences between Java overload resolution and C ++?

Java added generics several years ago, but specifically made them less powerful than C ++ templates. Regardless of whether this was a good idea, it limits what automatic translation can do with heavily shaded code.

Besides using some research compiler that can turn C ++ into Java bytecode, I'm afraid you might be stuck with manual porting.

+7
source share

Can you use JNI and call old C ++ code from new Java code?

+1
source share

Generics is a Java function that conforms to C ++ patterns, and they are not supported in J2ME. You can use them with the framework , which probably uses preprocessing to do the trick. (In fact, Generics in Java is a compiler function - the JVM knows nothing about them.)

In any case, it will be difficult, if not impossible, to automatically transfer even a small part of your form of C ++ code to Java Standard Edition - with J2ME the situation is much worse. There are many important differences between Java Generics and C ++ templates.

0
source share

I think for your case a very simple tool will be possible and perhaps worth it. However, this can be a fun job! A friend of mine once made a port from C ++ to Java, and he just made a list of regular expression substitutions. For example, he had all occurrences → replaced by a dot. And so on. That was a few years ago, so I really do not want to ask him.

So, can you do the same, collect some simple substitutions, and perhaps post them somewhere on github?

0
source share

I do not think it will be possible, especially. if your source code is strongly templatized - J2ME does not support generics, AFAIK.

Unfortunately, it seems that it will take a lot of manual work to go through the source code and rewrite it (I assume your target platform does not support JNI)

0
source share

All Articles