Replace shared_pointer with RAII, also fix root path not routing correctly

This commit is contained in:
Pablu23
2024-11-26 17:29:36 +01:00
parent c18d5f993d
commit af0c6fb814
5 changed files with 37 additions and 26 deletions

View File

@@ -5,7 +5,6 @@
#include "response.hpp"
#include <cstddef>
#include <functional>
#include <memory>
#include <string>
namespace http {
@@ -14,23 +13,25 @@ public:
bool m_is_value;
bool m_is_dummy;
std::string m_sub_path;
std::map<std::string, std::shared_ptr<Node>> m_next;
std::map<std::string, Node *> m_next;
std::function<void(Request, Response *)> m_function;
public:
Node(std::string subPath, bool isValue,
std::function<void(Request, Response *)>);
Node(std::string subPath);
~Node();
};
class Tree {
private:
std::shared_ptr<Node> m_root;
Node *m_root;
std::string m_method;
size_t m_depth;
public:
Tree(std::string method);
~Tree();
void add_path(std::string, std::function<void(Request, Response *)>);
std::optional<std::function<void(Request, Response *)>> get(std::string);
void debug_Print();