Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI_physicalQuantity.cc
Go to the documentation of this file.
1/*
2# <<BEGIN-copyright>>
3# Copyright 2019, Lawrence Livermore National Security, LLC.
4# This file is part of the gidiplus package (https://github.com/LLNL/gidiplus).
5# gidiplus is licensed under the MIT license (see https://opensource.org/licenses/MIT).
6# SPDX-License-Identifier: MIT
7# <<END-copyright>>
8*/
9
10#include "GIDI.hpp"
11#include <HAPI.hpp>
12
13namespace GIDI {
14
15/*! \class PhysicalQuantity
16 * Class to store a physical quantity. A physical quantity is a value (e.g., 13.2) with a unit (e.g., 'cm'). The physical quantity
17 * can be unitless (i.e., the unit can be an empty string). Examples a physical quantities are '13.2 cm', '0.132 m', '4.5 kg'.
18 */
19
20/* *********************************************************************************************************//**
21 *
22 * @param a_node [in] The **HAPI::Node** to be parsed and used to construct the PhysicalQuantity.
23 * @param a_setupInfo [in] Information create my the Protare constructor to help in parsing.
24 ***********************************************************************************************************/
25
27 Form( a_node, a_setupInfo, FormType::physicalQuantity ),
28 m_value( a_node.attribute_as_double( GIDI_valueChars ) ),
29 m_unit( a_node.attribute_as_string( GIDI_unitChars ) ) {
30
31}
32
33/* *********************************************************************************************************//**
34 *
35 * @param a_value [in] The physical quantity's value.
36 * @param a_unit [in] The physical quantity's unit.
37 ***********************************************************************************************************/
38
39PhysicalQuantity::PhysicalQuantity( double a_value, std::string const &a_unit ) :
41 m_value( a_value ),
42 m_unit( a_unit ) {
43
44}
45
46/* *********************************************************************************************************//**
47 ***********************************************************************************************************/
48
52
53/* *********************************************************************************************************//**
54 * The assignment operator. This method sets the members of *this* to those of *a_rhs* except for those
55 * not set by base classes.
56 *
57 * @param a_rhs [in] Instance whose member are used to set the members of *this*.
58 ***********************************************************************************************************/
59
61
62 if( this != &a_rhs ) {
63 Form::operator=( a_rhs );
64
65 m_value = a_rhs.value( );
66 m_unit = a_rhs.unit( );
67 }
68
69 return( *this );
70}
71
72/* *********************************************************************************************************//**
73 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
74 *
75 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
76 * @param a_indent [in] The amount to indent *this* node.
77 ***********************************************************************************************************/
78
79void PhysicalQuantity::toXMLList( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent ) const {
80
81 std::string attributes = a_writeInfo.addAttribute( GIDI_valueChars, LUPI::Misc::doubleToShortestString( value( ) ) ) + a_writeInfo.addAttribute( GIDI_unitChars, unit( ) );
82
83 a_writeInfo.addNodeStarterEnder( a_indent, moniker( ), attributes );
84}
85
86/* *********************************************************************************************************//**
87 * Writes the information of *a_physicalQuantity* to *a_os*.
88 *
89 * @param a_os [out] The stream to write to.
90 * @param a_physicalQuantity [in] The PhysicalQuantity whose information is written.
91 ***********************************************************************************************************/
92
93std::ostream &operator<<( std::ostream &a_os, PhysicalQuantity const &a_physicalQuantity ) {
94
95 a_os << a_physicalQuantity.value( ) << " " << a_physicalQuantity.unit( );
96
97 return( a_os );
98}
99
100}
#define GIDI_unitChars
Definition GIDI.hpp:439
#define GIDI_valueChars
Definition GIDI.hpp:445
Form & operator=(Form const &a_rhs)
Definition GIDI_form.cc:93
Form(FormType a_type)
Definition GIDI_form.cc:25
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent="") const
std::string const & unit() const
Definition GIDI.hpp:729
PhysicalQuantity & operator=(PhysicalQuantity const &a_rhs)
PhysicalQuantity(HAPI::Node const &a_node, SetupInfo &a_setupInfo)
double value() const
Definition GIDI.hpp:728
std::string const & moniker() const
Definition GUPI.hpp:102
void addNodeStarterEnder(std::string const &indent, std::string const &a_moniker, std::string const &a_attributes="")
Definition GUPI.hpp:57
std::string addAttribute(std::string const &a_name, std::string const &a_value) const
Definition GUPI.hpp:60
Definition GIDI.hpp:32
FormType
Definition GIDI.hpp:118
std::ostream & operator<<(std::ostream &a_os, PhysicalQuantity const &a_physicalQuantity)
std::string doubleToShortestString(double a_value, int a_significantDigits=15, int a_favorEFormBy=0)
Definition LUPI_misc.cc:349