Search Results
Pool.h
/*
* MoMEMta: a modular implementation of the Matrix Element Method
* Copyright (C) 2016 Universite catholique de Louvain (UCL), Belgium
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <assert.h>
#include <memory>
#include <unordered_map>
#include <momemta/any.h>
#include <momemta/impl/InputTag_fwd.h>
#include <momemta/Value.h>
// A simple memory pool
struct PoolContent {
momemta::any ptr;
bool valid;
};
class Pool {
public:
Pool() = default;
template<typename T, typename... Args> std::shared_ptr<T> put(const InputTag& tag, Args&&... args);
template<typename T> Value<T> get(const InputTag& tag) const;
void alias(const InputTag& from, const InputTag& to);
bool exists(const InputTag& tag) const;
private:
friend class MoMEMta;
friend class Module;
template <typename U>
friend class ValueProxy;
using PoolStorage = std::unordered_map<InputTag, PoolContent>;
friend struct InputTag;
void remove(const InputTag&, bool force = true);
void remove_if_invalid(const InputTag&);
momemta::any reserve(const InputTag&);
template<typename T> std::shared_ptr<const T> raw_get(const InputTag& tag) const;
template<typename T, typename... Args> PoolStorage::iterator create(const InputTag& tag,
bool valid, Args&&... args) const;
public:
class tag_not_found_error: public std::runtime_error {
using std::runtime_error::runtime_error;
};
class duplicated_tag_error: public std::runtime_error {
using std::runtime_error::runtime_error;
};
class constructor_tag_error: public std::runtime_error {
using std::runtime_error::runtime_error;
};
private:
virtual void freeze() final;
Pool(const Pool&) = delete;
Pool& operator=(const Pool&) = delete;
bool m_frozen = false;
mutable PoolStorage m_storage;
};
using PoolPtr = std::shared_ptr<Pool>;