|
|
|||
File indexing completed on 2025-12-15 10:11:01
0001 //------------------------------- -*- C++ -*- -------------------------------// 0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details 0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT) 0004 //---------------------------------------------------------------------------// 0005 //! \file celeritas/phys/AtomicNumber.hh 0006 //---------------------------------------------------------------------------// 0007 #pragma once 0008 0009 #include "corecel/Assert.hh" 0010 0011 namespace celeritas 0012 { 0013 //---------------------------------------------------------------------------// 0014 /*! 0015 * Type-safe atomic number identifier. 0016 * 0017 * Atomic numbers (Z and A) have constraints that integers do not (zero is not 0018 * an atomic number, dividing one atomic number by another is meaningless) so 0019 * this type improves the semantics and safety. 0020 * 0021 * Generally speaking, Z and A numbers are used during setup and when 0022 * evaluating expressions that use atomic charge. Z or A should not be used to 0023 * "index" data during runtime. 0024 * 0025 * Constructing with a nonpositive values gives the result in a `false` state 0026 * (\c get will throw a \c DebugError). 0027 */ 0028 class AtomicNumber 0029 { 0030 public: 0031 //! Construct with an invalid/unassigned value of zero 0032 constexpr AtomicNumber() = default; 0033 0034 //! Construct with the Z value 0035 explicit CELER_CONSTEXPR_FUNCTION AtomicNumber(int z_or_a_value) 0036 : value_(z_or_a_value) 0037 { 0038 } 0039 0040 //! True if value is assigned/valid 0041 explicit CELER_CONSTEXPR_FUNCTION operator bool() const 0042 { 0043 return value_ > 0; 0044 } 0045 0046 //! Get the Z or A value 0047 CELER_CONSTEXPR_FUNCTION int unchecked_get() const { return value_; } 0048 0049 // Get the Z or A value 0050 inline CELER_FUNCTION int get() const; 0051 0052 private: 0053 int value_{0}; 0054 }; 0055 0056 //---------------------------------------------------------------------------// 0057 // INLINE DEFINITIONS 0058 //---------------------------------------------------------------------------// 0059 /*! 0060 * Get Z or A value. 0061 */ 0062 inline CELER_FUNCTION int AtomicNumber::get() const 0063 { 0064 CELER_ENSURE(*this); 0065 return value_; 0066 } 0067 0068 //---------------------------------------------------------------------------// 0069 // COMPARATORS 0070 //---------------------------------------------------------------------------// 0071 #define CELER_DEFINE_ATOMICNUMBER_CMP(TOKEN) \ 0072 CELER_CONSTEXPR_FUNCTION bool operator TOKEN(AtomicNumber lhs, \ 0073 AtomicNumber rhs) \ 0074 { \ 0075 return lhs.unchecked_get() TOKEN rhs.unchecked_get(); \ 0076 } 0077 0078 CELER_DEFINE_ATOMICNUMBER_CMP(==) 0079 CELER_DEFINE_ATOMICNUMBER_CMP(!=) 0080 CELER_DEFINE_ATOMICNUMBER_CMP(<) 0081 CELER_DEFINE_ATOMICNUMBER_CMP(>) 0082 CELER_DEFINE_ATOMICNUMBER_CMP(<=) 0083 CELER_DEFINE_ATOMICNUMBER_CMP(>=) 0084 0085 #undef CELER_DEFINE_ATOMICNUMBER_CMP 0086 0087 //---------------------------------------------------------------------------// 0088 } // namespace celeritas
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|