diff --git a/assets/static/reaclib/include/reaclib.h b/assets/static/reaclib/include/reaclib.h index 7cf58f66..014a63c2 100644 --- a/assets/static/reaclib/include/reaclib.h +++ b/assets/static/reaclib/include/reaclib.h @@ -104,6 +104,10 @@ namespace serif::network::reaclib { << "Chapter: " << reaction.m_chapter << ")"; return os; } + + friend bool operator==(const REACLIBReaction& lhs, const REACLIBReaction& rhs); + + friend bool operator!=(const REACLIBReaction& lhs, const REACLIBReaction& rhs); }; class REACLIBReactionSet { @@ -136,6 +140,15 @@ namespace serif::network::reaclib { return false; } + [[nodiscard]] bool contains(const REACLIBReaction& reaction) const { + for (const auto& r : m_reactions) { + if (r == reaction) { + return true; + } + } + return false; + } + [[nodiscard]] size_t size() const { return m_reactions.size(); } @@ -170,6 +183,16 @@ namespace serif::network::reaclib { return m_reactions.end(); } + bool containsSpecies(const serif::atomic::Species &species) const { + for (const auto& reaction : m_reactions) { + if (std::ranges::find(reaction.reactants(), species) != reaction.reactants().end() || + std::ranges::find(reaction.products(), species) != reaction.products().end()) { + return true; + } + } + return false; + } + [[nodiscard]] const REACLIBReaction& operator[](size_t index) const { if (index >= m_reactions.size()) { throw std::out_of_range("Index out of range in REACLIBReactionSet."); @@ -188,6 +211,7 @@ namespace serif::network::reaclib { [[nodiscard]] auto end() const { return m_reactions.cend(); } + }; static std::unordered_map s_all_reaclib_reactions; static bool s_initialized = false; @@ -198,6 +222,18 @@ namespace serif::network::reaclib { inline bool operator!=(const REACLIBReaction& lhs, const REACLIBReaction& rhs) { return !(lhs == rhs); } + + inline bool operator==(const REACLIBReactionSet& lhs, const REACLIBReactionSet& rhs) { + if (lhs.size() != rhs.size()) return false; + for (const auto& reaction : lhs) { + if (!rhs.contains(reaction)) return false; + } + return true; + } + + inline bool operator!=(const REACLIBReactionSet& lhs, const REACLIBReactionSet& rhs) { + return !(lhs == rhs); + } } namespace std { diff --git a/assets/static/reaclib/include/reactions.h b/assets/static/reaclib/include/reactions.h index 1ea25628..ad070da3 100644 --- a/assets/static/reaclib/include/reactions.h +++ b/assets/static/reaclib/include/reactions.h @@ -8,11 +8,10 @@ // Note: Only reactions with species defined in the atomicSpecies.h header will be included at compile time. #pragma once #include "atomicSpecies.h" +#include "species.h" #include "reaclib.h" namespace serif::network::reaclib { - - inline void initializeAllReaclibReactions() { if (s_initialized) return; // already initialized s_initialized = true;