Webserv
Loading...
Searching...
No Matches
Block.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <string>
5#include <vector>
6
7namespace config {
8
9typedef std::vector<std::string> StringVector;
10typedef std::map<std::string, StringVector> DirectiveMap;
11
19class Block {
20public:
21 // ========================= Construction & Destruction =========================
22
23 virtual ~Block();
24
25 // ============================== Public Interface ==============================
26
28 bool has(std::string const &key) const;
29 StringVector const *operator[](std::string const &key) const;
30 StringVector &operator[](std::string const &key);
31 void add(std::string const &key, StringVector const &values);
32 void add(std::string const &key, std::string const &value);
33
34 // ============================== Getters & Setters =============================
35
37 DirectiveMap const &getDirectives() const;
38
41
48 StringVector const *get(std::string const &key) const;
49
54 std::string getRoot() const;
55
56 void setRoot(std::string const &root);
57
58protected:
59 friend class DirectiveHandler;
60
62};
63
64} // namespace config
Base class for configuration blocks like 'server' and 'location'.
Definition Block.hpp:19
virtual ~Block()
Definition Block.cpp:5
StringVector const * operator[](std::string const &key) const
Definition Block.cpp:18
DirectiveMap const & getDirectives() const
Provides read-only access to the underlying directive map.
Definition Block.cpp:10
DirectiveMap directives_
Definition Block.hpp:61
void setRoot(std::string const &root)
Definition Block.cpp:59
friend class DirectiveHandler
Definition Block.hpp:59
std::string getRoot() const
A convenient, strongly-typed accessor for the 'root' directive.
Definition Block.cpp:52
void add(std::string const &key, StringVector const &values)
Definition Block.cpp:38
StringVector const * get(std::string const &key) const
Retrieves the arguments for a specific directive.
Definition Block.cpp:28
bool has(std::string const &key) const
Checks if a directive exists within the block.
Definition Block.cpp:36
Definition ConfigException.hpp:6
std::vector< std::string > StringVector
Definition Block.hpp:9
std::map< std::string, StringVector > DirectiveMap
Definition Block.hpp:10