Skip to content

Commit

Permalink
Merge pull request #276 from LLNL/feature/nselliott/constexpr-updates
Browse files Browse the repository at this point in the history
Add constexpr to some simple types
  • Loading branch information
nselliott authored Aug 12, 2024
2 parents c888a99 + fcf82ab commit 8e4e00a
Show file tree
Hide file tree
Showing 18 changed files with 257 additions and 397 deletions.
4 changes: 2 additions & 2 deletions .gitlab/jobs/tioga.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ release_resources:
####
# Build and test jobs for specific compilers, extends generic tioga build and
# test job
cce_16_0_0_rocm_5_6_0:
amdclang_rocm_6.0.2:
variables:
COMPILER: "cce-16.0.0-rocm-5.6.0"
COMPILER: "amdclang-rocm-6.0.2-gfx90a"
extends: .job_on_tioga
56 changes: 2 additions & 54 deletions source/SAMRAI/hier/BlockId.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,61 +16,9 @@
namespace SAMRAI {
namespace hier {

const BlockId
BlockId::s_invalid_id(
tbox::MathUtilities<int>::getMax());
const BlockId BlockId::s_zero_id(0);
const BlockId BlockId::s_invalid_id(s_invalid_val);
const BlockId BlockId::s_zero_id(s_zero_val);

/*
*******************************************************************************
*******************************************************************************
*/
BlockId::BlockId():
d_value(invalidId().d_value)
{
}

/*
*******************************************************************************
*******************************************************************************
*/
BlockId::BlockId(
const BlockId& other):
d_value(other.d_value)
{
}

/*
*******************************************************************************
*******************************************************************************
*/
BlockId::BlockId(
const unsigned int& value):
d_value(value)
{
}

/*
*******************************************************************************
*******************************************************************************
*/
BlockId::BlockId(
const int& value):
d_value(static_cast<unsigned int>(value))
{
TBOX_ASSERT(value >=0);
}

/*
*******************************************************************************
*******************************************************************************
*/
BlockId::~BlockId()
{
#ifdef DEBUG_CHECK_ASSERTIONS
d_value = s_invalid_id.d_value;
#endif
}

}
}
75 changes: 43 additions & 32 deletions source/SAMRAI/hier/BlockId.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define included_hier_BlockId

#include "SAMRAI/SAMRAI_config.h"
#include "SAMRAI/tbox/MathUtilities.h"
#include "SAMRAI/tbox/Utilities.h"

#include <iostream>
Expand All @@ -36,21 +37,27 @@ class BlockId
/*!
* @brief Default constructor sets the value to invalid.
*/
BlockId();
constexpr BlockId() :
d_value(s_invalid_val)
{
}

/*!
* @brief Copy constructor.
*/
BlockId(
const BlockId& other);
constexpr BlockId(
const BlockId& other) = default;

/*!
* @brief Construct from an unsigned int.
*
* This method is explicit to prevent automatic conversion.
*/
explicit BlockId(
const unsigned int& value);
constexpr explicit BlockId(
const unsigned int& value) :
d_value(value)
{
}

/*!
* @brief Construct from a signed int.
Expand All @@ -59,13 +66,17 @@ class BlockId
*
* @pre value >= 0
*/
explicit BlockId(
const int& value);
constexpr explicit BlockId(
const int& value) :
d_value(static_cast<unsigned int>(value))
{
TBOX_CONSTEXPR_ASSERT(value >=0);
}

/*!
* @brief Default constructor.
*/
~BlockId();
~BlockId() = default;

/*!
* @brief Assignment operator.
Expand All @@ -74,28 +85,24 @@ class BlockId
*
* @return @c *this
*/
BlockId&
constexpr BlockId&
operator = (
const BlockId& rhs)
{
d_value = rhs.d_value;
return *this;
}
const BlockId& rhs) = default;

/*!
* @brief Set to an int value.
*
* @param[in] rhs
*/
void
constexpr void
setId(
const int& rhs)
{
TBOX_ASSERT(rhs >= 0);
TBOX_CONSTEXPR_ASSERT(rhs >= 0);
d_value = static_cast<block_t>(rhs);
}

