1/*****************************************************************************
2
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements.  See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License.  You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied.  See the License for the specific language governing
16  permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22  sc_name_gen.cpp -- Unique name generator.
23
24  Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
25
26  CHANGE LOG AT THE END OF THE FILE
27 *****************************************************************************/
28
29
30#include "sysc/kernel/sc_kernel_ids.h"
31#include "sysc/kernel/sc_name_gen.h"
32#include "sysc/utils/sc_iostream.h"
33
34#if defined(_MSC_VER) && _MSC_VER >= 1310
35// "C4351: new behavior: elements of array will be default initialized"
36#pragma warning(disable: 4351)
37#endif
38
39namespace sc_core {
40
41// ----------------------------------------------------------------------------
42//  CLASS : sc_name_gen
43//
44//  Unique name generator class.
45// ----------------------------------------------------------------------------
46
47sc_name_gen::sc_name_gen() : m_unique_name_map(), m_unique_name()
48{}
49
50sc_name_gen::~sc_name_gen()
51{
52    sc_strhash<int*>::iterator it( m_unique_name_map );
53    for( ; ! it.empty(); it ++ ) {
54	delete it.contents();
55    }
56    m_unique_name_map.erase();
57}
58
59
60// to generate unique names for objects in an MT-Safe way
61
62const char*
63sc_name_gen::gen_unique_name( const char* basename_, bool preserve_first )
64{
65    if( basename_ == 0 ) {
66	SC_REPORT_ERROR( SC_ID_GEN_UNIQUE_NAME_, 0 );
67    }
68    int* c = m_unique_name_map[basename_];
69    if( c == 0 ) {
70	c = new int( 0 );
71	m_unique_name_map.insert( CCAST<char*>( basename_ ), c );
72	if (preserve_first) {
73	    std::sprintf( m_unique_name, "%s", basename_ );
74	} else {
75            std::sprintf( m_unique_name, "%s_%d", basename_, *c );
76        }
77    } else {
78        std::sprintf( m_unique_name, "%s_%d", basename_, ++ (*c) );
79    }
80    return m_unique_name;
81}
82
83} // namespace sc_core
84
85// $Log: sc_name_gen.cpp,v $
86// Revision 1.6  2011/08/26 20:46:10  acg
87//  Andy Goodrich: moved the modification log to the end of the file to
88//  eliminate source line number skew when check-ins are done.
89//
90// Revision 1.5  2011/08/24 22:05:51  acg
91//  Torsten Maehne: initialization changes to remove warnings.
92//
93// Revision 1.4  2011/02/18 20:27:14  acg
94//  Andy Goodrich: Updated Copyrights.
95//
96// Revision 1.3  2011/02/13 21:47:37  acg
97//  Andy Goodrich: update copyright notice.
98//
99// Revision 1.2  2008/05/22 17:06:26  acg
100//  Andy Goodrich: updated copyright notice to include 2008.
101//
102// Revision 1.1.1.1  2006/12/15 20:20:05  acg
103// SystemC 2.3
104//
105// Revision 1.3  2006/01/13 18:44:30  acg
106// Added $Log to record CVS changes into the source.
107//
108
109// Taf!
110