Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
gString.h File Reference

Go to the source code of this file.

Classes

struct  gString_s
 

Macros

#define gString_minIncrement   sizeof( char * )
 

Typedefs

typedef struct gString_s gString
 

Functions

int gString_initialize (statusMessageReporting *smr, gString *gStr, int size, int increment)
 
int gString_release (statusMessageReporting *smr, gString *gStr)
 
int gString_clear (statusMessageReporting *smr, gString *gStr)
 
int gString_addTo (statusMessageReporting *smr, gString *gStr, char const *str)
 
char constgString_string (statusMessageReporting *smr, gString *gStr)
 
int gString_length (statusMessageReporting *smr, gString *gStr)
 
int gString_allocated (statusMessageReporting *smr, gString *gStr)
 
int gString_increment (statusMessageReporting *smr, gString *gStr)
 

Macro Definition Documentation

◆ gString_minIncrement

#define gString_minIncrement   sizeof( char * )

Definition at line 49 of file gString.h.

Typedef Documentation

◆ gString

typedef struct gString_s gString

Definition at line 50 of file gString.h.

Function Documentation

◆ gString_addTo()

int gString_addTo ( statusMessageReporting smr,
gString gStr,
char const str 
)

Definition at line 90 of file gString.cc.

90 {
91
92 int n, size = strlen( str );
93
94 if( gStr->gStr == NULL ) {
95 if( gString_initialize( smr, gStr, size + 1, gStr->increment ) != 0 ) return( 1 ); }
96 else if( ( gStr->length + size ) > gStr->allocated ) {
97 n = gStr->increment;
98 if( n < size ) n = size;
99 //if( ( gStr->gStr = xData_realloc2( smr, gStr->gStr, gStr->allocated + n, "gStr->gStr" ) ) == NULL ) return( 1 );
100 if( ( gStr->gStr = (char*) xData_realloc2( smr, gStr->gStr, gStr->allocated + n, "gStr->gStr" ) ) == NULL ) return( 1 );
101 gStr->allocated += n;
102 }
103 strcpy( &(gStr->gStr[gStr->length - 1]), str );
104 gStr->length = gStr->length + size;
105 return( 0 );
106}
int gString_initialize(statusMessageReporting *smr, gString *gStr, int size, int increment)
Definition: gString.cc:48
int length
Definition: gString.h:53
int increment
Definition: gString.h:53
int allocated
Definition: gString.h:53
char * gStr
Definition: gString.h:54
#define xData_realloc2(smr, old, size, forItem)
Definition: xData.h:314

Referenced by tpi_channelID_toStringSans(), and tpi_spectralID_toStringSans().

◆ gString_allocated()

int gString_allocated ( statusMessageReporting smr,
gString gStr 
)

Definition at line 127 of file gString.cc.

127 {
128
129 return( gStr->allocated );
130}

◆ gString_clear()

int gString_clear ( statusMessageReporting smr,
gString gStr 
)

Definition at line 79 of file gString.cc.

79 {
80
81 if( gStr->gStr != NULL ) {
82 gStr->length = 1;
83 gStr->gStr[0] = 0;
84 }
85 return( 0 );
86}

◆ gString_increment()

int gString_increment ( statusMessageReporting smr,
gString gStr 
)

Definition at line 135 of file gString.cc.

135 {
136
137 return( gStr->increment );
138}

◆ gString_initialize()

int gString_initialize ( statusMessageReporting smr,
gString gStr,
int  size,
int  increment 
)

Definition at line 48 of file gString.cc.

48 {
49
50 if( size > 0 ) {
51 //if( ( gStr->gStr = xData_malloc2( smr, size + 1, 0, "gStr->gStr" ) ) == NULL ) return( 1 );
52 if( ( gStr->gStr = (char*) xData_malloc2( smr, size + 1, 0, "gStr->gStr" ) ) == NULL ) return( 1 );
53 gStr->length = 1;
54 gStr->gStr[0] = 0; }
55 else {
56 size = 0;
57 gStr->length = 0;
58 gStr->gStr = NULL;
59 }
60 gStr->allocated = size;
61 //if( increment < gString_minIncrement ) increment = gString_minIncrement;
62 if( increment < (int) gString_minIncrement ) increment = gString_minIncrement;
63 gStr->increment = increment;
64 return( 0 );
65}
#define gString_minIncrement
Definition: gString.h:49
#define xData_malloc2(smr, size, zero, forItem)
Definition: xData.h:313

Referenced by gString_addTo(), and gString_release().

◆ gString_length()

int gString_length ( statusMessageReporting smr,
gString gStr 
)

Definition at line 119 of file gString.cc.

119 {
120
121 return( gStr->length );
122}

◆ gString_release()

int gString_release ( statusMessageReporting smr,
gString gStr 
)

Definition at line 69 of file gString.cc.

69 {
70
71 if( gStr->gStr != NULL ) free( gStr->gStr );
72 gString_initialize( smr, gStr, 0, gStr->increment );
73 return( 0 );
74}

◆ gString_string()

char const * gString_string ( statusMessageReporting smr,
gString gStr 
)

Definition at line 111 of file gString.cc.

111 {
112
113 return( gStr->gStr );
114}