2019-01-06 12:52:55 -05:00
|
|
|
/*
|
|
|
|
|
ISC License
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link>
|
|
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2024-02-15 19:50:54 -06:00
|
|
|
#include "nonstd/optional.hpp"
|
2019-01-06 12:52:55 -05:00
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
#include <cstdint>
|
2019-01-06 12:52:55 -05:00
|
|
|
#include <string>
|
2024-02-15 18:11:59 -06:00
|
|
|
#include <unordered_map>
|
2024-02-22 00:05:23 -06:00
|
|
|
#include <boost/unordered/concurrent_flat_map.hpp>
|
2019-01-06 12:52:55 -05:00
|
|
|
|
|
|
|
|
class PolicyCache
|
|
|
|
|
{
|
2024-02-15 19:53:16 -06:00
|
|
|
public:
|
2024-02-22 00:05:23 -06:00
|
|
|
typedef boost::concurrent_flat_map<std::string,std::string> Map;
|
2024-02-15 20:14:42 -06:00
|
|
|
|
2019-01-06 12:52:55 -05:00
|
|
|
public:
|
2024-02-15 20:14:32 -06:00
|
|
|
PolicyCache()
|
|
|
|
|
: _max_size(256)
|
|
|
|
|
{
|
|
|
|
|
}
|
2019-01-06 12:52:55 -05:00
|
|
|
|
|
|
|
|
public:
|
2024-02-16 00:11:45 -06:00
|
|
|
const
|
2024-02-22 00:11:04 -06:00
|
|
|
std::string
|
2024-02-15 19:53:16 -06:00
|
|
|
insert(std::string const &key_,
|
|
|
|
|
std::string &val_)
|
|
|
|
|
{
|
2024-02-22 00:10:37 -06:00
|
|
|
return NULL;
|
2024-02-15 19:53:16 -06:00
|
|
|
}
|
2024-02-15 20:02:29 -06:00
|
|
|
|
2024-02-15 20:17:32 -06:00
|
|
|
const
|
2024-02-22 00:11:04 -06:00
|
|
|
std::string
|
2024-02-15 20:02:29 -06:00
|
|
|
find(char const *key_)
|
|
|
|
|
{
|
2024-02-22 00:09:31 -06:00
|
|
|
std::string *rv ;
|
|
|
|
|
|
|
|
|
|
rv = nullptr;
|
2024-02-22 00:08:04 -06:00
|
|
|
auto func =
|
|
|
|
|
[&](const auto &v)
|
|
|
|
|
{
|
2024-02-22 00:09:31 -06:00
|
|
|
rv = &v;
|
2024-02-22 00:08:04 -06:00
|
|
|
};
|
|
|
|
|
|
2024-02-22 00:08:11 -06:00
|
|
|
_cache.visit(key_,func);
|
|
|
|
|
|
|
|
|
|
return rv;
|
2024-02-15 20:02:29 -06:00
|
|
|
}
|
2024-02-15 20:14:42 -06:00
|
|
|
|
2024-02-15 19:54:37 -06:00
|
|
|
void
|
|
|
|
|
erase(const char *key_)
|
2024-02-15 20:02:29 -06:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2019-01-06 12:52:55 -05:00
|
|
|
|
|
|
|
|
private:
|
2024-02-15 19:48:28 -06:00
|
|
|
unsigned _max_size;
|
2024-02-16 00:05:23 -06:00
|
|
|
Map _cache;
|
2019-01-06 12:52:55 -05:00
|
|
|
};
|