00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef SC_STRING_H
00038 #define SC_STRING_H
00039
00040
00041 #include "sysc/utils/sc_iostream.h"
00042 #include "sysc/utils/sc_report.h"
00043
00044 namespace sc_dt {
00045 class sc_string_old;
00046 }
00047
00048 #ifdef SC_USE_SC_STRING_OLD
00049 typedef sc_dt::sc_string_old sc_string;
00050 #endif
00051 #ifdef SC_USE_STD_STRING
00052 typedef ::std::string sc_string;
00053 #endif
00054
00055 namespace sc_dt {
00056
00057
00058 class sc_string_rep;
00059
00060
00061
00062
00063
00064
00065
00066 enum sc_numrep
00067 {
00068 SC_NOBASE = 0,
00069 SC_BIN = 2,
00070 SC_OCT = 8,
00071 SC_DEC = 10,
00072 SC_HEX = 16,
00073 SC_BIN_US,
00074 SC_BIN_SM,
00075 SC_OCT_US,
00076 SC_OCT_SM,
00077 SC_HEX_US,
00078 SC_HEX_SM,
00079 SC_CSD
00080 };
00081
00082
00083
00084
00085 typedef ::std::istream systemc_istream;
00086 typedef ::std::ostream systemc_ostream;
00087
00088 const std::string to_string( sc_numrep );
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 #if defined(__GNUC__) // GNU C++ compiler.
00104 inline sc_numrep sc_io_base( systemc_ostream& stream_object,
00105 sc_numrep def_base )
00106 {
00107 ::std::ios::fmtflags flags =
00108 stream_object.flags() & ::std::ios::basefield;
00109 if ( flags & ::std::ios::dec ) return SC_DEC;
00110 if ( flags & ::std::ios::hex ) return SC_HEX;
00111 if ( flags & ::std::ios::oct ) return SC_OCT;
00112 return def_base;
00113 }
00114 inline bool sc_io_show_base( systemc_ostream& stream_object )
00115 {
00116 return stream_object.flags() & ::std::ios::showbase;
00117 }
00118 #else // Other
00119 inline sc_numrep sc_io_base( systemc_ostream& stream_object,
00120 sc_numrep def_base )
00121 {
00122 return SC_DEC;
00123 }
00124 inline bool sc_io_show_base( systemc_ostream& stream_object )
00125 {
00126 return false;
00127 }
00128 #endif
00129
00130
00131
00132
00133
00134
00135
00136
00137 class sc_string_old
00138 {
00139 friend systemc_ostream& operator << (systemc_ostream& os, const sc_string_old& a);
00140 friend systemc_istream& operator >> ( systemc_istream& is, sc_string_old& a );
00141
00142 public:
00143
00144
00145
00146 explicit sc_string_old( int size = 16 );
00147 sc_string_old( const char* s );
00148 sc_string_old( const char* s, int n );
00149 sc_string_old( const sc_string_old& s );
00150
00151
00152
00153
00154 ~sc_string_old();
00155
00156
00157
00158
00159 sc_string_old& operator = ( const char* s );
00160 sc_string_old& operator = ( const sc_string_old& s );
00161
00162 sc_string_old& operator += ( const char* s );
00163 sc_string_old& operator += ( char c );
00164 sc_string_old& operator += ( const sc_string_old& s );
00165
00166 sc_string_old operator + ( const char* s ) const;
00167 sc_string_old operator + ( char c ) const;
00168 sc_string_old operator + ( const sc_string_old& s ) const;
00169
00170 friend sc_string_old operator + ( const char* s, const sc_string_old& t );
00171
00172
00173
00174
00175 sc_string_old substr( int first, int last ) const;
00176
00177
00178
00179
00180 bool operator == ( const char* s ) const;
00181 bool operator != ( const char* s ) const;
00182 bool operator < ( const char* s ) const;
00183 bool operator <= ( const char* s ) const;
00184 bool operator > ( const char* s ) const;
00185 bool operator >= ( const char* s ) const;
00186 bool operator == ( const sc_string_old& s ) const;
00187 bool operator != ( const sc_string_old& s ) const;
00188 bool operator < ( const sc_string_old& s ) const;
00189 bool operator <= ( const sc_string_old& s ) const;
00190 bool operator > ( const sc_string_old& s ) const;
00191 bool operator >= ( const sc_string_old& s ) const;
00192
00193
00194
00195
00196 int length() const;
00197
00198
00199
00200
00201 const char* c_str() const;
00202
00203
00204
00205 operator const char*() const;
00206
00207
00208
00209 char operator[](int index) const;
00210
00211
00212
00213 char& operator[](int index);
00214
00215
00216 static sc_string_old to_string(const char* format, ...);
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 template<class T> sc_string_old& fmt(const T& t)
00228 {
00229
00230 int index;
00231 int last_char = length()-1;
00232 sc_string_old temp(*this);
00233 do
00234 {
00235 index = temp.pos("%");
00236 if(index == last_char)
00237 return *this;
00238 temp = substr(index,last_char);
00239 } while(temp[0] != '%');
00240 int f_len = (int)temp.fmt_length();
00241 temp = to_string(substr(0,index+f_len-1).c_str(),t);
00242 return (*this) = temp + substr(index+f_len,last_char);
00243 }
00244 sc_string_old& fmt(const sc_string_old& s);
00245
00246
00247
00248
00249 int pos(const sc_string_old& sub_string)const;
00250
00251
00252
00253 sc_string_old& remove(unsigned index, unsigned length);
00254
00255
00256
00257 sc_string_old& insert(const sc_string_old& sub_string, unsigned index);
00258
00259
00260
00261
00262 bool is_delimiter(const sc_string_old& str, unsigned index)const;
00263
00264
00265
00266 bool contains(char c)const;
00267
00268
00269
00270 sc_string_old uppercase()const;
00271
00272
00273
00274 sc_string_old lowercase()const;
00275
00276
00277
00278 static sc_string_old make_str(long n);
00279 void set( int index, char c );
00280 int cmp( const char* s ) const;
00281 int cmp( const sc_string_old& s ) const;
00282
00283
00284 void print( systemc_ostream& os = ::std::cout ) const;
00285
00286 private:
00287
00288 sc_string_old( sc_string_rep* r );
00289
00290 sc_string_rep* rep;
00291
00292 void test(int position)const;
00293 unsigned fmt_length()const;
00294 };
00295
00296
00297
00298
00299 inline
00300 systemc_ostream&
00301 operator << ( systemc_ostream& os, sc_numrep numrep )
00302 {
00303 os << to_string( numrep );
00304 return os;
00305 }
00306
00307
00308 inline
00309 systemc_ostream&
00310 operator << ( systemc_ostream& os, const sc_string_old& a )
00311 {
00312 a.print( os );
00313 return os;
00314 }
00315
00316 }
00317
00318 #endif