GridFire 0.0.1a
General Purpose Nuclear Network
Loading...
Searching...
No Matches
gridfire::reaction::ReactionSet Class Reference

A collection of Reaction objects. More...

#include <reaction.h>

Inheritance diagram for gridfire::reaction::ReactionSet:
gridfire::reaction::LogicalReactionSet

Public Member Functions

 ReactionSet (std::vector< Reaction > reactions)
 Constructs a ReactionSet from a vector of reactions.
 
 ReactionSet (const ReactionSet &other)
 Copy constructor.
 
ReactionSetoperator= (const ReactionSet &other)
 Copy assignment operator.
 
virtual ~ReactionSet ()=default
 Virtual destructor.
 
virtual void add_reaction (Reaction reaction)
 Adds a reaction to the set.
 
virtual void remove_reaction (const Reaction &reaction)
 Removes a reaction from the set.
 
bool contains (const std::string_view &id) const
 Checks if the set contains a reaction with the given ID.
 
bool contains (const Reaction &reaction) const
 Checks if the set contains the given reaction.
 
virtual size_t size () const
 Gets the number of reactions in the set.
 
void clear ()
 Removes all reactions from the set.
 
bool contains_species (const fourdst::atomic::Species &species) const
 Checks if any reaction in the set involves the given species.
 
bool contains_reactant (const fourdst::atomic::Species &species) const
 Checks if any reaction in the set contains the given species as a reactant.
 
bool contains_product (const fourdst::atomic::Species &species) const
 Checks if any reaction in the set contains the given species as a product.
 
virtual const Reactionoperator[] (size_t index) const
 Accesses a reaction by its index.
 
const Reactionoperator[] (const std::string_view &id) const
 Accesses a reaction by its ID.
 
bool operator== (const ReactionSet &other) const
 Compares this set with another for equality.
 
bool operator!= (const ReactionSet &other) const
 Compares this set with another for inequality.
 
uint64_t hash (uint64_t seed=0) const
 Computes a hash for the entire set.
 
Iterators

Provides iterators to loop over the reactions in the set.

auto begin ()
 
auto begin () const
 
auto end ()
 
auto end () const
 

Private Attributes

quill::Logger * m_logger = fourdst::logging::LogManager::getInstance().getLogger("log")
 
std::vector< Reactionm_reactions
 
std::string m_id
 
std::unordered_map< std::string, Reactionm_reactionNameMap
 Maps reaction IDs to Reaction objects for quick lookup.
 

Detailed Description

A collection of Reaction objects.

This class manages a set of individual Reaction objects, providing efficient lookup by ID and functionality to query the entire set.

Example:

ReactionSet my_set({reaction1, reaction2});
my_set.add_reaction(reaction3);
if (my_set.contains("h1(p,g)h2")) {
const Reaction& r = my_set["h1(p,g)h2"];
}
Represents a single nuclear reaction from a specific data source.
Definition reaction.h:71
ReactionSet(std::vector< Reaction > reactions)
Constructs a ReactionSet from a vector of reactions.
Definition reaction.cpp:140

Definition at line 307 of file reaction.h.

Constructor & Destructor Documentation

◆ ReactionSet() [1/2]

gridfire::reaction::ReactionSet::ReactionSet ( std::vector< Reaction > reactions)
explicit

Constructs a ReactionSet from a vector of reactions.

Parameters
reactionsThe initial vector of Reaction objects.

Definition at line 140 of file reaction.cpp.

◆ ReactionSet() [2/2]

gridfire::reaction::ReactionSet::ReactionSet ( const ReactionSet & other)

Copy constructor.

Parameters
otherThe ReactionSet to copy.

Definition at line 154 of file reaction.cpp.

◆ ~ReactionSet()

virtual gridfire::reaction::ReactionSet::~ReactionSet ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ add_reaction()

void gridfire::reaction::ReactionSet::add_reaction ( Reaction reaction)
virtual

Adds a reaction to the set.

Parameters
reactionThe Reaction to add.

Definition at line 175 of file reaction.cpp.

◆ begin() [1/2]

auto gridfire::reaction::ReactionSet::begin ( )
inline

Definition at line 435 of file reaction.h.

◆ begin() [2/2]

auto gridfire::reaction::ReactionSet::begin ( ) const
inlinenodiscard

Definition at line 436 of file reaction.h.

◆ clear()

void gridfire::reaction::ReactionSet::clear ( )

Removes all reactions from the set.

Definition at line 211 of file reaction.cpp.

◆ contains() [1/2]

bool gridfire::reaction::ReactionSet::contains ( const Reaction & reaction) const
nodiscard

Checks if the set contains the given reaction.

Parameters
reactionThe Reaction to find.
Returns
True if the reaction is in the set, false otherwise.

Definition at line 202 of file reaction.cpp.

◆ contains() [2/2]

bool gridfire::reaction::ReactionSet::contains ( const std::string_view & id) const
nodiscard

