Geant4
9.6.p02
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
geant4_9_6_p02
source
processes
hadronic
models
lend
src
gString.cc
Go to the documentation of this file.
1
/*
2
# <<BEGIN-copyright>>
3
# Copyright (c) 2010, Lawrence Livermore National Security, LLC.
4
# Produced at the Lawrence Livermore National Laboratory
5
# Written by Bret R. Beck, beck6@llnl.gov.
6
# CODE-461393
7
# All rights reserved.
8
#
9
# This file is part of GIDI. For details, see nuclear.llnl.gov.
10
# Please also read the "Additional BSD Notice" at nuclear.llnl.gov.
11
#
12
# Redistribution and use in source and binary forms, with or without modification,
13
# are permitted provided that the following conditions are met:
14
#
15
# 1) Redistributions of source code must retain the above copyright notice,
16
# this list of conditions and the disclaimer below.
17
# 2) Redistributions in binary form must reproduce the above copyright notice,
18
# this list of conditions and the disclaimer (as noted below) in the
19
# documentation and/or other materials provided with the distribution.
20
# 3) Neither the name of the LLNS/LLNL nor the names of its contributors may be
21
# used to endorse or promote products derived from this software without
22
# specific prior written permission.
23
#
24
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
25
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27
# SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR
28
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
31
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
# <<END-copyright>>
35
*/
36
#include "
gString.h
"
37
#include <
xData.h
>
38
#include <string.h>
39
40
#if defined __cplusplus
41
namespace
GIDI {
42
using namespace
GIDI;
43
#endif
44
45
/*
46
***************************************************
47
*/
48
int
gString_initialize
(
statusMessageReporting
*smr,
gString
*gStr,
int
size,
int
increment ) {
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
}
66
/*
67
***************************************************
68
*/
69
int
gString_release
(
statusMessageReporting
*smr,
gString
*gStr ) {
70
71
if
( gStr->
gStr
!= NULL ) free( gStr->
gStr
);
72
gString_initialize
( smr, gStr, 0, gStr->
increment
);
73
return
( 0 );
74
}
75
/*
76
***************************************************
77
*/
78
//int gString_clear( statusMessageReporting *smr, gString *gStr ) {
79
int
gString_clear
(
statusMessageReporting
*,
gString
*gStr ) {
80
81
if
( gStr->
gStr
!= NULL ) {
82
gStr->
length
= 1;
83
gStr->
gStr
[0] = 0;
84
}
85
return
( 0 );
86
}
87
/*
88
***************************************************
89
*/
90
int
gString_addTo
(
statusMessageReporting
*smr,
gString
*gStr,
char
const
*str ) {
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
}
107
/*
108
***************************************************
109
*/
110
//char const *gString_string( statusMessageReporting *smr, gString *gStr ) {
111
char
const
*
gString_string
(
statusMessageReporting
*,
gString
*gStr ) {
112
113
return
( gStr->
gStr
);
114
}
115
/*
116
***************************************************
117
*/
118
//int gString_length( statusMessageReporting *smr, gString *gStr ) {
119
int
gString_length
(
statusMessageReporting
*,
gString
*gStr ) {
120
121
return
( gStr->
length
);
122
}
123
/*
124
***************************************************
125
*/
126
//int gString_allocated( statusMessageReporting *smr, gString *gStr ) {
127
int
gString_allocated
(
statusMessageReporting
*,
gString
*gStr ) {
128
129
return
( gStr->
allocated
);
130
}
131
/*
132
***************************************************
133
*/
134
//int gString_increment( statusMessageReporting *smr, gString *gStr ) {
135
int
gString_increment
(
statusMessageReporting
*,
gString
*gStr ) {
136
137
return
( gStr->
increment
);
138
}
139
140
#if defined __cplusplus
141
}
142
#endif
Generated on Sat May 25 2013 14:34:00 for Geant4 by
1.8.4