SystemC
3.0.0
Accellera SystemC proof-of-concept library
sysc
datatypes
fx
scfx_string.h
Go to the documentation of this file.
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
scfx_string.h -
23
24
Original Author: Robert Graulich, Synopsys, Inc.
25
Martin Janssen, Synopsys, Inc.
26
27
*****************************************************************************/
28
29
/*****************************************************************************
30
31
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
32
changes you are making here.
33
34
Name, Affiliation, Date:
35
Description of Modification:
36
37
*****************************************************************************/
38
// $Log: scfx_string.h,v $
39
// Revision 1.1.1.1 2006/12/15 20:20:04 acg
40
// SystemC 2.3
41
//
42
// Revision 1.2 2006/01/03 23:18:34 acg
43
// Changed copyright to include 2006.
44
//
45
// Revision 1.1.1.1 2005/12/19 23:16:43 acg
46
// First check in of SystemC 2.1 into its own archive.
47
//
48
// Revision 1.9 2005/09/15 23:02:03 acg
49
// Added std:: prefix to appropriate methods and types to get around
50
// issues with the Edison Front End.
51
//
52
// Revision 1.8 2005/06/07 17:27:02 acg
53
// Fixed bug in scfx_string::operator += where an array reference was used
54
// rather than the [] operator. This meant that the buffer may have been
55
// accessed beyond its allocated storage.
56
//
57
58
#ifndef SCFX_STRING_H
59
#define SCFX_STRING_H
60
61
#include <cstdio>
62
63
64
namespace
sc_dt
65
{
66
67
// classes defined in this module
68
class
scfx_string;
69
70
71
// ----------------------------------------------------------------------------
72
// CLASS : scfx_string
73
//
74
// Simple string class for internal use.
75
// ----------------------------------------------------------------------------
76
77
class
SC_API
scfx_string
78
{
79
void
resize( std::size_t );
80
81
public
:
82
83
scfx_string
();
84
85
~scfx_string
();
86
87
int
length()
const
;
88
89
void
clear();
90
91
char
& operator [] (
int
);
92
93
void
append(
int
);
94
void
discard(
int
);
95
void
remove(
int
);
96
97
void
operator += (
char
);
98
void
operator += (
const
char
* );
99
100
operator
const
char
* ();
101
102
private
:
103
104
std::size_t m_len;
105
std::size_t m_alloc;
106
char
* m_buffer;
107
};
108
109
110
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
111
112
inline
113
void
114
scfx_string::resize( std::size_t i )
115
{
116
do
{
117
m_alloc *= 2;
118
}
while
( i >= m_alloc );
119
120
char
* temp =
new
char
[m_alloc];
121
122
for
(
int
j = 0; j < (int) m_len; ++ j ) {
123
temp[j] = m_buffer[j];
124
}
125
temp[m_len] = 0;
126
127
delete
[] m_buffer;
128
m_buffer = temp;
129
}
130
131
132
inline
133
scfx_string::scfx_string
()
134
: m_len( 0 ), m_alloc( BUFSIZ ), m_buffer( new char[m_alloc] )
135
{
136
m_buffer[m_len] = 0;
137
}
138
139
140
inline
141
scfx_string::~scfx_string
()
142
{
143
delete
[] m_buffer;
144
}
145
146
147
inline
148
int
149
scfx_string::length
()
const
150
{
151
return
m_len;
152
}
153
154
155
inline
156
void
157
scfx_string::clear
()
158
{
159
m_len = 0;
160
m_buffer[m_len] = 0;
161
}
162
163
164
inline
165
char
&
166
scfx_string::operator []
(
int
i )
167
{
168
if
( i >= (
int
) m_alloc ) {
169
resize( i );
170
}
171
return
m_buffer[i];
172
}
173
174
175
inline
176
void
177
scfx_string::append
(
int
n )
178
{
179
m_len += n;
180
m_buffer[m_len] = 0;
181
}
182
183
inline
184
void
185
scfx_string::discard
(
int
n )
186
{
187
m_len -= n;
188
m_buffer[m_len] = 0;
189
}
190
191
inline
192
void
193
scfx_string::remove
(
int
i )
194
{
195
for
(
int
j = i + 1; j < (int) m_len; ++ j )
196
m_buffer[j - 1] = m_buffer[j];
197
-- m_len;
198
m_buffer[m_len] = 0;
199
}
200
201
202
inline
203
void
204
scfx_string::operator +=
(
char
c )
205
{
206
this->
operator []
( m_len ) = c;
207
m_len ++;
208
this->
operator []
( m_len ) = 0;
209
}
210
211
inline
212
void
213
scfx_string::operator +=
(
const
char
* s )
214
{
215
while
( *s )
216
(*this) += *s ++;
217
}
218
219
220
inline
221
scfx_string::operator
const
char
*()
222
{
223
m_buffer[m_len] = 0;
224
return
m_buffer;
225
}
226
227
}
// namespace sc_dt
228
229
230
#endif
231
232
// Taf!
SC_API
#define SC_API
Definition:
sc_cmnhdr.h:148
sc_dt
Definition:
sc_signal_ifs.h:38
sc_dt::scfx_string
Definition:
scfx_string.h:78
sc_dt::scfx_string::clear
void clear()
Definition:
scfx_string.h:157
sc_dt::scfx_string::scfx_string
scfx_string()
Definition:
scfx_string.h:133
sc_dt::scfx_string::operator[]
char & operator[](int)
Definition:
scfx_string.h:166
sc_dt::scfx_string::operator+=
void operator+=(char)
Definition:
scfx_string.h:204
sc_dt::scfx_string::append
void append(int)
Definition:
scfx_string.h:177
sc_dt::scfx_string::discard
void discard(int)
Definition:
scfx_string.h:185
sc_dt::scfx_string::length
int length() const
Definition:
scfx_string.h:149
sc_dt::scfx_string::remove
void remove(int)
Definition:
scfx_string.h:193
sc_dt::scfx_string::~scfx_string
~scfx_string()
Definition:
scfx_string.h:141
Generated on Fri Aug 16 2024 16:36:33 for SystemC by
1.9.4