Checks if the set contains a reaction with the given ID.

Parameters
idThe ID of the reaction to find.
Returns
True if the reaction is in the set, false otherwise.

Definition at line 193 of file reaction.cpp.

◆ contains_product()

bool gridfire::reaction::ReactionSet::contains_product ( const fourdst::atomic::Species & species) const
nodiscard

Checks if any reaction in the set contains the given species as a product.

Parameters
speciesThe species to check for.
Returns
True if the species is a product in any reaction.

Definition at line 234 of file reaction.cpp.

◆ contains_reactant()

bool gridfire::reaction::ReactionSet::contains_reactant ( const fourdst::atomic::Species & species) const
nodiscard

Checks if any reaction in the set contains the given species as a reactant.

Parameters
speciesThe species to check for.
Returns
True if the species is a reactant in any reaction.

Definition at line 225 of file reaction.cpp.

◆ contains_species()

bool gridfire::reaction::ReactionSet::contains_species ( const fourdst::atomic::Species & species) const
nodiscard

Checks if any reaction in the set involves the given species.

Parameters
speciesThe species to check for.
Returns
True if the species is involved in any reaction.

Definition at line 216 of file reaction.cpp.

◆ end() [1/2]

auto gridfire::reaction::ReactionSet::end ( )
inline

Definition at line 437 of file reaction.h.

◆ end() [2/2]

auto gridfire::reaction::ReactionSet::end ( ) const
inlinenodiscard

Definition at line 438 of file reaction.h.

◆ hash()

uint64_t gridfire::reaction::ReactionSet::hash ( uint64_t seed = 0) const
nodiscard

Computes a hash for the entire set.

Parameters
seedThe seed for the hash function.
Returns
A 64-bit hash value.

The algorithm computes the hash of each individual reaction, sorts the hashes, and then computes a final hash over the sorted list of hashes. This ensures the hash is order-independent.

Definition at line 270 of file reaction.cpp.

◆ operator!=()

bool gridfire::reaction::ReactionSet::operator!= ( const ReactionSet & other) const

Compares this set with another for inequality.

Parameters
otherThe other ReactionSet to compare with.
Returns
True if the sets are not equal.

Definition at line 266 of file reaction.cpp.

◆ operator=()

ReactionSet & gridfire::reaction::ReactionSet::operator= ( const ReactionSet & other)

Copy assignment operator.

Parameters
otherThe ReactionSet to assign from.
Returns
A reference to this ReactionSet.

Definition at line 166 of file reaction.cpp.

◆ operator==()

bool gridfire::reaction::ReactionSet::operator== ( const ReactionSet & other) const

Compares this set with another for equality.

Parameters
otherThe other ReactionSet to compare with.
Returns
True if the sets are equal (same size and hash).

Definition at line 259 of file reaction.cpp.

◆ operator[]() [1/2]

const Reaction & gridfire::reaction::ReactionSet::operator[] ( const std::string_view & id) const
nodiscard

Accesses a reaction by its ID.

Parameters
idThe ID of the reaction to access.
Returns
A const reference to the Reaction.
Exceptions
std::out_of_rangeif no reaction with the given ID exists.

Definition at line 251 of file reaction.cpp.

◆ operator[]() [2/2]

const Reaction & gridfire::reaction::ReactionSet::operator[] ( size_t index) const
nodiscardvirtual

Accesses a reaction by its index.

Parameters
indexThe index of the reaction to access.
Returns
A const reference to the Reaction.
Exceptions
std::out_of_rangeif the index is out of bounds.

Reimplemented in gridfire::reaction::LogicalReactionSet.

Definition at line 243 of file reaction.cpp.

◆ remove_reaction()

void gridfire::reaction::ReactionSet::remove_reaction ( const Reaction & reaction)
virtual

Removes a reaction from the set.

Parameters
reactionThe Reaction to remove.

Definition at line 181 of file reaction.cpp.

◆ size()

virtual size_t gridfire::reaction::ReactionSet::size ( ) const
inlinenodiscardvirtual

Gets the number of reactions in the set.

Returns
The size of the set.

Reimplemented in gridfire::reaction::LogicalReactionSet.

Definition at line 363 of file reaction.h.

Member Data Documentation

◆ m_id

std::string gridfire::reaction::ReactionSet::m_id
private

Definition at line 443 of file reaction.h.

◆ m_logger

quill::Logger* gridfire::reaction::ReactionSet::m_logger = fourdst::logging::LogManager::getInstance().getLogger("log")
private

Definition at line 441 of file reaction.h.

◆ m_reactionNameMap

std::unordered_map<std::string, Reaction> gridfire::reaction::ReactionSet::m_reactionNameMap
private

Maps reaction IDs to Reaction objects for quick lookup.

Definition at line 444 of file reaction.h.

◆ m_reactions

std::vector<Reaction> gridfire::reaction::ReactionSet::m_reactions
private

Definition at line 442 of file reaction.h.


The documentation for this class was generated from the following files: