00001
00036
00037 #ifndef CLDAQ__TUTILITIES_HH
00038 #define CLDAQ__TUTILITIES_HH
00039
00040 #include "Ttypes.h"
00041
00042
00062 class TUtilities
00063 {
00064
00065 public:
00066 static Tstring ConvertIntegerToString( Tint i, Tint digits );
00067 static Tstring ConvertLongToString( Tlong l, Tint digits );
00068 static Tstring ConvertUnsignedLongToString( TUlong ul, Tint digits );
00069 static Tstring ConvertDoubleToString( Tdouble d, Tint precision );
00070 static Tstring ConvertFloatToString( Tfloat f, Tint precision );
00071 static Tint ConvertStringToInteger( const Tstring& nptr, Tchar** endptr, Tint base );
00072 static Tdouble ConvertStringToDouble( const Tstring& nptr, Tchar** endptr );
00073 static Tvoid ShowBitPattern( Tint bit );
00074 static Tbool FileExist( const Tstring& filename, Tint mode );
00075 static TstringList Split( const Tstring& source, const Tstring& pattern, Tint pos );
00076 static TintList Index( const Tstring& source, const Tstring& pattern, Tint pos );
00077 static TintList Size( const Tstring& source, const Tstring& pattern, Tint pos );
00078 static Tstring Substitute( const Tstring& source, const Tstring& pattern, const Tstring& substr, Tint pos );
00079 static Tstring SubstituteAll( const Tstring& source, const Tstring& pattern, const Tstring& substr, Tint pos );
00080 static Tbool IsMatch( const Tstring& source, const Tstring& pattern, Tbool igcase, Tint pos );
00081 static Tint GetNumberOfMatches( const Tstring& source, const Tstring& pattern, Tint pos );
00082 static Tstring GetSubMatch( Tint index, const Tstring& source, const Tstring& pattern, Tint pos );
00083 static TstringList GetSubMatch( const Tstring& source, const Tstring& pattern, Tint pos );
00084 static Tstring GetBaseName( const Tstring& path );
00085 static Tstring GetDirectoryName( const Tstring& path );
00086
00087 public:
00088 friend Tstring itostr( Tint i, Tint digits = 6 );
00089 friend Tstring ltostr( Tlong l, Tint digits = 6 );
00090 friend Tstring ultostr( TUlong ul, Tint digits = 6 );
00091 friend Tstring dtostr( Tdouble d, Tint precision = 6 );
00092 friend Tstring ftostr( Tfloat f, Tint precision = 6 );
00093 friend Tint strtoi( const Tstring& nptr, Tchar** endptr = 0, Tint base = 0 );
00094 friend Tdouble strtod( const Tstring& nptr, Tchar** endptr = 0 );
00095 friend Tvoid showbit( Tint bit );
00096 friend Tbool isexist( const Tstring& filename, Tint mode = R_OK|F_OK );
00097 friend TstringList split( const Tstring& source, const Tstring& pattern = "(\t| |\\s)+", Tint pos = 0 );
00098 friend TintList index( const Tstring& source, const Tstring& pattern = "(\t| |\\s)+", Tint pos = 0 );
00099 friend TintList size( const Tstring& source, const Tstring& pattern, Tint pos = 0 );
00100 friend Tstring subst( const Tstring& source, const Tstring& pattern = "(#.*)|(//.*)", const Tstring& substr = "", Tbool all = Ttrue, Tint pos = 0 );
00101 friend Tbool match( const Tstring& source, const Tstring& pattern, Tbool igcase = Tfalse, Tint pos = 0 );
00102 friend Tint nmatch( const Tstring& source, const Tstring& pattern, Tint pos = 0 );
00103 friend Tstring submatch( Tint index, const Tstring& source, const Tstring& pattern, Tint pos = 0 );
00104 friend TstringList submatch( const Tstring& source, const Tstring& pattern, Tint pos = 0 );
00105 friend Tbool grep( const Tstring& source, const Tstring& pattern, Tbool igcase = Tfalse, Tint pos = 0 );
00106 friend Tstring basename( const Tstring& path );
00107 friend Tstring dirname( const Tstring& path );
00108
00109 #ifdef __CLDAQ_ROOT_DLL
00110 ClassDef(TUtilities,0)
00111 #endif
00112
00113 };
00114
00115 inline Tstring itostr( Tint i, Tint digits )
00116 {
00117 return TUtilities::ConvertIntegerToString( i, digits );
00118 }
00119
00120 inline Tstring ltostr( Tlong l, Tint digits )
00121 {
00122 return TUtilities::ConvertLongToString( l, digits );
00123 }
00124
00125 inline Tstring ultostr( TUlong ul, Tint digits )
00126 {
00127 return TUtilities::ConvertUnsignedLongToString( ul, digits );
00128 }
00129
00130 inline Tstring dtostr( Tdouble d, Tint precision )
00131 {
00132 return TUtilities::ConvertDoubleToString( d, precision );
00133 }
00134
00135 inline Tstring ftostr( Tfloat f, Tint precision )
00136 {
00137 return TUtilities::ConvertFloatToString( f, precision );
00138 }
00139
00140 inline Tint strtoi( const Tstring& nptr, Tchar** endptr, Tint base )
00141 {
00142 return TUtilities::ConvertStringToInteger( nptr, endptr, base );
00143 }
00144
00145 inline Tdouble strtod( const Tstring& nptr, Tchar** endptr )
00146 {
00147 return TUtilities::ConvertStringToDouble( nptr, endptr );
00148 }
00149
00150 inline Tvoid showbit( Tint bit )
00151 {
00152 TUtilities::ShowBitPattern( bit );
00153 return;
00154 }
00155
00156 inline Tbool isexist( const Tstring& filename, Tint mode )
00157 {
00158 return TUtilities::FileExist( filename, mode );
00159 }
00160
00161 inline TstringList split( const Tstring& source, const Tstring& pattern, Tint pos )
00162 {
00163 return TUtilities::Split( source, pattern, pos );
00164 }
00165
00166 inline TintList index( const Tstring& source, const Tstring& pattern, Tint pos )
00167 {
00168 return TUtilities::Index( source, pattern, pos );
00169 }
00170
00171 inline TintList size( const Tstring& source, const Tstring& pattern, Tint pos )
00172 {
00173 return TUtilities::Size( source, pattern, pos );
00174 }
00175
00176 inline Tstring subst( const Tstring& source, const Tstring& pattern, const Tstring& substr, Tbool all, Tint pos )
00177 {
00178 if ( all ) {
00179 return TUtilities::SubstituteAll( source, pattern, substr, pos );
00180 } else {
00181 return TUtilities::Substitute( source, pattern, substr, pos );
00182 }
00183 }
00184
00185 inline Tbool match( const Tstring& source, const Tstring& pattern, Tbool igcase, Tint pos )
00186 {
00187 return TUtilities::IsMatch( source, pattern, igcase, pos );
00188 }
00189
00190 inline Tbool grep( const Tstring& source, const Tstring& pattern, Tbool igcase, Tint pos )
00191 {
00192 return TUtilities::IsMatch( source, pattern, igcase, pos );
00193 }
00194
00195 inline Tstring submatch( Tint index, const Tstring& source, const Tstring& pattern, Tint pos )
00196 {
00197 return TUtilities::GetSubMatch( index, source, pattern, pos );
00198 }
00199
00200 inline TstringList submatch( const Tstring& source, const Tstring& pattern, Tint pos )
00201 {
00202 return TUtilities::GetSubMatch( source, pattern, pos );
00203 }
00204
00205 inline Tstring basename( const Tstring& path )
00206 {
00207 return TUtilities::GetBaseName( path );
00208 }
00209
00210 inline Tstring dirname( const Tstring& path )
00211 {
00212 return TUtilities::GetDirectoryName( path );
00213 }
00214
00215 #endif