From 1377e996618fc518b29ed5e19797dc8e55bfb9af Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 11 Mar 2024 19:21:38 -0400 Subject: [PATCH] foward decl --- CMakeLists.txt | 2 +- include/lilfbtf/fwddecl.h | 33 ++++++++++++++ include/lilfbtf/tree.h | 91 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 include/lilfbtf/fwddecl.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b18ffa8..677e787 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(lilfbtf5 VERSION 0.1.15) +project(lilfbtf5 VERSION 0.1.16) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) diff --git a/include/lilfbtf/fwddecl.h b/include/lilfbtf/fwddecl.h new file mode 100644 index 0000000..dbc52ab --- /dev/null +++ b/include/lilfbtf/fwddecl.h @@ -0,0 +1,33 @@ +#pragma once +/* + * Copyright (C) 2024 Brett Terpstra + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LILFBTF5_FWDDECL_H +#define LILFBTF5_FWDDECL_H + +namespace fb +{ + namespace detail + { + class node_t; + } + + class func_t; + class tree_t; +} + +#endif //LILFBTF5_FWDDECL_H diff --git a/include/lilfbtf/tree.h b/include/lilfbtf/tree.h index 13754b8..9690fe8 100644 --- a/include/lilfbtf/tree.h +++ b/include/lilfbtf/tree.h @@ -19,9 +19,98 @@ #ifndef LILFBTF5_TREE_H #define LILFBTF5_TREE_H +#include +#include +#include "blt/std/ranges.h" +#include "blt/std/allocator.h" +#include + namespace fb { - + using func_t_call_t = std::function)>; + + class func_t + { + private: + blt::size_t argc_ = 0; + std::string type; + const func_t_call_t& func; + protected: + blt::unsafe::any_t value; + public: + explicit func_t(blt::size_t argc, const func_t_call_t& func): + argc_(argc), func(func) + {} + + [[nodiscard]] inline blt::size_t argc() const + { return argc_; } + + [[nodiscard]] inline blt::unsafe::any_t getValue() const + { + return value; + } + + inline func_t& setValue(blt::unsafe::any_t val) + { + this->value = val; + return *this; + } + + inline std::string& getType() + { + return type; + } + + inline void call(blt::span args) + { + func(*this, args); + }; + + ~func_t() = default; + }; + + namespace detail + { + class node_t + { + friend tree_t; + private: + blt::bump_allocator& alloc; + func_t type; + node_t** children = nullptr; + public: + explicit node_t(const func_t& type, blt::bump_allocator& alloc): alloc(alloc), type(type) + { + children = alloc.emplace_many(this->type.argc()); + for (blt::size_t i = 0; i < this->type.argc(); i++) + children[i] = nullptr; + } + + inline void evaluate() + { + type.call(blt::span{children, type.argc()}); + } + + ~node_t() + { + for (blt::size_t i = 0; i < type.argc(); i++) + { + alloc.destroy(children[i]); + alloc.deallocate(children[i]); + } + alloc.deallocate(children, type.argc()); + } + }; + } + + + class tree_t + { + private: + blt::bump_allocator& alloc; + public: + + }; } #endif //LILFBTF5_TREE_H