void
constexpr void
setId(
const unsigned int& rhs)
{
Expand All @@ -105,16 +112,16 @@ class BlockId
/*!
* @brief Whether the value is valid.
*/
bool
constexpr bool
isValid() const
{
return d_value != s_invalid_id.d_value;
return d_value != s_invalid_val;
}

/*!
* @brief Access the numerical value.
*/
const block_t&
constexpr const block_t&
getBlockValue() const
{
return d_value;
Expand Down Expand Up @@ -149,7 +156,7 @@ class BlockId
*
* @param[in] rhs
*/
bool
constexpr bool
operator == (
const BlockId& rhs) const
{
Expand All @@ -163,7 +170,7 @@ class BlockId
*
* @param[in] rhs
*/
bool
constexpr bool
operator != (
const BlockId& rhs) const
{
Expand All @@ -177,7 +184,7 @@ class BlockId
*
* @param[in] rhs
*/
bool
constexpr bool
operator < (
const BlockId& rhs) const
{
Expand All @@ -191,7 +198,7 @@ class BlockId
*
* @param[in] rhs
*/
bool
constexpr bool
operator > (
const BlockId& rhs) const
{
Expand All @@ -205,7 +212,7 @@ class BlockId
*
* @param[in] rhs
*/
bool
constexpr bool
operator <= (
const BlockId& rhs) const
{
Expand All @@ -219,7 +226,7 @@ class BlockId
*
* @param[in] rhs
*/
bool
constexpr bool
operator >= (
const BlockId& rhs) const
{
Expand All @@ -239,7 +246,7 @@ class BlockId
*
* @param[in] rhs
*/
bool
constexpr bool
operator == (
const block_t& rhs) const
{
Expand All @@ -253,7 +260,7 @@ class BlockId
*
* @param[in] rhs
*/
bool
constexpr bool
operator != (
const block_t& rhs) const
{
Expand All @@ -267,7 +274,7 @@ class BlockId
*
* @param[in] rhs
*/
bool
constexpr bool
operator < (
const block_t& rhs) const
{
Expand All @@ -281,7 +288,7 @@ class BlockId
*
* @param[in] rhs
*/
bool
constexpr bool
operator > (
const block_t& rhs) const
{
Expand All @@ -295,7 +302,7 @@ class BlockId
*
* @param[in] rhs
*/
bool
constexpr bool
operator <= (
const block_t& rhs) const
{
Expand All @@ -309,7 +316,7 @@ class BlockId
*
* @param[in] rhs
*/
bool
constexpr bool
operator >= (
const block_t& rhs) const
{
Expand All @@ -336,6 +343,10 @@ class BlockId
*/
unsigned int d_value;

static constexpr unsigned int s_zero_val = 0;
static constexpr unsigned int s_invalid_val =
tbox::MathUtilities<int>::getMax();

/*!
* @brief BlockId with a numerical value of zero.
*/
Expand Down
47 changes: 0 additions & 47 deletions source/SAMRAI/hier/BoxId.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,6 @@
namespace SAMRAI {
namespace hier {

/*
************************************************************************
* Constructors
************************************************************************
*/
BoxId::BoxId():
d_global_id(),
d_periodic_id()
{
}

BoxId::BoxId(
const GlobalId& id,
const PeriodicId& periodic_id):
d_global_id(id),
d_periodic_id(periodic_id)
{
TBOX_ASSERT(periodic_id.isValid());
}

BoxId::BoxId(
const LocalId& local_id,
const int owner,
const PeriodicId& periodic_id):
d_global_id(local_id, owner),
d_periodic_id(periodic_id)
{
TBOX_ASSERT(periodic_id.isValid());
}

BoxId::BoxId(
const BoxId& r):
d_global_id(r.d_global_id),
d_periodic_id(r.d_periodic_id)
{
TBOX_ASSERT(r.d_periodic_id.isValid());
}

/*
************************************************************************
* Destructor
************************************************************************
*/
BoxId::~BoxId()
{
}

/*
******************************************************************************
* Stream-insert operator.
Expand Down
Loading

0 comments on commit 8e4e00a

Please sign in to comment.