Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tpia_depot.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 <string.h>
37 #include <tpia_depot.h>
38 
39 #if defined __cplusplus
40 namespace GIDI{
41 using namespace GIDI;
42 #endif
43 
44 /*
45 ************************************************************
46 */
47 tpia_depot *tpia_depot_create( statusMessageReporting *smr, const char *projectileName ) {
48 
49  tpia_depot *depot;
50 
51  //if( ( depot = xData_malloc2( smr, sizeof( tpia_depot ), 0, "map" ) ) == NULL ) return( NULL );
52  if( ( depot = (tpia_depot*) xData_malloc2( smr, sizeof( tpia_depot ), 0, "map" ) ) == NULL ) return( NULL );
53  if( tpia_depot_initialize( smr, depot, projectileName ) ) depot = tpia_depot_free( depot, 0 );
54  return( depot );
55 }
56 /*
57 ************************************************************
58 */
59 int tpia_depot_initialize( statusMessageReporting *smr, tpia_depot *depot, const char *projectileName ) {
60 
61  memset( depot, 0, sizeof( tpia_depot ) );
62  depot->status = 0;
63  depot->projectileName = NULL;
64  depot->numberOfTargets = 0;
65  depot->targets = NULL;
66  depot->map = NULL;
67  //if( ( depot->projectileName = xData_malloc2( smr, strlen( projectileName ) + 1, 0, "projectile" ) ) == NULL ) return( 1 );
68  if( ( depot->projectileName = (char*) xData_malloc2( smr, strlen( projectileName ) + 1, 0, "projectile" ) ) == NULL ) return( 1 );
69  return( 0 );
70 }
71 /*
72 ************************************************************
73 */
74 tpia_depot *tpia_depot_free( tpia_depot *depot, int freeMap ) {
75 
76  tpia_depot_release( depot, freeMap );
77  xData_free( NULL, depot );
78  return( NULL );
79 }
80 /*
81 ************************************************************
82 */
83 int tpia_depot_release( tpia_depot *depot, int freeMap ) {
84 
85  tpia_targetEntry *next, *targetEntry;
86 
87  if( depot->projectileName != NULL ) xData_free( NULL, depot->projectileName );
88  for( targetEntry = depot->targets; targetEntry != NULL; targetEntry = next ) {
89  next = targetEntry->next;
90  tpia_target_free( NULL, targetEntry->target );
91  xData_free( NULL, targetEntry );
92  }
93  depot->numberOfTargets = 0;
94  depot->targets = NULL;
95  //if( freeMap && ( depot->map != NULL ) ) depot->map = tpia_map_free( NULL, depot->map );
96  if( freeMap && ( depot->map != NULL ) ) depot->map = (tpia_map*) tpia_map_free( NULL, depot->map );
97  return( depot->status = 0 );
98 }
99 /*
100 ************************************************************
101 */
102 //int tpia_depot_setMap( statusMessageReporting *smr, tpia_depot *depot, tpia_map *map ) {
104 
105  depot->map = map;
106  return( 0 );
107 }
108 /*
109 ************************************************************
110 */
111 int tpia_depot_setMapFromFilename( statusMessageReporting *smr, tpia_depot *depot, const char *basePath, const char *mapFileName ) {
112 
113  if( ( depot->map = tpia_map_readFile( smr, basePath, mapFileName ) ) == NULL ) return( 1 );
114  return( 0 );
115 }
116 /*
117 ************************************************************
118 */
120 
121  tpia_map *map = depot->map;
122 
123  depot->map = NULL;
124  return( map );
125 }
126 /*
127 ************************************************************
128 */
130 
131  tpia_map *map = tpia_depot_releaseMap( depot );
132 
133  if( map != NULL ) tpia_map_free( NULL, map );
134  return( 0 );
135 }
136 /*
137 ************************************************************
138 */
140 
141  return( depot->targets );
142 }
143 /*
144 ************************************************************
145 */
147 
148  return( targetEntry->next );
149 }
150 /*
151 ************************************************************
152 */
153 tpia_target *tpia_depot_addTarget( statusMessageReporting *smr, tpia_depot *depot, const char *evaluation, const char *targetName ) {
154 
155  return( tpia_depot_addTargetFromMap( smr, depot, depot->map, evaluation, targetName ) );
156 }
157 /*
158 ************************************************************
159 */
160 tpia_target *tpia_depot_addTargetFromMap( statusMessageReporting *smr, tpia_depot *depot, tpia_map *map, const char *evaluation, const char *targetName ) {
161 
162  tpia_targetEntry *targetEntry;
164 
165  for( targetEntry = tpia_depot_getFirstTargetEntry( depot ); targetEntry != NULL; targetEntry = tpia_depot_getNextTargetEntry( targetEntry ) ) {
166  if( !strcmp( targetEntry->target->targetID->name, targetName ) ) {
167  smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "depot already contains target = %s ", targetName );
168  return( NULL );
169  }
170  }
171  target = tpia_target_createReadFromMap( smr, map, evaluation, depot->projectileName, targetName );
172  return( target );
173 }
174 
175 #if defined __cplusplus
176 }
177 #endif
tpia_target * tpia_target_free(statusMessageReporting *smr, tpia_target *target)
Definition: tpia_target.cc:108
tpia_map * tpia_map_readFile(statusMessageReporting *smr, const char *basePath, const char *mapFileName)
Definition: tpia_map.cc:88
int smr_setMessageError(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
int tpia_depot_release(tpia_depot *depot, int freeMap)
Definition: tpia_depot.cc:83
#define xData_malloc2(smr, size, zero, forItem)
Definition: xData.h:313
const XML_Char * target
void * xData_free(statusMessageReporting *smr, void *p)
Definition: xDataMisc.cc:89
Definition: tpia_depot.h:53
tpia_targetEntry * tpia_depot_getNextTargetEntry(tpia_targetEntry *targetEntry)
Definition: tpia_depot.cc:146
tpia_target * tpia_depot_addTargetFromMap(statusMessageReporting *smr, tpia_depot *depot, tpia_map *map, const char *evaluation, const char *targetName)
Definition: tpia_depot.cc:160
int numberOfTargets
Definition: tpia_depot.h:61
tpia_targetEntry * targets
Definition: tpia_depot.h:62
tpia_target * target
Definition: tpia_depot.h:55
int tpia_depot_setMap(statusMessageReporting *, tpia_depot *depot, tpia_map *map)
Definition: tpia_depot.cc:103
tpia_depot * tpia_depot_create(statusMessageReporting *smr, const char *projectileName)
Definition: tpia_depot.cc:47
tpia_map * map
Definition: tpia_depot.h:63
tpia_targetEntry * tpia_depot_getFirstTargetEntry(tpia_depot *depot)
Definition: tpia_depot.cc:139
int tpia_depot_setMapFromFilename(statusMessageReporting *smr, tpia_depot *depot, const char *basePath, const char *mapFileName)
Definition: tpia_depot.cc:111
void * tpia_map_free(statusMessageReporting *smr, tpia_map *map)
Definition: tpia_map.cc:184
tpia_map * tpia_depot_releaseMap(tpia_depot *depot)
Definition: tpia_depot.cc:119
tpia_target * tpia_depot_addTarget(statusMessageReporting *smr, tpia_depot *depot, const char *evaluation, const char *targetName)
Definition: tpia_depot.cc:153
tpia_depot * tpia_depot_free(tpia_depot *depot, int freeMap)
Definition: tpia_depot.cc:74
tpia_particle * targetID
Definition: tpia_target.h:298
int tpia_depot_freeMap(tpia_depot *depot)
Definition: tpia_depot.cc:129
int tpia_depot_initialize(statusMessageReporting *smr, tpia_depot *depot, const char *projectileName)
Definition: tpia_depot.cc:59
tpia_target * tpia_target_createReadFromMap(statusMessageReporting *smr, tpia_map *map, const char *evaluation, const char *projectileName, const char *targetName)
Definition: tpia_target.cc:93
tpia_targetEntry * next
Definition: tpia_depot.h:54
char * projectileName
Definition: tpia_depot.h:60