Heterogeneous tree header only library. Such tree can store node with diffrent data types.
- CMake > 3.16
- Boost > 1.65
- C++17 compatible compiler
- Clone repository
git clone <url>
- Enter project directory
cd heterogeneous-tree
- Run CMake
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=RELEASE
- Build
cmake --build build
build folder now contains tree_demo executable - demo application for library
Demo application accepts path to file with serialized heterogeneous tree and path to output file, then reads tree from input, prints it to console and saves to output
Program options:
- i,input - path to input file
- o,output - path to output file
samples folder contains example files for demo application:
- sample_input.txt - example of program input
- sample_output.txt - example of program output
- Define types that tree will store e.g. int, double and std::string
- Create tree
#include <string>
#include "tree_lib/tree.hpp"
using TreeType = tree_lib::Tree<int, double, std::string>;
TreeType tree;
- Create nodes and connect them
using TreeNodeType = TreeType::NodeType;
TreeNodeType root = 1;
TreeNodeType leftChild = 2.0;
TreeNodeType rightChild = "str";
root.AddChild(std::move(leftChild));
root.AddChild(std::move(rightChild));
tree.SetRoot(std::move(root));
- Print tree
#include <iostream>
tree.Print(std::cout);
- Save and load tree
#include <fstream>
std::ofstream out("..");
tree.Dump(out);
tree.Clear();
std::ifstream in("..");
tree.Load(in);