Skip to content

Commit

Permalink
refactor: Split out time step from indexing header
Browse files Browse the repository at this point in the history
  • Loading branch information
2b-t committed Jun 16, 2024
1 parent a976eb6 commit 6727bd5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 30 deletions.
31 changes: 1 addition & 30 deletions include/lbt/populations/indexing/indexing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,11 @@
#include <tuple>

#include "lbt/common/type_definitions.hpp"
#include "lbt/populations/indexing/timestep.hpp"


namespace lbt {

/**\enum Timestep
* \brief Strongly typed enum for even and odd time steps required for AA access pattern
*/
enum class Timestep: bool {
Even = false,
Odd = true
};

/**\fn operator!
* \brief Negation operator for the timestep
*
* \param[in] ts Timestep to be negated
* \return Negated timestep
*/
inline constexpr Timestep operator! (Timestep const& ts) noexcept {
return (ts == Timestep::Even) ? Timestep::Odd : Timestep::Even;
}

/**\fn Timestep output stream operator
* \brief Output stream operator for the timestep
*
* \param[in,out] os Output stream
* \param[in] ts Timestep to be printed to output stream
* \return Output stream including the type of timestep
*/
inline std::ostream& operator << (std::ostream& os, Timestep const& ts) noexcept {
os << ((ts == Timestep::Even) ? "even time step" : "odd time step");
return os;
}

/**\class Indexing
* \brief Class for indexing of a population
*
Expand Down
48 changes: 48 additions & 0 deletions include/lbt/populations/indexing/timestep.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* \file timestep.hpp
* \brief Base class for timestep
* \author Tobit Flatscher (github.com/2b-t)
*/

#ifndef LBT__INDEXING__TIMESTEP
#define LBT__INDEXING__TIMESTEP
#pragma once

#include <ostream>


namespace lbt {

/**\enum Timestep
* \brief Strongly typed enum for even and odd time steps required for AA access pattern
*/
enum class Timestep: bool {
Even = false,
Odd = true
};

/**\fn operator!
* \brief Negation operator for the timestep
*
* \param[in] ts Timestep to be negated
* \return Negated timestep
*/
inline constexpr Timestep operator! (Timestep const& ts) noexcept {
return (ts == Timestep::Even) ? Timestep::Odd : Timestep::Even;
}

/**\fn Timestep output stream operator
* \brief Output stream operator for the timestep
*
* \param[in,out] os Output stream
* \param[in] ts Timestep to be printed to output stream
* \return Output stream including the type of timestep
*/
inline std::ostream& operator << (std::ostream& os, Timestep const& ts) noexcept {
os << ((ts == Timestep::Even) ? "even time step" : "odd time step");
return os;
}

}

#endif // LBT__INDEXING__TIMESTEP

0 comments on commit 6727bd5

Please sign in to comment.