8 #ifndef MOD_SERVLET_CONTEXT_H
9 #define MOD_SERVLET_CONTEXT_H
11 #include <experimental/any>
12 #include <experimental/string_view>
20 using std::experimental::string_view;
88 template <
typename T,
typename KeyType>
99 template <
typename KeyType,
typename ValueType>
119 template <
typename ValueType>
131 template <
typename ValueType>
133 {
return _attr_map.
put(std::move(key), std::forward(value)); }
144 template <
typename KeyType>
179 template <
typename KeyType>
257 servlet_config(std::string &&servlet_name) : _servlet_name{std::move(servlet_name)} {}
262 virtual ~servlet_config() noexcept = default;
272 const std::
string& get_servlet_name()
const {
return _servlet_name; }
294 template <
typename KeyType>
296 {
return get_servlet_context().get_init_parameter(key); }
305 {
return get_servlet_context().get_init_parameters(); }
327 filter_config(
const std::string &filter_name) : _filter_name{filter_name} {}
334 filter_config(std::string &&filter_name) : _filter_name{std::move(filter_name)} {}
339 virtual ~filter_config() noexcept = default;
347 const std::
string& get_filter_name()
const {
return _filter_name; }
370 template <
typename KeyType>
372 {
return get_servlet_context().get_init_parameter(key); }
381 {
return get_servlet_context().get_init_parameters(); }
392 #endif // MOD_SERVLET_CONTEXT_H
servlet_context(const std::string &ctx_path, const std::string &webapp_path, init_params_map &&init_params)
Protected constructor to be used from derrived classes.
Definition: context.h:217
virtual ~servlet_context() noexcept=default
virtual destructor
init_params_map _init_params_map
Initial parameters map.
Definition: context.h:231
bool put(key_type &&key, Args &&...args)
Associates a value of specified type created with a given arguments with the specified key in this ma...
Definition: any_map.h:283
Defines optional container objects and related methods.
bool set_attribute(const std::string &key, ValueType &&value)
Binds an object to a given attribute name in this servlet context.
Definition: context.h:120
Defines a set of methods that a servlet uses to communicate with its servlet container.
Definition: context.h:44
const std::string _servlet_name
Servlet name.
Definition: context.h:311
const tree_any_map & get_attributes() const
Const version of get_attributes method.
Definition: context.h:161
filter_config(std::string &&filter_name)
Move version of the object constructor.
Definition: context.h:334
bool set_attribute(std::string &&key, ValueType &&value)
Move version of set_attribute(const std::string&, ValueType&&)
Definition: context.h:132
std::map< std::string, std::string, std::less<> > init_params_map
Type definition for initial parameters map.
Definition: context.h:50
Optional reference implementation.
Definition: optional.h:221
const std::string & _ctx_path
Context path.
Definition: context.h:223
const std::string & get_webapp_path() const
Returns filesystem path of current web application.
Definition: context.h:68
Covenience class on top of associative container to facilitate work with value type std::any...
Definition: any_map.h:84
const std::map< std::string, std::string, std::less<> > & get_init_parameters()
Returns all the filter's initialization parameters as a tree_map.
Definition: context.h:380
servlet_config(std::string &&servlet_name)
Move version of the object constructor.
Definition: context.h:257
const std::string & get_context_path() const
Return the main path associated with this context.
Definition: context.h:62
constexpr T & value()&
Accesses the contained value as a reference.
Definition: optional.h:332
const init_params_map & get_init_parameters() const
Returns the context's initialization parameters map of std::string objects.
Definition: context.h:196
const std::string & _webapp_path
Filesystem path of current webapp.
Definition: context.h:236
filter_config(const std::string &filter_name)
Creates new filter_config object with a given filter name.
Definition: context.h:327
optional_ref< const ValueType > get_attribute(const KeyType &key) const
Finds attribute by key and casts it to specified ValueType.
Definition: context.h:100
A servlet configuration object used by a servlet container to pass information to a servlet during in...
Definition: context.h:243
tree_any_map & get_attributes()
Returns an tree_map containing all the attributes available within this servlet context.
Definition: context.h:154
const std::string _filter_name
Filter name.
Definition: context.h:387
A filter configuration object used by a servlet container to pass information to a filter during init...
Definition: context.h:320
virtual optional_ref< const std::string > get_mime_type(string_view file_name) const =0
Returns the MIME type of the specified file, or null if the MIME type is not known.
servlet_config(const std::string &servlet_name)
Creates new servlet_config object with a given servlet name.
Definition: context.h:250
bool remove_attribute(const KeyType &key)
Removes the attribute with the given name from the servlet context.
Definition: context.h:145
optional_ref< const std::string > get_init_parameter(const KeyType &key)
Returns a std::string containing the value of the named initialization parameter, or empty_reference ...
Definition: context.h:371
const std::map< std::string, std::string, std::less<> > & get_init_parameters() const
Returns all the servlet's initialization parameters as a tree_map.
Definition: context.h:304
optional_ref< const T > get_attribute(const KeyType &key) const
Returns the servlet container attribute with the given name, or empty reference if there is no attrib...
Definition: context.h:89
optional_ref< const std::string > get_init_parameter(const KeyType &key) const
Returns a reference to a std::string containing the value of the named context-wide initialization pa...
Definition: context.h:180
Containes the implementation of any_map class and related type definitions.
optional_ref< const std::string > get_init_parameter(const KeyType &key) const
Returns a std::string containing the value of the named initialization parameter, or empty_reference ...
Definition: context.h:295
constexpr bool has_value() const noexcept
Checks whether this object contains valid pointer.
Definition: optional.h:325
optional_ref< const T > get(const KeyType &key) const
Returns optional_ref object to a value with a specified type, if that value exists and can be casted ...
Definition: any_map.h:203
tree_any_map _attr_map
Attributes map (to be filled by inheriting class).
Definition: context.h:227