Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
LUPI_statusMessageReporting.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 <errno.h>
11#include <stdlib.h>
12#include <string.h>
13#include <sys/stat.h>
14#include <iostream>
15#include <iomanip>
16
17#include <LUPI.hpp>
18
19namespace LUPI {
20
21/* *********************************************************************************************************//**
22 * Constructor for a StatusMessageReporting instance.
23 ***********************************************************************************************************/
24
26
27 int status = smr_initialize( &m_smr, smr_status_Ok );
28
29 if( status != 0 ) throw( "StatusMessageReporting::StatusMessageReporting: Oops." ); // Currently, this should never happend.
30}
31
32/* *********************************************************************************************************//**
33 * Destructor for a StatusMessageReporting instance.
34 ***********************************************************************************************************/
35
40
41/* *********************************************************************************************************//**
42 * Returns the first *a_reports* reports from *m_smr* with *a_prefix* appended to the beginning of the returned string.
43 *
44 * @param a_prefix [in] A string added to the beginning of the message.
45 * @param a_report [in] The maximum number of reports to include in the message.
46 * @param a_clear [in] If *true*, calls the **clear()** method after the message is constructed.
47 ***********************************************************************************************************/
48
49std::string StatusMessageReporting::constructMessage( std::string a_prefix, int a_reports, bool a_clear ) {
50
51 std::string sep( "" );
52 std::string message( a_prefix );
53 statusMessageReport const *report;
54
55 if( a_prefix == "" ) sep = "\n";
56
57 for( report = smr_firstReport( &m_smr ); report != NULL; report = smr_nextReport( report ), --a_reports ) {
58 if( a_reports == 0 ) break;
59
60 char *reportMessage = smr_copyMessage( report );
61 if( reportMessage != nullptr ) {
62 message += sep;
63 message += reportMessage;
64 free( reportMessage );
65 sep = "\n";
66 }
67 }
68 if( a_clear ) clear( );
69
70 return( message );
71}
72
73/* *********************************************************************************************************//**
74 * Returns the first *a_reports* reports from *m_smr* with *a_prefix* appended to the beginning of the returned string.
75 *
76 * @param a_prefix [in] A string added to the beginning of the message.
77 * @param a_report [in] The maximum number of reports to include in the message.
78 * @param a_clear [in] If *true*, calls the **clear()** method after the message is constructed.
79 ***********************************************************************************************************/
80
81std::string StatusMessageReporting::constructFullMessage( std::string const &a_prefix, int a_reports, bool a_clear ) {
82
83 std::string message( a_prefix );
84 statusMessageReport const *report;
85
86 for( report = smr_firstReport( &m_smr ); report != NULL; report = smr_nextReport( report ), --a_reports ) {
87 if( a_reports == 0 ) break;
88
89 char *reportMessage = smr_copyFullMessage( report );
90 if( reportMessage != nullptr ) {
91 message += '\n';
92 message += reportMessage;
93 free( reportMessage );
94 }
95 }
96 if( a_clear ) clear( );
97
98 return( message );
99}
100
101} // End of namespace LUPI.
std::string constructFullMessage(std::string const &a_prefix, int a_reports=1, bool a_clear=false)
std::string constructMessage(std::string a_prefix, int a_reports=1, bool a_clear=false)
void free(voidpf ptr)
Definition LUPI.hpp:40
char * smr_copyMessage(statusMessageReport const *report)
int smr_initialize(statusMessageReporting *smr, enum smr_status verbosity)
statusMessageReport const * smr_firstReport(statusMessageReporting const *smr)
void smr_release(statusMessageReporting *smr)
statusMessageReport const * smr_nextReport(statusMessageReport const *report)
char * smr_copyFullMessage(statusMessageReport const *report)