Leosac  0.7.0
OpenSourceAccessControl
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 }
bool has(const KeyType &key) const
Definition: Registry.hpp:149
void set(const KeyType &key, const T &obj)
Definition: Registry.hpp:123
This is the header file for a generated source file, GitSHA1.cpp.
void erase(const KeyType &key)
Erase an entry for the store.
Definition: Registry.hpp:143
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
static std::mutex mutex_
static void erase(const KeyType &key)
std::chrono::steady_clock Clock
Definition: Registry.hpp:73
static UnderlyingRegistry registry_
A simple container that can holds object of any type.
Definition: Registry.hpp:55
UnderlyingRegistry::Clock Clock
static bool has(const KeyType &key)
An application wide registry that can store objects of any type.