Webserv
Loading...
Searching...
No Matches
config::Block Class Reference

Base class for configuration blocks like 'server' and 'location'. More...

#include <Block.hpp>

Inheritance diagram for config::Block:
config::LocationBlock config::ServerBlock

Public Member Functions

 Block (std::string const &name)
 Block (const Block &other)
Blockoperator= (const Block &other)
virtual ~Block ()
bool has (std::string const &key) const
 Checks if a directive exists within the block.
ArgumentVector const & get (std::string const &key) const
 Safely gets the values for a directive.
Blockadd (std::string const &key, std::vector< std::string > const &)
 Adds a directive with multiple values.
Blockadd (std::string const &key, std::string const &)
Blockadd (std::string const &key, std::string const &, std::string const &)
Blockadd (std::string const &key, ParsedDirectiveArgs const &args)
Blockadd (std::string const &key, ArgumentVector const &values)
Blockadd (std::string const &key, ArgumentPtr value)
Blockadd (std::string const &key, size_t value)
std::vector< std::string > getRawValues (std::string const &key) const
std::string getFirstRawValue (std::string const &key) const
std::vector< std::string > get (std::string const &key, http::Request const &req) const
std::string getFirstEvaluatedString (std::string const &key, http::Request const &req) const
std::string const & name () const
 Gets the name of the block.
std::string root () const
 Gets the root path directive.
std::vector< std::string > indexFiles () const
 Gets the index files directive.
Blockroot (std::string const &)
 Sets the root directive using a fluent interface.
size_t maxBodySize () const
BlockmaxBodySize (size_t)

Protected Attributes

std::string name_
 The name of the block (e.g., "server", "location").
DirectiveMap directives_
 Map storing directive names and their values.

Friends

class DirectiveHandler
std::ostream & operator<< (std::ostream &o, Block const &b)

Detailed Description

Base class for configuration blocks like 'server' and 'location'.

This class provides a generic storage mechanism for configuration directives using a map, allowing for high extensibility.

Constructor & Destructor Documentation

◆ Block() [1/2]

config::Block::Block ( std::string const & name)
explicit

◆ Block() [2/2]

config::Block::Block ( const Block & other)

◆ ~Block()

config::Block::~Block ( )
virtual

Member Function Documentation

◆ add() [1/7]

Block & config::Block::add ( std::string const & key,
ArgumentPtr value )

◆ add() [2/7]

Block & config::Block::add ( std::string const & key,
ArgumentVector const & values )

◆ add() [3/7]

Block & config::Block::add ( std::string const & key,
ParsedDirectiveArgs const & args )

◆ add() [4/7]

Block & config::Block::add ( std::string const & key,
size_t value )

◆ add() [5/7]

Block & config::Block::add ( std::string const & key,
std::string const & value )

◆ add() [6/7]

Block & config::Block::add ( std::string const & key,
std::string const & v1,
std::string const & v2 )

◆ add() [7/7]

Block & config::Block::add ( std::string const & key,
std::vector< std::string > const & value )

Adds a directive with multiple values.

Parameters
keyThe name of the directive.
valuesA vector of string values.
Returns
A reference to the Block object for chaining.

◆ get() [1/2]

ArgumentVector const & config::Block::get ( std::string const & key) const

Safely gets the values for a directive.

Retrieves the arguments for a specific directive.

Parameters
keyThe name of the directive.
Returns
A constant reference to the vector of directive values.
Exceptions
std::out_of_rangeIf the directive is not found.
Parameters
keyThe name of the directive (e.g., "root").
Returns
A const pointer to the vector of arguments, or NULL if the directive is not found or has no arguments.

◆ get() [2/2]

std::vector< std::string > config::Block::get ( std::string const & key,
http::Request const & req ) const

◆ getFirstEvaluatedString()

std::string config::Block::getFirstEvaluatedString ( std::string const & key,
http::Request const & req ) const

◆ getFirstRawValue()

std::string config::Block::getFirstRawValue ( std::string const & key) const

◆ getRawValues()

std::vector< std::string > config::Block::getRawValues ( std::string const & key) const

◆ has()

bool config::Block::has ( std::string const & key) const

Checks if a directive exists within the block.

Parameters
keyThe name of the directive to check.
Returns
True if the directive exists, false otherwise.

◆ indexFiles()

std::vector< std::string > config::Block::indexFiles ( ) const

Gets the index files directive.

Returns
A vector of index file names.

◆ maxBodySize() [1/2]

size_t config::Block::maxBodySize ( ) const

◆ maxBodySize() [2/2]

Block & config::Block::maxBodySize ( size_t size)

◆ name()

std::string const & config::Block::name ( ) const

Gets the name of the block.

Returns
A constant reference to the block's name.

◆ operator=()

Block & config::Block::operator= ( const Block & other)

◆ root() [1/2]

std::string config::Block::root ( ) const

Gets the root path directive.

Returns
The root path string, or an empty string if not set.

◆ root() [2/2]

Block & config::Block::root ( std::string const & root)

Sets the root directive using a fluent interface.

Parameters
pathThe root path to set.
Returns
A reference to the Block object for chaining.

◆ DirectiveHandler

friend class DirectiveHandler
friend

◆ operator<<

std::ostream & operator<< ( std::ostream & o,
Block const & b )
friend

Member Data Documentation

◆ directives_

DirectiveMap config::Block::directives_
protected

Map storing directive names and their values.

◆ name_

std::string config::Block::name_
protected

The name of the block (e.g., "server", "location").


The documentation for this class was generated from the following files: