Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
LUPI_formatVersion.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 <limits.h>
11
12#include "LUPI.hpp"
13
14namespace LUPI {
15
16/*! \class FormatVersion
17 * Class to store GNDS format.
18 */
19
20/* *********************************************************************************************************//**
21 ***********************************************************************************************************/
22
24 m_format( "" ),
25 m_major( -1 ),
26 m_minor( -1 ),
27 m_patch( "" ) {
28
29}
30
31/* *********************************************************************************************************//**
32 * @param a_formatVersion [in] The GNDS format.
33 ***********************************************************************************************************/
34
35FormatVersion::FormatVersion( std::string const &a_formatVersion ) :
36 m_format( a_formatVersion ),
37 m_major( -1 ),
38 m_minor( -1 ),
39 m_patch( "" ) {
40
41 setFormat( a_formatVersion );
42}
43
44/* *********************************************************************************************************//**
45 * @param a_formatVersion [in] The GNDS format.
46 ***********************************************************************************************************/
47
49 m_format( a_formatVersion.format( ) ),
50 m_major( a_formatVersion.major( ) ),
51 m_minor( a_formatVersion.minor( ) ),
52 m_patch( a_formatVersion.patch( ) ) {
53
54}
55
56/* *********************************************************************************************************//**
57 * The assignment operator. This method sets the members of *this* to those of *a_rhs* except for those
58 * not set by base classes.
59 *
60 * @param a_rhs [in] Instance whose member are used to set the members of *this*.
61 ***********************************************************************************************************/
62
64
65 if( this != &a_rhs ) {
66 m_format = a_rhs.format( );
67 m_major = a_rhs.major( );
68 m_minor = a_rhs.minor( );
69 m_patch = a_rhs.patch( );
70 }
71
72 return( *this );
73}
74
75/* *********************************************************************************************************//**
76 * Set the format to *a_formatVersion* and parse its components.
77 *
78 * @param a_formatVersion [in] The GNDS format.
79 *
80 * @return true if format of the form "MAJOR.MINOR[.PATCH]" where MAJOR and MINOR are integers. Otherwise returns false.
81 ***********************************************************************************************************/
82
83bool FormatVersion::setFormat( std::string const &a_formatVersion ) {
84
85 m_format = a_formatVersion;
86
87 std::vector<std::string> formatItems = Misc::splitString( a_formatVersion, '.' );
88
89 if( ( formatItems.size( ) < 2 ) || ( formatItems.size( ) > 3 ) ) goto err;
90
91 if( !Misc::stringToInt( formatItems[0], m_major ) ) goto err;
92 if( !Misc::stringToInt( formatItems[1], m_minor ) ) goto err;
93
94 if( formatItems.size( ) == 3 ) m_patch = formatItems[2];
95
96 return( true );
97
98err:
99 m_major = -1;
100 m_minor = -1;
101 m_patch = "";
102 return( false );
103}
104
105/* *********************************************************************************************************//**
106 * Returns true if m_format is a supported format and false otherwise;
107 *
108 * @return true if format is supported and false otherwise.
109 ***********************************************************************************************************/
110
112
113 if( m_format == GNDS_formatVersion_1_10Chars ) return( true );
114 if( m_format == GNDS_formatVersion_2_0Chars ) return( true );
115 if( m_format == GNDS_formatVersion_2_0_LLNL_4Chars ) return( true );
116 if( m_format == GNDS_formatVersion_2_1Chars ) return( true );
117
118 return( false );
119}
120
121} // End namespace LUPI.
#define GNDS_formatVersion_2_0Chars
Definition LUPI.hpp:49
#define GNDS_formatVersion_1_10Chars
Definition LUPI.hpp:48
#define GNDS_formatVersion_2_0_LLNL_4Chars
Definition LUPI.hpp:50
#define GNDS_formatVersion_2_1Chars
Definition LUPI.hpp:51
int minor() const
Definition LUPI.hpp:76
std::string const & format() const
Definition LUPI.hpp:74
FormatVersion & operator=(FormatVersion const &a_rhs)
int major() const
Definition LUPI.hpp:75
bool setFormat(std::string const &a_formatVersion)
std::string const & patch() const
Definition LUPI.hpp:77
std::vector< std::string > splitString(std::string const &a_string, char a_delimiter, bool a_strip=false)
Definition LUPI_misc.cc:103
bool stringToInt(std::string const &a_string, int &a_value)
Definition LUPI_misc.cc:260
Definition LUPI.hpp:40