Leosac  0.8.0
Open Source Access Control
ThreadLocalRegistry.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "tools/log.hpp"
24 #include <boost/any.hpp>
25 #include <map>
26 
27 namespace Leosac
28 {
36 {
37  public:
38  enum KeyType
39  {
41  };
42 
44 
45  template <typename T>
46  static T get(const KeyType &key)
47  {
48  return registry_.get<T>(key);
49  }
50 
51  template <typename T>
52  static void set(const KeyType &key, const T &obj)
53  {
54  registry_.set(key, obj);
55  }
56 
57  template <typename T>
58  static void set(const KeyType &key, const T &obj,
59  const UnderlyingRegistry::Clock::time_point &expire_at)
60  {
61  registry_.set(key, obj, expire_at);
62  }
63 
64  static void erase(const KeyType &key)
65  {
66  return registry_.erase(key);
67  }
68 
69  static bool has(const KeyType &key)
70  {
71  return registry_.has(key);
72  }
73 
74  static void purge()
75  {
76  return registry_.purge();
77  }
78 
79  private:
80  static thread_local UnderlyingRegistry registry_;
81 };
82 }
Leosac::ThreadLocalRegistry::set
static void set(const KeyType &key, const T &obj)
Definition: ThreadLocalRegistry.hpp:52
Leosac::ThreadLocalRegistry
A simple, thread-local container to share various type of objects.
Definition: ThreadLocalRegistry.hpp:35
Leosac::Registry::has
bool has(const KeyType &key) const
Definition: Registry.hpp:149
Leosac::ThreadLocalRegistry::erase
static void erase(const KeyType &key)
Definition: ThreadLocalRegistry.hpp:64
Leosac::ThreadLocalRegistry::KeyType
KeyType
Definition: ThreadLocalRegistry.hpp:38
Leosac::Registry
A simple container that can holds object of any type.
Definition: Registry.hpp:55
Registry.hpp
Leosac::ThreadLocalRegistry::registry_
static thread_local UnderlyingRegistry registry_
Definition: ThreadLocalRegistry.hpp:80
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::ThreadLocalRegistry::DATABASE
@ DATABASE
Definition: ThreadLocalRegistry.hpp:40
Leosac::ThreadLocalRegistry::set
static void set(const KeyType &key, const T &obj, const UnderlyingRegistry::Clock::time_point &expire_at)
Definition: ThreadLocalRegistry.hpp:58
Leosac::ThreadLocalRegistry::get
static T get(const KeyType &key)
Definition: ThreadLocalRegistry.hpp:46
Leosac::Registry::get
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.
Definition: Registry.hpp:81
Leosac::Registry::set
void set(const KeyType &key, const T &obj)
Definition: Registry.hpp:123
Leosac::Registry::erase
void erase(const KeyType &key)
Erase an entry for the store.
Definition: Registry.hpp:143
Leosac::Registry::purge
void purge()
Remove expired entry from the store.
Definition: Registry.hpp:157
log.hpp
Leosac::ThreadLocalRegistry::purge
static void purge()
Definition: ThreadLocalRegistry.hpp:74
Leosac::ThreadLocalRegistry::has
static bool has(const KeyType &key)
Definition: ThreadLocalRegistry.hpp:69