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 #ifndef SC_STRING_H
00033 #define SC_STRING_H
00034 
00035 
00036 #include "sysc/utils/sc_iostream.h"
00037 #include "sysc/utils/sc_report.h"
00038 
00039 namespace sc_dt {
00040         class sc_string_old;
00041 }
00042 
00043 #ifdef SC_USE_SC_STRING_OLD
00044         typedef sc_dt::sc_string_old sc_string;
00045 #endif
00046 #ifdef SC_USE_STD_STRING
00047         typedef ::std::string sc_string;
00048 #endif
00049 
00050 namespace sc_dt {
00051 
00052 
00053 class sc_string_rep;
00054 
00055 
00056 sc_string_old operator + ( const char* s, const sc_string_old& t );
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 class sc_string_old
00066 {
00067     friend systemc_ostream& operator << (systemc_ostream& os, const sc_string_old& a);
00068     friend systemc_istream& operator >> ( systemc_istream& is, sc_string_old& a );
00069 
00070 public:
00071 
00072     
00073 
00074     explicit sc_string_old( int size = 16 );
00075     sc_string_old( const char* s );
00076     sc_string_old( const char* s, int n ); 
00077     sc_string_old( const sc_string_old& s );
00078 
00079 
00080     
00081 
00082     ~sc_string_old();
00083 
00084 
00085     
00086 
00087     sc_string_old& operator = ( const char* s );
00088     sc_string_old& operator = ( const sc_string_old& s );
00089 
00090     sc_string_old& operator += ( const char* s );
00091     sc_string_old& operator += ( char c );
00092     sc_string_old& operator += ( const sc_string_old& s );
00093 
00094     sc_string_old operator + ( const char* s ) const;
00095     sc_string_old operator + ( char c ) const;
00096     sc_string_old operator + ( const sc_string_old& s ) const;
00097 
00098     friend sc_string_old operator + ( const char* s, const sc_string_old& t );
00099 
00100 
00101     
00102 
00103     sc_string_old substr( int first, int last ) const;
00104 
00105 
00106     
00107 
00108     bool operator == ( const char* s ) const;
00109     bool operator != ( const char* s ) const;
00110     bool operator <  ( const char* s ) const;
00111     bool operator <= ( const char* s ) const;
00112     bool operator >  ( const char* s ) const;
00113     bool operator >= ( const char* s ) const;
00114     bool operator == ( const sc_string_old& s ) const;
00115     bool operator != ( const sc_string_old& s ) const;
00116     bool operator <  ( const sc_string_old& s ) const;
00117     bool operator <= ( const sc_string_old& s ) const;
00118     bool operator >  ( const sc_string_old& s ) const;
00119     bool operator >= ( const sc_string_old& s ) const;
00120 
00121     
00122     
00123     
00124     int length() const;
00125 
00126     
00127     
00128     
00129     const char* c_str() const;
00130     
00131     
00132     
00133     operator const char*() const;
00134     
00135     
00136     
00137     char operator[](int index) const;
00138     
00139     
00140     
00141     char& operator[](int index);
00142 
00143     
00144     static sc_string_old to_string(const char* format, ...);
00145     
00146     
00147     
00148     
00149     
00150     
00151     
00152     
00153     
00154     
00155     template<class T> sc_string_old& fmt(const T& t)
00156         {
00157             
00158             int index;
00159             int last_char = length()-1;
00160             sc_string_old temp(*this);
00161             do
00162             {
00163                 index = temp.pos("%");
00164                 if(index == last_char)
00165                     return *this;
00166                 temp = substr(index,last_char);
00167             } while(temp[0] != '%');
00168             int f_len = (int)temp.fmt_length(); 
00169             temp = to_string(substr(0,index+f_len-1).c_str(),t);
00170             return (*this) = temp + substr(index+f_len,last_char);
00171         }
00172     sc_string_old& fmt(const sc_string_old& s);
00173     
00174     
00175     
00176     
00177     int pos(const sc_string_old& sub_string)const;
00178     
00179     
00180     
00181     sc_string_old& remove(unsigned index, unsigned length);
00182     
00183     
00184     
00185     sc_string_old& insert(const sc_string_old& sub_string, unsigned index);
00186     
00187     
00188     
00189     
00190     bool is_delimiter(const sc_string_old& str, unsigned index)const;
00191     
00192     
00193     
00194     bool contains(char c)const;
00195     
00196     
00197     
00198     sc_string_old uppercase()const;
00199     
00200     
00201     
00202     sc_string_old lowercase()const;
00203     
00204     
00205     
00206     static sc_string_old make_str(long n);
00207     void set( int index, char c );
00208     int cmp( const char* s ) const;
00209     int cmp( const sc_string_old& s ) const;
00210 
00211 
00212     void print( systemc_ostream& os = ::std::cout ) const;
00213 
00214 private:
00215 
00216     sc_string_old( sc_string_rep* r );
00217 
00218     sc_string_rep* rep;
00219 
00220     void test(int position)const;
00221     unsigned fmt_length()const;
00222 };
00223 
00224 
00225 
00226 
00227 inline
00228 systemc_ostream&
00229 operator << ( systemc_ostream& os, const sc_string_old& a )
00230 {
00231     a.print( os );
00232     return os;
00233 }
00234 
00235 } 
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 
00245 
00246 
00247 
00248 
00249 
00250 
00251 
00252 #endif