Maurice Grönwoldt
5bb68a7d02
We have no make install support... so we don't need to have everything as a single-header and lib file.
43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include "MiddleWare.h"
|
|
#include "Request.h"
|
|
#include "Response.h"
|
|
|
|
#include <map>
|
|
|
|
namespace VWeb {
|
|
|
|
class MiddleWareHandler {
|
|
public:
|
|
PreMiddleWareReturn HandlePre(Ref<Request> &);
|
|
void HandlePost(Ref<Request> &, Ref<Response> &);
|
|
void Shutdown(Ref<Request> &, Ref<Response> &);
|
|
|
|
public:
|
|
template <class T> Ref<MiddleWare> GetRef() {
|
|
return GetById(typeid(T).name());
|
|
}
|
|
template <class T> T &Get() {
|
|
return static_cast<T &>(*GetById(typeid(T).name()));
|
|
}
|
|
template <class T> void Set(Ref<MiddleWare> &instance) {
|
|
auto &type = typeid(T);
|
|
if (type.before(typeid(MiddleWare)))
|
|
SetById(type.name(), instance);
|
|
}
|
|
template <class T> T &Create() {
|
|
return static_cast<T &>(*CreateMiddleWare<T>());
|
|
}
|
|
template <class T> void Remove() { RemoveById(typeid(T).name()); }
|
|
|
|
protected:
|
|
template <class T> Ref<MiddleWare> CreateMiddleWare() {
|
|
return SetById(typeid(T).name(), CreateRef<T>());
|
|
}
|
|
Ref<MiddleWare> GetById(const char *id);
|
|
Ref<MiddleWare> SetById(const char *id, const Ref<MiddleWare> &);
|
|
void RemoveById(const char *id);
|
|
std::map<std::string, Ref<MiddleWare>> m_MiddleWares;
|
|
};
|
|
} // namespace VWeb
|