vxorg/vxorg.cpp
Lily Tsuru af49206a16 Rewrite it in C++
rust people are going to be very mad at me now /j
2024-10-21 12:22:35 -04:00

55 lines
1.2 KiB
C++

#include <filesystem>
#include <fstream>
#include <ranges>
#include <string>
#include <string_view>
#include <vector>
#include "tree.hpp"
#include "vxheaven_parse.hpp"
int main() {
std::ifstream ifs("./samples.sort");
vxorg::VxHeavenTree tree;
vxorg::parse_into_tree(tree, ifs);
// walk the resulting tree
tree.walk([](auto* node) {
auto tab_count = node->parent_count();
auto& data = node->data();
for(auto i = 0; i < tab_count; ++i)
std::printf("\t");
if(data.name.empty()) {
std::printf("(root)\n");
} else {
if(data.is_sample) {
std::string sample_name {};
std::vector<vxorg::VxHeavenItem*> parent_list {};
vxorg::VxHeavenTree::Node* parent = node->parent_node();
while(parent) {
if(parent->data().name.empty())
break;
parent_list.push_back(&parent->data());
parent = parent->parent_node();
}
for(auto& item : std::views::reverse(parent_list)) {
sample_name += std::format("{}.", item->name);
}
sample_name += data.name;
std::printf("%s (sample %s)\n", data.name.c_str(), sample_name.c_str());
} else {
std::printf("%s\n", data.name.c_str());
}
}
});
return 0;
}