ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
core/ek/EKReactions.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022-2023 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU 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 * ESPResSo 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 General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <algorithm>
23#include <cassert>
24#include <memory>
25#include <vector>
26
27namespace EK {
28
29template <class EKReaction> class EKReactions {
30 using container_type = std::vector<std::shared_ptr<EKReaction>>;
31
32public:
33 using value_type = typename container_type::value_type;
34 using iterator = typename container_type::iterator;
35 using const_iterator = typename container_type::const_iterator;
36
37private:
38 container_type m_ekreactions;
39
40public:
41 bool contains(std::shared_ptr<EKReaction> const &ek_reaction) const noexcept {
42 return std::find(begin(), end(), ek_reaction) != end();
43 }
44 void add(std::shared_ptr<EKReaction> const &ek_reaction) {
45 assert(not contains(ek_reaction));
46 m_ekreactions.emplace_back(ek_reaction);
47 }
48 void remove(std::shared_ptr<EKReaction> const &ek_reaction) {
49 assert(contains(ek_reaction));
50 std::erase(m_ekreactions, ek_reaction);
51 }
52
53 iterator begin() { return m_ekreactions.begin(); }
54 iterator end() { return m_ekreactions.end(); }
55 const_iterator begin() const { return m_ekreactions.begin(); }
56 const_iterator end() const { return m_ekreactions.end(); }
57 [[nodiscard]] bool empty() const { return m_ekreactions.empty(); }
58};
59
60} // namespace EK
void remove(std::shared_ptr< EKReaction > const &ek_reaction)
typename container_type::const_iterator const_iterator
bool contains(std::shared_ptr< EKReaction > const &ek_reaction) const noexcept
const_iterator begin() const
typename container_type::value_type value_type
void add(std::shared_ptr< EKReaction > const &ek_reaction)
typename container_type::iterator iterator
const_iterator end() const