tpia_depot.cc

Go to the documentation of this file.
00001 /*
00002 # <<BEGIN-copyright>>
00003 # Copyright (c) 2010, Lawrence Livermore National Security, LLC. 
00004 # Produced at the Lawrence Livermore National Laboratory 
00005 # Written by Bret R. Beck, beck6@llnl.gov. 
00006 # CODE-461393
00007 # All rights reserved. 
00008 #  
00009 # This file is part of GIDI. For details, see nuclear.llnl.gov. 
00010 # Please also read the "Additional BSD Notice" at nuclear.llnl.gov. 
00011 # 
00012 # Redistribution and use in source and binary forms, with or without modification, 
00013 # are permitted provided that the following conditions are met: 
00014 #
00015 #      1) Redistributions of source code must retain the above copyright notice, 
00016 #         this list of conditions and the disclaimer below.
00017 #      2) Redistributions in binary form must reproduce the above copyright notice, 
00018 #         this list of conditions and the disclaimer (as noted below) in the 
00019 #          documentation and/or other materials provided with the distribution.
00020 #      3) Neither the name of the LLNS/LLNL nor the names of its contributors may be 
00021 #         used to endorse or promote products derived from this software without 
00022 #         specific prior written permission. 
00023 #
00024 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
00025 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00026 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT 
00027 # SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR 
00028 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00029 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
00030 # OR SERVICES;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
00031 # AND ON  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00032 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
00033 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00034 # <<END-copyright>>
00035 */
00036 #include <string.h>
00037 #include <tpia_depot.h>
00038 
00039 #if defined __cplusplus
00040 namespace GIDI{
00041 using namespace GIDI;
00042 #endif
00043 
00044 /*
00045 ************************************************************
00046 */
00047 tpia_depot *tpia_depot_create( statusMessageReporting *smr, const char *projectileName ) {
00048 
00049     tpia_depot *depot;
00050 
00051     //if( ( depot = xData_malloc2( smr, sizeof( tpia_depot ), 0, "map" ) ) == NULL ) return( NULL );
00052     if( ( depot = (tpia_depot*) xData_malloc2( smr, sizeof( tpia_depot ), 0, "map" ) ) == NULL ) return( NULL );
00053     if( tpia_depot_initialize( smr, depot, projectileName ) ) depot = tpia_depot_free( depot, 0 );
00054     return( depot );
00055 }
00056 /*
00057 ************************************************************
00058 */
00059 int tpia_depot_initialize( statusMessageReporting *smr, tpia_depot *depot, const char *projectileName ) {
00060 
00061     memset( depot, 0, sizeof( tpia_depot ) );
00062     depot->status = 0;
00063     depot->projectileName = NULL;
00064     depot->numberOfTargets = 0;
00065     depot->targets = NULL;
00066     depot->map = NULL;
00067     //if( ( depot->projectileName = xData_malloc2( smr, strlen( projectileName ) + 1, 0, "projectile" ) ) == NULL ) return( 1 );
00068     if( ( depot->projectileName = (char*) xData_malloc2( smr, strlen( projectileName ) + 1, 0, "projectile" ) ) == NULL ) return( 1 );
00069     return( 0 );
00070 }
00071 /*
00072 ************************************************************
00073 */
00074 tpia_depot *tpia_depot_free( tpia_depot *depot, int freeMap ) {
00075 
00076     tpia_depot_release( depot, freeMap );
00077     xData_free( NULL, depot );
00078     return( NULL );
00079 }
00080 /*
00081 ************************************************************
00082 */
00083 int tpia_depot_release( tpia_depot *depot, int freeMap ) {
00084 
00085     tpia_targetEntry *next, *targetEntry;
00086 
00087     if( depot->projectileName != NULL ) xData_free( NULL, depot->projectileName );
00088     for( targetEntry = depot->targets; targetEntry != NULL; targetEntry = next ) {
00089         next = targetEntry->next;
00090         tpia_target_free( NULL, targetEntry->target );
00091         xData_free( NULL, targetEntry );
00092     }
00093     depot->numberOfTargets = 0;
00094     depot->targets = NULL;
00095     //if( freeMap && ( depot->map != NULL ) ) depot->map = tpia_map_free( NULL, depot->map );
00096     if( freeMap && ( depot->map != NULL ) ) depot->map = (tpia_map*) tpia_map_free( NULL, depot->map );
00097     return( depot->status = 0 );
00098 }
00099 /*
00100 ************************************************************
00101 */
00102 //int tpia_depot_setMap( statusMessageReporting *smr, tpia_depot *depot, tpia_map *map ) {
00103 int tpia_depot_setMap( statusMessageReporting *, tpia_depot *depot, tpia_map *map ) {
00104 
00105     depot->map = map;
00106     return( 0 );
00107 }
00108 /*
00109 ************************************************************
00110 */
00111 int tpia_depot_setMapFromFilename( statusMessageReporting *smr, tpia_depot *depot, const char *basePath, const char *mapFileName ) {
00112 
00113     if( ( depot->map = tpia_map_readFile( smr, basePath, mapFileName ) ) == NULL ) return( 1 );
00114     return( 0 );
00115 }
00116 /*
00117 ************************************************************
00118 */
00119 tpia_map *tpia_depot_releaseMap( tpia_depot *depot ) {
00120 
00121     tpia_map *map = depot->map;
00122 
00123     depot->map = NULL;
00124     return( map );
00125 }
00126 /*
00127 ************************************************************
00128 */
00129 int tpia_depot_freeMap( tpia_depot *depot ) {
00130 
00131     tpia_map *map = tpia_depot_releaseMap( depot );
00132 
00133     if( map != NULL ) tpia_map_free( NULL, map );
00134     return( 0 );
00135 }
00136 /*
00137 ************************************************************
00138 */
00139 tpia_targetEntry *tpia_depot_getFirstTargetEntry( tpia_depot *depot ) {
00140 
00141     return( depot->targets );
00142 }
00143 /*
00144 ************************************************************
00145 */
00146 tpia_targetEntry *tpia_depot_getNextTargetEntry( tpia_targetEntry *targetEntry ) {
00147 
00148     return( targetEntry->next );
00149 }
00150 /*
00151 ************************************************************
00152 */
00153 tpia_target *tpia_depot_addTarget( statusMessageReporting *smr, tpia_depot *depot, const char *evaluation, const char *targetName ) {
00154 
00155     return( tpia_depot_addTargetFromMap( smr, depot, depot->map, evaluation, targetName ) );
00156 }
00157 /*
00158 ************************************************************
00159 */
00160 tpia_target *tpia_depot_addTargetFromMap( statusMessageReporting *smr, tpia_depot *depot, tpia_map *map, const char *evaluation, const char *targetName ) {
00161 
00162     tpia_targetEntry *targetEntry;
00163     tpia_target *target;
00164 
00165     for( targetEntry = tpia_depot_getFirstTargetEntry( depot ); targetEntry != NULL; targetEntry = tpia_depot_getNextTargetEntry( targetEntry ) ) {
00166         if( !strcmp( targetEntry->target->targetID->name, targetName ) ) {
00167             smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "depot already contains target = %s ", targetName );
00168             return( NULL );
00169         }
00170     }
00171     target = tpia_target_createReadFromMap( smr, map, evaluation, depot->projectileName, targetName );
00172     return( target );
00173 }
00174 
00175 #if defined __cplusplus
00176 }
00177 #endif

Generated on Mon May 27 17:50:35 2013 for Geant4 by  doxygen 1.4.7