From 2e999889bdc86d6aa41ad485215e45b59b8fabb1 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 4 Jun 2021 19:03:07 -0400 Subject: [PATCH] Attempts to implement tree construction. --- Machines/Utility/ROMCatalogue.cpp | 23 +++++++++++++++++++---- Machines/Utility/ROMCatalogue.hpp | 2 ++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Machines/Utility/ROMCatalogue.cpp b/Machines/Utility/ROMCatalogue.cpp index e38a8d4f9..8c8de8349 100644 --- a/Machines/Utility/ROMCatalogue.cpp +++ b/Machines/Utility/ROMCatalogue.cpp @@ -18,14 +18,29 @@ Request::Request(Name name, bool optional) { node.is_optional = optional; } +Request Request::append(Node::Type type, const Request &rhs) { + // Start with the easiest case: this is already an ::All request, and + // so is the new thing. + if(node.type == type && rhs.node.type == type) { + Request new_request = *this; + new_request.node.children.insert(new_request.node.children.end(), rhs.node.children.begin(), rhs.node.children.end()); + return new_request; + } + + // Otherwise create a new parent node. + Request parent; + parent.node.type = type; + parent.node.children.push_back(this->node); + parent.node.children.push_back(rhs.node); + return parent; +} + Request Request::operator &&(const Request &rhs) { - (void)rhs; - return *this; + return append(Node::Type::All, rhs); } Request Request::operator ||(const Request &rhs) { - (void)rhs; - return *this; + return append(Node::Type::Any, rhs); } bool Request::validate(Map &map) const { diff --git a/Machines/Utility/ROMCatalogue.hpp b/Machines/Utility/ROMCatalogue.hpp index ec69124c7..846095b19 100644 --- a/Machines/Utility/ROMCatalogue.hpp +++ b/Machines/Utility/ROMCatalogue.hpp @@ -179,6 +179,8 @@ struct Request { bool validate(Map &) const; }; Node node; + + Request append(Node::Type type, const Request &rhs); }; }