Leosac  0.8.0
Open Source Access Control
Leosac::Registry< KeyType > Class Template Reference

A simple container that can holds object of any type. More...

#include <Registry.hpp>

+ Collaboration diagram for Leosac::Registry< KeyType >:

Public Types

using Clock = std::chrono::steady_clock
 

Public Member Functions

template<typename T >
std::enable_if_t< std::is_same< KeyType, std::string >::value &&!std::is_same< KeyType, const char * >::value, T > get (const std::string &key) const
 Specialization for key of type std::string. More...
 
template<typename T >
std::enable_if_t< std::is_same< KeyType, const char * >::value &&!std::is_same< KeyType, std::string >::value, T > get (const char *key) const
 Specialization for string literals. More...
 
template<typename T >
std::enable_if_t<!std::is_same< KeyType, const char * >::value &&!std::is_same< KeyType, std::string >::value, T > get (const KeyType &key) const
 
template<typename T >
void set (const KeyType &key, const T &obj)
 
template<typename T >
void set (const KeyType &key, const T &obj, const std::chrono::steady_clock::time_point &expire_at)
 
void erase (const KeyType &key)
 Erase an entry for the store. More...
 
bool has (const KeyType &key) const
 
void purge ()
 Remove expired entry from the store. More...
 
size_t size () const
 

Static Private Member Functions

template<typename T >
static bool is_type_valid (const boost::any &a)
 

Private Attributes

std::map< KeyType, Clock::time_point > expiry_
 
std::map< KeyType, boost::any > store_
 

Detailed Description

template<typename KeyType = std::string>
class Leosac::Registry< KeyType >

A simple container that can holds object of any type.

This is basically a map<string, boost::any>. Type safety is enforced at runtime, and trying to retrieve an object of type that doesn't match will result in an assertion.

While the registry supports concept of expiration for its entry, it is not designed to prevent access to expired object. Instead, its goal is to remove expired from time to time to prevent infinite memory grows.

Note
The registry is templated on the key type.

Definition at line 55 of file Registry.hpp.

Member Typedef Documentation

◆ Clock

template<typename KeyType = std::string>
using Leosac::Registry< KeyType >::Clock = std::chrono::steady_clock

Definition at line 73 of file Registry.hpp.

Member Function Documentation

◆ erase()

template<typename KeyType = std::string>
void Leosac::Registry< KeyType >::erase ( const KeyType &  key)
inline

Erase an entry for the store.

If the store has no such entry, does nothing.

Definition at line 143 of file Registry.hpp.

◆ get() [1/3]

template<typename KeyType = std::string>
template<typename T >
std::enable_if_t<std::is_same<KeyType, const char *>::value && !std::is_same<KeyType, std::string>::value, T> Leosac::Registry< KeyType >::get ( const char *  key) const
inline

Specialization for string literals.

Definition at line 100 of file Registry.hpp.

◆ get() [2/3]

template<typename KeyType = std::string>
template<typename T >
std::enable_if_t<!std::is_same<KeyType, const char *>::value && !std::is_same<KeyType, std::string>::value, T> Leosac::Registry< KeyType >::get ( const KeyType &  key) const
inline

Definition at line 109 of file Registry.hpp.

◆ get() [3/3]

template<typename KeyType = std::string>
template<typename T >
std::enable_if_t<std::is_same<KeyType, std::string>::value && !std::is_same<KeyType, const char *>::value, T> Leosac::Registry< KeyType >::get ( const std::string &  key) const
inline

Specialization for key of type std::string.

Definition at line 81 of file Registry.hpp.

◆ has()

template<typename KeyType = std::string>
bool Leosac::Registry< KeyType >::has ( const KeyType &  key) const
inline

Definition at line 149 of file Registry.hpp.

◆ is_type_valid()

template<typename KeyType = std::string>
template<typename T >
static bool Leosac::Registry< KeyType >::is_type_valid ( const boost::any &  a)
inlinestaticprivate

Definition at line 59 of file Registry.hpp.

◆ purge()

template<typename KeyType = std::string>
void Leosac::Registry< KeyType >::purge ( )
inline

Remove expired entry from the store.

Definition at line 157 of file Registry.hpp.

◆ set() [1/2]

template<typename KeyType = std::string>
template<typename T >
void Leosac::Registry< KeyType >::set ( const KeyType &  key,
const T &  obj 
)
inline

Definition at line 123 of file Registry.hpp.

◆ set() [2/2]

template<typename KeyType = std::string>
template<typename T >
void Leosac::Registry< KeyType >::set ( const KeyType &  key,
const T &  obj,
const std::chrono::steady_clock::time_point &  expire_at 
)
inline

Definition at line 130 of file Registry.hpp.

◆ size()

template<typename KeyType = std::string>
size_t Leosac::Registry< KeyType >::size ( ) const
inline

Definition at line 176 of file Registry.hpp.

Member Data Documentation

◆ expiry_

template<typename KeyType = std::string>
std::map<KeyType, Clock::time_point> Leosac::Registry< KeyType >::expiry_
private

Definition at line 182 of file Registry.hpp.

◆ store_

template<typename KeyType = std::string>
std::map<KeyType, boost::any> Leosac::Registry< KeyType >::store_
private

Definition at line 183 of file Registry.hpp.


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