Textual description of trees is one of the main elements of the PPL language. The module that implements this task is written in C#, as is the entire PPL project. I translated this module into C++ to demonstrate the possibility of translating the entire project into C++ to speed up work, as well as to implement the PPL language on various platforms.
For this purpose, I decided to use -
As it turned out, it is impossible to translate a large code for free. In addition, freeing memory, creating objects in the stack and heap, etc. had to be adjusted manually.
My knowledge of C++ and C# was enough to make this translation without the help of additional programs. It also allowed me to make interesting use of the free time I have.
As a small example, I give a hierarchical description of countries and cities -
#include "TreeCreator.h"
int main()
{
TreeCreator* tc = new TreeCreator();
const char* countries =
"Countries [Europe]"
"(Italy"
"(Roma)(Milan)(Turin))"
"(France"
"(Paris)(Marseile)(Provence))"
"(Spain"
"(Madrid)(Granada)(Alicante))";
Composite* root = tc->CreateTree(countries);
root->Display(1);
delete tc;
}
/*
-Node root
---Node Countries Europe
-----Node Italy
-------Leaf Name: Roma value:
-------Leaf Name: Milan value:
-------Leaf Name: Turin value:
-----Node France
-------Leaf Name: Paris value:
-------Leaf Name: Marseile value:
-------Leaf Name: Provence value:
-----Node Spain
-------Leaf Name: Madrid value:
-------Leaf Name: Granada value:
-------Leaf Name: Alicante value:
*/
You can use this code in your projects, supplementing it with the necessary solutions.
You can find the project here -