Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
PoPI_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 <string.h>
11#include <stdlib.h>
12#include <math.h>
13
14#include "PoPI.hpp"
15
16namespace PoPI {
17
18#define PoPI_valueChars "value"
19#define PoPI_unitChars "unit"
20
21/*! \class PhysicalQuantity
22 * The base class for all PhysicalQuantity classes.
23 */
24
25/* *********************************************************************************************************//**
26 * @param a_node [in] The **HAPI::Node** node to be parsed.
27 * @param a_class [in] The class of the physical quantity.
28 ***********************************************************************************************************/
29
31 m_class( a_class ),
32 m_tag( a_node.name( ) ),
33 m_label( a_node.attribute( PoPI_labelChars ).value( ) ),
34 m_valueString( a_node.attribute( PoPI_valueChars ).value( ) ),
35 m_unit( a_node.attribute( PoPI_unitChars ).value( ) ) {
36
37}
38
39/* *********************************************************************************************************//**
40 ***********************************************************************************************************/
41
45
46/* *********************************************************************************************************//**
47 * Adds the contents of *this* to *a_XMLList* where each item in *a_XMLList* is one line (without linefeeds) to output as an XML representation of *this*.
48 *
49 * @param a_XMLList [in] The list to add an XML output representation of *this* to.
50 * @param a_indent1 [in] The amount of indentation to added to each line added to *a_XMLList*.
51 ***********************************************************************************************************/
52
53void PhysicalQuantity::toXMLList( std::vector<std::string> &a_XMLList, std::string const &a_indent1 ) const {
54
55 std::string _unit;
56
57 if( m_unit.size( ) > 0 ) _unit = "\" unit=\"" + m_unit;
58
59 std::string header = a_indent1 + "<" + m_tag + " label=\"" + m_label + "\" value=\"" + valueToString( ) + _unit + "\"/>";
60 a_XMLList.push_back( std::move( header ) );
61}
62
63/*! \class PQ_double
64 * The physical quantity class representing a double.
65 */
66
67/* *********************************************************************************************************//**
68 * @param a_node [in] The **HAPI::Node** node to be parsed.
69 ***********************************************************************************************************/
70
73 m_value( 0.0 ) {
74
75 initialize( );
76}
77
78/* *********************************************************************************************************//**
79 * @param a_node [in] The **HAPI::Node** node to be parsed.
80 * @param a_class [in] The class of the physical quantity.
81 ***********************************************************************************************************/
82
83PQ_double::PQ_double( HAPI::Node const &a_node, PQ_class a_class ) :
84 PhysicalQuantity( a_node, a_class ),
85 m_value( 0.0 ) {
86
87 initialize( );
88}
89
90/* *********************************************************************************************************//**
91 * This method is called my the constructors to do the common stuff.
92 ***********************************************************************************************************/
93
94void PQ_double::initialize( ) {
95
96 char *last;
97
98 if( valueString( ) != "" ) m_value = strtod( valueString( ).c_str( ), &last );
99}
100
101/* *********************************************************************************************************//**
102 ***********************************************************************************************************/
103
107
108/* *********************************************************************************************************//**
109 * Returns the value of *this* in units of *a_unit*. Currently, unit conversion is not supported.
110 *
111 * @param a_unit [in] The requested unit to return the value in.
112 *
113 * @return The value of *this* in units of *a_unit*.
114 ***********************************************************************************************************/
115
116double PQ_double::value( LUPI_maybeUnused char const *a_unit ) const {
117
118 return( m_value );
119}
120
121/* *********************************************************************************************************//**
122 * Converts the double value of self to a string.
123 *
124 * @return The string value of *this*.
125 ***********************************************************************************************************/
126
127std::string PQ_double::valueToString( void ) const {
128
129 std::string sValue = LUPI::Misc::argumentsToString( "%.12g", m_value );
130 if( fabs( m_value ) < 1e10 ) {
131 if( sValue.find( '.' ) == std::string::npos ) sValue = LUPI::Misc::argumentsToString( "%.1f", m_value );
132 }
133
134 return( sValue );
135}
136
137/*! \class PQ_integer
138 * The physical quantity class representing an integer.
139 */
140
141/* *********************************************************************************************************//**
142 * @param a_node [in] The **HAPI::Node** node to be parsed.
143 ***********************************************************************************************************/
144
147 m_value( a_node.attribute( PoPI_valueChars ).as_int( ) ) {
148}
149
150/* *********************************************************************************************************//**
151 ***********************************************************************************************************/
152
156
157/* *********************************************************************************************************//**
158 * Returns the value of *this* in units of *a_unit*. Currently, unit conversion is not supported.
159 *
160 * @param a_unit [in] The requested unit to return the value in.
161 *
162 * @return The value of *this* in units of *a_unit*.
163 ***********************************************************************************************************/
164
165int PQ_integer::value( LUPI_maybeUnused char const *a_unit ) const {
166
167 return( m_value );
168}
169
170/* *********************************************************************************************************//**
171 * Convert the integer value of *this* to a string.
172 *
173 * @return The string value of *this*.
174 ***********************************************************************************************************/
175
176std::string PQ_integer::valueToString( void ) const {
177
178 return( LUPI::Misc::argumentsToString( "%d", m_value ) );
179}
180
181/*! \class PQ_fraction
182 * The physical quantity class representing a fraction.
183 */
184
185/* *********************************************************************************************************//**
186 * @param a_node [in] The **HAPI::Node** node to be parsed.
187 ***********************************************************************************************************/
188
191
192}
193
194/* *********************************************************************************************************//**
195 ***********************************************************************************************************/
196
200
201/* *********************************************************************************************************//**
202 * Returns the value of *this* in units of *a_unit*. Currently, unit conversion is not supported.
203 *
204 * @param a_unit [in] The requested unit to return the value in.
205 *
206 * @return The value of *this* in units of *a_unit*.
207 ***********************************************************************************************************/
208
209std::string PQ_fraction::value( LUPI_maybeUnused char const *a_unit ) const {
210
211 return( valueString( ) );
212}
213
214/* *********************************************************************************************************//**
215 * Returns the value as a string.
216 *
217 * @return The string value of *this*.
218 ***********************************************************************************************************/
219
220std::string PQ_fraction::valueToString( void ) const {
221
222 return( valueString( ) );
223}
224
225/*! \class PQ_string
226 * The physical quantity class represented as a string.
227 */
228
229/* *********************************************************************************************************//**
230 * @param a_node [in] The **HAPI::Node** node to be parsed.
231 ***********************************************************************************************************/
232
234 PhysicalQuantity( a_node, PQ_class::string ) {
235
236}
237
238/* *********************************************************************************************************//**
239 ***********************************************************************************************************/
240
244
245/* *********************************************************************************************************//**
246 * Returns the value of *this* in units of *a_unit*. Currently, unit conversion is not supported.
247 *
248 * @param a_unit [in] The requested unit to return the value in.
249 *
250 * @return The value of *this* in units of *a_unit*.
251 ***********************************************************************************************************/
252
253std::string PQ_string::value( LUPI_maybeUnused char const *a_unit ) const {
254
255 return( valueString( ) );
256}
257
258/* *********************************************************************************************************//**
259 * Returns the string value of *this*.
260 *
261 * @return The string value of *this*.
262 ***********************************************************************************************************/
263
264std::string PQ_string::valueToString( void ) const {
265
266 return( valueString( ) );
267}
268
269/*! \class PQ_shell
270 * The physical quantity that represents the probability as a double that a process like internal conversion or pair production occurs.
271 */
272
273/* *********************************************************************************************************//**
274 * @param a_node [in] The **HAPI::Node** node to be parsed.
275 ***********************************************************************************************************/
276
278 PQ_double( a_node, PQ_class::shell ) {
279
280}
281
282/* *********************************************************************************************************//**
283 ***********************************************************************************************************/
284
288
289}
#define LUPI_maybeUnused
#define PoPI_labelChars
Definition PoPI.hpp:90
#define PoPI_unitChars
#define PoPI_valueChars
PQ_double(HAPI::Node const &a_node)
double value(void) const
Definition PoPI.hpp:443
virtual std::string valueToString(void) const
PQ_fraction(HAPI::Node const &a_node)
virtual std::string valueToString(void) const
std::string value(void) const
PQ_integer(HAPI::Node const &a_node)
virtual std::string valueToString(void) const
int value(void) const
Definition PoPI.hpp:465
PQ_shell(HAPI::Node const &a_node)
std::string value(void) const
Definition PoPI.hpp:502
virtual std::string valueToString(void) const
PQ_string(HAPI::Node const &a_node)
void toXMLList(std::vector< std::string > &a_XMLList, std::string const &a_indent1) const
std::string const & valueString(void) const
Definition PoPI.hpp:419
virtual std::string valueToString(void) const =0
PhysicalQuantity(HAPI::Node const &a_node, PQ_class a_class)
std::string argumentsToString(char const *a_format,...)
Definition LUPI_misc.cc:305
Definition PoPI.hpp:28
PQ_class
Definition PoPI.hpp:105