Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
statusMessageReporting.cc File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "statusMessageReporting.h"

Go to the source code of this file.

Functions

int smr_initialize (statusMessageReporting *smr)
 
int smr_release (statusMessageReporting *smr)
 
int smr_setMessageInfo (statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
 
int smr_vsetMessageInfo (statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt, va_list *args)
 
int smr_setMessageError (statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
 
int smr_vsetMessageError (statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt, va_list *args)
 
char * smr_allocateFormatMessage (const char *fmt,...)
 
char * smr_vallocateFormatMessage (const char *fmt, va_list *args)
 
int smr_isOk (statusMessageReporting *smr)
 
int smr_isInfo (statusMessageReporting *smr)
 
int smr_isError (statusMessageReporting *smr)
 
int smr_isFatal (statusMessageReporting *smr)
 
const char * smr_getMessage (statusMessageReporting *smr)
 
char * smr_getFullMessage (statusMessageReporting *smr)
 
void smr_print (statusMessageReporting *smr, FILE *f, int clear)
 

Function Documentation

◆ smr_allocateFormatMessage()

char * smr_allocateFormatMessage ( const char *  fmt,
  ... 
)

Definition at line 121 of file statusMessageReporting.cc.

121 {
122
123 char *s;
124 va_list args;
125
126 va_start( args, fmt );
127 s = smr_vallocateFormatMessage( fmt, &args );
128 va_end( args );
129 return( s );
130}
char * smr_vallocateFormatMessage(const char *fmt, va_list *args)

◆ smr_getFullMessage()

char * smr_getFullMessage ( statusMessageReporting smr)

Definition at line 247 of file statusMessageReporting.cc.

247 {
248
249 return( smr_getFullMessage2( "%s\nAt line %d of %s", smr->message, smr->line, smr->packageName ) );
250}
char packageName[smr_maximumPackageNameSize]

◆ smr_getMessage()

const char * smr_getMessage ( statusMessageReporting smr)

Definition at line 240 of file statusMessageReporting.cc.

240 {
241
242 return( smr->message );
243}

◆ smr_initialize()

int smr_initialize ( statusMessageReporting smr)

Definition at line 57 of file statusMessageReporting.cc.

57 {
58
59 smr->status = smr_status_Ok;
60 smr->packageName[0] = 0;
61 smr->line= -1;
62 smr->code = 0;
63 smr->message = NULL;
64 return( 0 );
65}
@ smr_status_Ok

Referenced by G4GIDI_map::G4GIDI_map(), G4GIDI_target::init(), and smr_release().

◆ smr_isError()

int smr_isError ( statusMessageReporting smr)

Definition at line 224 of file statusMessageReporting.cc.

224 {
225
226 if( smr == NULL ) return( 1 );
227 return( ( smr->status == smr_status_Error ) || ( smr->status == smr_status_Fatal ) );
228}
@ smr_status_Error
@ smr_status_Fatal

◆ smr_isFatal()

int smr_isFatal ( statusMessageReporting smr)

Definition at line 232 of file statusMessageReporting.cc.

232 {
233
234 if( smr == NULL ) return( 1 );
235 return( smr->status == smr_status_Fatal );
236}

◆ smr_isInfo()

int smr_isInfo ( statusMessageReporting smr)

Definition at line 216 of file statusMessageReporting.cc.

216 {
217
218 if( smr == NULL ) return( 1 );
219 return( smr->status == smr_status_Info );
220}
@ smr_status_Info

◆ smr_isOk()

◆ smr_print()

void smr_print ( statusMessageReporting smr,
FILE *  f,
int  clear 
)

Definition at line 267 of file statusMessageReporting.cc.

267 {
268
269 if( smr->message != NULL ) fprintf( f, "%s\nAt line %d of %s\n", smr->message, smr->line, smr->packageName );
270 if( clear ) smr_release( smr );
271}
int smr_release(statusMessageReporting *smr)

Referenced by G4GIDI_map::G4GIDI_map(), and G4GIDI_target::init().

◆ smr_release()

int smr_release ( statusMessageReporting smr)

Definition at line 69 of file statusMessageReporting.cc.

69 {
70
71 if( smr->message != NULL ) {
72 if( smr->message != smr_mallocFailed ) free( smr->message );
73 }
74 return( smr_initialize( smr ) );
75}
int smr_initialize(statusMessageReporting *smr)

Referenced by smr_print(), G4GIDI_map::~G4GIDI_map(), and G4GIDI_target::~G4GIDI_target().

◆ smr_setMessageError()

◆ smr_setMessageInfo()

int smr_setMessageInfo ( statusMessageReporting smr,
void *  userInterface,
const char *  file,
int  line,
int  code,
const char *  fmt,
  ... 
)

Definition at line 79 of file statusMessageReporting.cc.

79 {
80
81 int status;
82 va_list args;
83
84 va_start( args, fmt );
85 status = smr_setMessage( smr, userInterface, file, line, code, smr_status_Info, fmt, &args );
86 va_end( args );
87 return( status );
88}

Referenced by tpia_map_findTarget(), and tpia_map_toXMLString().

◆ smr_vallocateFormatMessage()

char * smr_vallocateFormatMessage ( const char *  fmt,
va_list *  args 
)

Definition at line 134 of file statusMessageReporting.cc.

134 {
135
136 int n, size = 128;
137 char *message = NULL;
138 va_list args_;
139
140 while( 1 ) {
141 if( ( message = (char *) realloc( message, size ) ) == NULL ) return( NULL );
142 //TK110426
143#if defined WIN32
144 args_ = *args;
145#elif defined __IBMCPP__
146 va_copy( args_, *args );
147#else
148 __va_copy( args_, *args );
149#endif
150 n = vsnprintf( message, size, fmt, args_ );
151 va_end( args_ );
152 if( ( n > -1 ) && ( n < size ) ) break;
153 if( n > -1 ) { /* glibc 2.1 */
154 size = n + 3; }
155 else { /* glibc 2.0 */
156 size += 128;
157 }
158 }
159 return( message );
160}

Referenced by smr_allocateFormatMessage(), and tpia_misc_setMessageError_Element().

◆ smr_vsetMessageError()

int smr_vsetMessageError ( statusMessageReporting smr,
void *  userInterface,
const char *  file,
int  line,
int  code,
const char *  fmt,
va_list *  args 
)

Definition at line 113 of file statusMessageReporting.cc.

113 {
114
115 int status = smr_setMessage( smr, userInterface, file, line, code, smr_status_Error, fmt, args );
116 return( status );
117}

Referenced by tpia_misc_setMessageError_Element().

◆ smr_vsetMessageInfo()

int smr_vsetMessageInfo ( statusMessageReporting smr,
void *  userInterface,
const char *  file,
int  line,
int  code,
const char *  fmt,
va_list *  args 
)

Definition at line 92 of file statusMessageReporting.cc.

92 {
93
94 int status = smr_setMessage( smr, userInterface, file, line, code, smr_status_Info, fmt, args );
95 return( status );
96}