DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
UnitBase< T, NativeType > Class Template Reference

#include <DLG4Units.hh>

Collaboration diagram for UnitBase< T, NativeType >:
[legend]

Classes

struct  DefaultUnitsProxy
 
struct  Evaluator
 
struct  NativeProxy
 
struct  ScalableProxy
 

Public Member Functions

 UnitBase ()
 
virtual ~UnitBase ()=default
 
 UnitBase (const UnitBase &other)
 
UnitBaseoperator= (const UnitBase &other)
 
 UnitBase (double f, Derived u)
 
void CheckValue (const G4String &context) const
 
void CheckUnit (const G4String &context) const
 

Static Public Member Functions

static T FromNative (NativeType native_value)
 
static T GetGlobalDefault ()
 

Public Attributes

ScalableProxy< UnitBaseInUnits {*this}
 
DefaultUnitsProxy InDefaultUnits {*this}
 
NativeProxy Native {*this}
 

Static Public Attributes

static T native {1.0}
 

Protected Member Functions

template<typename U = T, typename = std::enable_if_t<!std::is_base_of_v<Unit3Vec, U>>>
G4double ValidNativeUnitValue () const
 
 UnitBase (G4double f)
 

Protected Attributes

std::optional< NativeTypeNativeValue_
 

Detailed Description

template<class T, typename NativeType>
class DLG4::Units::UnitBase< T, NativeType >

CRTP base methods for Unit classes.

Template Parameters
T

Definition at line 90 of file DLG4Units.hh.

Constructor & Destructor Documentation

◆ UnitBase() [1/4]

template<class T , typename NativeType >
UnitBase ( )
inline

Definition at line 241 of file DLG4Units.hh.

242 : NativeValue_(std::nullopt) {
243 }
std::optional< NativeType > NativeValue_
Definition DLG4Units.hh:96

◆ ~UnitBase()

template<class T , typename NativeType >
virtual ~UnitBase ( )
virtualdefault

◆ UnitBase() [2/4]

template<class T , typename NativeType >
UnitBase ( const UnitBase< T, NativeType > &  other)
inline

Definition at line 247 of file DLG4Units.hh.

248 : NativeValue_(other.NativeValue_) {
249 }

◆ UnitBase() [3/4]

template<class T , typename NativeType >
UnitBase ( double  f,
Derived  u 
)
inlineexplicit

Definition at line 256 of file DLG4Units.hh.

257 : NativeValue_(f * u.ValidNativeUnitValue()) {
258 }

◆ UnitBase() [4/4]

template<class T , typename NativeType >
UnitBase ( G4double  f)
inlineexplicitprotected

Definition at line 286 of file DLG4Units.hh.

287 : NativeValue_(f) {
288 };

Member Function Documentation

◆ CheckUnit()

template<class T , typename NativeType >
void CheckUnit ( const G4String &  context) const
inline

Definition at line 273 of file DLG4Units.hh.

273 {
274 CheckValue(context);
275 if (!(NativeValue_ > 0.0)) {
276 G4Exception(context, "InvalidScale", FatalException,
277 "\n Attempted to apply a negative Unit\n");
278 exit(1);
279 }
280 }
void CheckValue(const G4String &context) const
Definition DLG4Units.hh:262

◆ CheckValue()

template<class T , typename NativeType >
void CheckValue ( const G4String &  context) const
inline

Definition at line 262 of file DLG4Units.hh.

262 {
263 // volatile may help with debugging dangling references.
264 volatile bool engagement_flag = NativeValue_.has_value();
265 if (!engagement_flag) {
266 //if (!NativeValue_.has_value()) {
267 G4Exception(context, "InvalidScale", FatalException,
268 "\n Attempted to use a Unit (or measure) before setting it;\n");
269 exit(1);
270 }
271 }

◆ FromNative()

template<class T , typename NativeType >
static T FromNative ( NativeType  native_value)
inlinestatic

Definition at line 238 of file DLG4Units.hh.

238{ return T(native_value); }

◆ GetGlobalDefault()

template<class T , typename NativeType >
static T GetGlobalDefault ( )
inlinestatic

Definition at line 260 of file DLG4Units.hh.

260{ return T(global_default_unit<T>); }

◆ operator=()

template<class T , typename NativeType >
UnitBase & operator= ( const UnitBase< T, NativeType > &  other)
inline

Definition at line 251 of file DLG4Units.hh.

251 {
252 this->NativeValue_ = other.NativeValue_;
253 return *this;
254 }

◆ ValidNativeUnitValue()

template<class T , typename NativeType >
template<typename U = T, typename = std::enable_if_t<!std::is_base_of_v<Unit3Vec, U>>>
G4double ValidNativeUnitValue ( ) const
inlineprotected

Validator for NativeValue_ if used in a unit context, errors if it was not initialized.

Definition at line 231 of file DLG4Units.hh.

231 {
232 this->CheckUnit("ValidNativeUnitValue");
233 return NativeValue_.value();
234 }
void CheckUnit(const G4String &context) const
Definition DLG4Units.hh:273

Member Data Documentation

◆ InDefaultUnits

template<class T , typename NativeType >
DefaultUnitsProxy InDefaultUnits {*this}

Definition at line 225 of file DLG4Units.hh.

225{*this};

◆ InUnits

template<class T , typename NativeType >
ScalableProxy<UnitBase> InUnits {*this}

Definition at line 224 of file DLG4Units.hh.

224{*this};

◆ Native

template<class T , typename NativeType >
NativeProxy Native {*this}

Definition at line 226 of file DLG4Units.hh.

226{*this};

◆ native

template<class T , typename NativeType >
T native {1.0}
inlinestatic

Definition at line 237 of file DLG4Units.hh.

237{1.0};

◆ NativeValue_

template<class T , typename NativeType >
std::optional<NativeType> NativeValue_
protected

Definition at line 96 of file DLG4Units.hh.


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