Webserv
Loading...
Searching...
No Matches
DirectiveHandler.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "config/Block.hpp"
6
7namespace config {
8
9class IDirective;
10
12public:
15
16 template <typename T>
17 void process(T &block, std::string const &key, ParsedDirectiveArgs const &args) const {
18 HandlerMap::const_iterator it = handlers_.find(key);
19 if (it != handlers_.end()) {
20 it->second->process(block, args);
21 } else {
22 block.add(key, args);
23 }
24 }
25
26 template <typename T> void process(T &block, ParsedDirectiveMap const &map) const {
27 for (ParsedDirectiveMap::const_iterator it = map.begin(); it != map.end(); ++it) {
28 process(block, it->first, it->second);
29 }
30 }
31
32private:
33 typedef std::map<std::string, IDirective *> HandlerMap;
36
40};
41
42} // namespace config
void registerHandler(IDirective *h)
Definition DirectiveHandler.cpp:33
DirectiveHandler & operator=(const DirectiveHandler &)
DirectiveHandler(const DirectiveHandler &)
void process(T &block, ParsedDirectiveMap const &map) const
Definition DirectiveHandler.hpp:26
void process(T &block, std::string const &key, ParsedDirectiveArgs const &args) const
Definition DirectiveHandler.hpp:17
HandlerMap handlers_
Definition DirectiveHandler.hpp:34
DirectiveHandler()
Definition DirectiveHandler.cpp:18
~DirectiveHandler()
Definition DirectiveHandler.cpp:39
std::map< std::string, IDirective * > HandlerMap
Definition DirectiveHandler.hpp:33
static DirectiveHandler & getInstance()
Definition DirectiveHandler.cpp:45
Defines the contract for a configuration directive handler.
Definition IDirective.hpp:18
Definition ArgumentFactory.hpp:5
std::vector< Token > ParsedDirectiveArgs
Definition types.hpp:13
std::map< std::string, ParsedDirectiveArgs > ParsedDirectiveMap
Definition types.hpp:14