Program Listing for File SimGalaxy.hpp

↰ Return to documentation for file (src/core/SimGalaxy.hpp)

#ifndef SIMGALAXY_HPP
#define SIMGALAXY_HPP

#include "../io/OutputManager.hpp"
#include "../io/SimControls.hpp"
#include <atomic>
#include <memory>

namespace core
{

    class SimGalaxy
    {
    public:

        SimGalaxy(const io::SimControls& simControls,
            std::unique_ptr<io::OutputManager> outputManager, bool restart = false);

        // Disallow copying and moving: this object owns the output
        // manager exclusively, so duplicating or relocating it makes
        // no sense
        SimGalaxy(const SimGalaxy&) = delete;
        auto operator=(const SimGalaxy&) -> SimGalaxy& = delete;
        SimGalaxy(SimGalaxy&&) = delete;
        auto operator=(SimGalaxy&&) -> SimGalaxy& = delete;

        ~SimGalaxy() = default;

        static constexpr int sigtermExitCode = 143;

        auto run() -> int;

        [[nodiscard]] auto trialsCompleted() const -> unsigned long
        {
            return trialsCompleted_.load(std::memory_order_relaxed);
        }

    private:

        void runTrial(unsigned long trialNum);

        const io::SimControls& simControls_;
        std::unique_ptr<io::OutputManager> outputManager_;
        std::atomic<unsigned long> trialsCompleted_{0};
        bool restart_ = false;
    };

} // namespace core

#endif // SIMGALAXY_HPP