Leosac  0.8.0
Open Source Access Control
GlobalRegistry.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 #include <mutex>
27 
28 namespace Leosac
29 {
34 {
35  public:
36  using KeyType = std::string;
39 
40  template <typename T>
41  static T get(const KeyType &key)
42  {
43  std::lock_guard<std::mutex> lg(mutex_);
44  return registry_.get<T>(key);
45  }
46 
47  template <typename T>
48  static void set(const KeyType &key, const T &obj)
49  {
50  std::lock_guard<std::mutex> lg(mutex_);
51  registry_.set(key, obj);
52  }
53 
54  template <typename T>
55  static void set(const KeyType &key, const T &obj,
56  const std::chrono::steady_clock::time_point &expire_at)
57  {
58  registry_.set(key, obj, expire_at);
59  }
60 
61  static void erase(const KeyType &key)
62  {
63  return registry_.erase(key);
64  }
65 
66  static bool has(const KeyType &key)
67  {
68  return registry_.has(key);
69  }
70 
71  private:
72  static std::mutex mutex_;
74 };
75 }
Leosac::GlobalRegistry::set
static void set(const KeyType &key, const T &obj, const std::chrono::steady_clock::time_point &expire_at)
Definition: GlobalRegistry.hpp:55
Leosac::GlobalRegistry::Clock
UnderlyingRegistry::Clock Clock
Definition: GlobalRegistry.hpp:38
Leosac::Registry::has
bool has(const KeyType &key) const
Definition: Registry.hpp:149
Leosac::GlobalRegistry::erase
static void erase(const KeyType &key)
Definition: GlobalRegistry.hpp:61
Leosac::Registry
A simple container that can holds object of any type.
Definition: Registry.hpp:55
Registry.hpp
Leosac::Registry::Clock
std::chrono::steady_clock Clock
Definition: Registry.hpp:73
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::GlobalRegistry::KeyType
std::string KeyType
Definition: GlobalRegistry.hpp:36
Leosac::GlobalRegistry::registry_
static UnderlyingRegistry registry_
Definition: GlobalRegistry.hpp:73
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::GlobalRegistry::get
static T get(const KeyType &key)
Definition: GlobalRegistry.hpp:41
Leosac::GlobalRegistry::set
static void set(const KeyType &key, const T &obj)
Definition: GlobalRegistry.hpp:48
Leosac::GlobalRegistry::mutex_
static std::mutex mutex_
Definition: GlobalRegistry.hpp:72
log.hpp
Leosac::GlobalRegistry::has
static bool has(const KeyType &key)
Definition: GlobalRegistry.hpp:66
Leosac::GlobalRegistry
An application wide registry that can store objects of any type.
Definition: GlobalRegistry.hpp:33