$darkmode
oak::Muxer< T > Class Template Reference

#include <route_muxer.hpp>

Inheritance diagram for oak::Muxer< T >:

Public Member Functions

std::string resolve (const std::string &route) const
 
void set_backtrack (bool enabled)
 
void set_default (T def)
 
std::vector< std::string > routes () const
 
bool has (const std::string &route) const
 
void add (const std::string &route, T val)
 
void set (const std::string &route, T val)
 
std::pair< T, Parameters > get (const std::string &route) const
 
void set_unsafe (const std::string &key, T val)
 
std::pair< T, Parameters > get_unsafe (const std::string &key) const
 

Static Public Member Functions

static std::string normalize (const std::string &route)
 
static bool is_identifier (const std::string &s)
 

Detailed Description

template<typename T>
class oak::Muxer< T >

The Muxer is an advanced map that takes HTTP endpoints as input and returns a unique value.

The kind of value that is returned is configurable, since Muxer doesn't need to know. This allows for easy testing as well as the ability to return complex web handlers.

Usage

Muxer<bool> mux;
mux.set_default(false);
mux.set_backtrack(true);
mux.add("/index.html", true);

Safety

As the muxer is almost always used in multi-threaded contexts, it contains a read-write mutex that allows routes to be added dynamically.

Member Function Documentation

◆ get()

template<typename T >
std::pair<T, Parameters> oak::Muxer< T >::get ( const std::string &  route) const
inline

Get the value associated with the normalized and resolved route.

If no default is set, this method will throw std::out_of_range when a route is not registered.

Here is the call graph for this function:

◆ is_identifier()

template<typename T >
static bool oak::Muxer< T >::is_identifier ( const std::string &  s)
inlinestatic

Return true if the input param string does not contain any forbidden characters.

Legal characters are alphanumeric characters and one of -_..

◆ normalize()

template<typename T >
static std::string oak::Muxer< T >::normalize ( const std::string &  route)
inlinestatic

Converts a path spec to the normal form.

In particular:

  • trailing slashes are removed
  • redundant path elements are removed
  • everything following the first '?' is removed

Safety

  • This function should not panic.
Here is the caller graph for this function:

◆ resolve()

template<typename T >
std::string oak::Muxer< T >::resolve ( const std::string &  route) const
inline

Convert a path spec to an existing registered path, or "".

If backtrack is true, then the first matching parent of the normalized route is returned.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_backtrack()

template<typename T >
void oak::Muxer< T >::set_backtrack ( bool  enabled)
inline

Set the backtracking behavior.

◆ set_default()

template<typename T >
void oak::Muxer< T >::set_default ( def)
inline

Set the default value, if no path can be matched.


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