sc_name_gen.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2006 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.4 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_name_gen.cpp -- Unique name generator.
00021 
00022   Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
00023 
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027 
00028   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00029   changes you are making here.
00030 
00031       Name, Affiliation, Date:
00032   Description of Modification:
00033 
00034  *****************************************************************************/
00035 
00036 
00037 // $Log: sc_name_gen.cpp,v $
00038 // Revision 1.1.1.1  2006/12/15 20:31:37  acg
00039 // SystemC 2.2
00040 //
00041 // Revision 1.3  2006/01/13 18:44:30  acg
00042 // Added $Log to record CVS changes into the source.
00043 //
00044 
00045 #include "sysc/kernel/sc_kernel_ids.h"
00046 #include "sysc/kernel/sc_name_gen.h"
00047 #include "sysc/utils/sc_iostream.h"
00048 
00049 namespace sc_core {
00050 
00051 // ----------------------------------------------------------------------------
00052 //  CLASS : sc_name_gen
00053 //
00054 //  Unique name generator class.
00055 // ----------------------------------------------------------------------------
00056 
00057 sc_name_gen::sc_name_gen()
00058 {}
00059 
00060 sc_name_gen::~sc_name_gen()
00061 {
00062     sc_strhash<int*>::iterator it( m_unique_name_map );
00063     for( ; ! it.empty(); it ++ ) {
00064     delete it.contents();
00065     }
00066     m_unique_name_map.erase();
00067 }
00068 
00069 
00070 // to generate unique names for objects in an MT-Safe way
00071 
00072 const char*
00073 sc_name_gen::gen_unique_name( const char* basename_, bool preserve_first )
00074 {
00075     if( basename_ == 0 ) {
00076     SC_REPORT_ERROR( SC_ID_GEN_UNIQUE_NAME_, 0 );
00077     }
00078     int* c = m_unique_name_map[basename_];
00079     if( c == 0 ) {
00080     c = new int( 0 );
00081     m_unique_name_map.insert( CCAST<char*>( basename_ ), c );
00082     if (preserve_first) {
00083         std::sprintf( m_unique_name, "%s", basename_ );
00084     } else {    
00085             std::sprintf( m_unique_name, "%s_%d", basename_, *c );
00086         }
00087     } else {
00088         std::sprintf( m_unique_name, "%s_%d", basename_, ++ (*c) );
00089     }
00090     return m_unique_name;
00091 }
00092 
00093 } // namespace sc_core
00094 
00095 // Taf!

Generated on Wed Jan 21 15:32:09 2009 for SystemC by  doxygen 1.5.5