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