@@ -23,22 +23,20 @@ extern void HeaderSchemaInit( Registry & reg );
2323
2424// constructor & destructor
2525
26- STEPfile::STEPfile ( Registry & r, InstMgr & i, const char * filename )
27- :
26+ STEPfile::STEPfile ( Registry & r, InstMgr & i, const std::string filename ) :
2827 _reg( r ), _instances( i ),
29- _headerId( 0 ), _maxErrorCount( 5000 ),
30- _fileName( 0 ), _entsNotCreated( 0 ), _entsInvalid( 0 ),
31- _entsIncomplete( 0 ), _entsWarning( 0 ),
32- _errorCount( 0 ), _warningCount( 0 ),
33- _fileIdIncr( 0 )
34-
28+ _headerId( 0 ), _maxErrorCount( 5000 ),
29+ _fileName( " " ), _entsNotCreated( 0 ), _entsInvalid( 0 ),
30+ _entsIncomplete( 0 ), _entsWarning( 0 ),
31+ _errorCount( 0 ), _warningCount( 0 ),
32+ _fileIdIncr( 0 )
3533{
3634 SetFileType ( VERSION_CURRENT );
3735 SetFileIdIncrement ();
3836 _currentDir = new DirObj ( " " );
3937 _headerRegistry = new Registry ( HeaderSchemaInit );
4038 _headerInstances = new InstMgr;
41- if ( filename ) {
39+ if ( ! filename. empty () ) {
4240 ReadExchangeFile ( filename );
4341 }
4442}
@@ -86,19 +84,23 @@ int STEPfile::SetFileType( FileTypeCode ft ) {
8684
8785
8886/* *****************************************************/
89- const char * STEPfile::TruncFileName ( const char * filename ) const {
90- const char * tmp = strrchr ( filename, ' /' );
91- if ( tmp ) {
92- return tmp++;
93- } else {
87+ std::string STEPfile::TruncFileName ( const std::string filename ) const {
88+ #if defined(__WIN32__) && !defined(__mingw32__)
89+ char slash = ' \\ ' ;
90+ #else
91+ char slash = ' /' ;
92+ #endif
93+ size_t l = filename.find_last_of ( slash );
94+ if ( l == std::string::npos ) {
9495 return filename;
96+ } else {
97+ return filename.substr ( l );
9598 }
96-
9799}
98100
99101
100102/* *****************************************************/
101- Severity STEPfile::ReadExchangeFile ( const char * filename, int useTechCor ) {
103+ Severity STEPfile::ReadExchangeFile ( const std::string filename, int useTechCor ) {
102104 _error.ClearErrorMsg ();
103105 _errorCount = 0 ;
104106 istream * in = OpenInputFile ( filename );
@@ -117,7 +119,7 @@ Severity STEPfile::ReadExchangeFile( const char * filename, int useTechCor ) {
117119 return rval;
118120}
119121
120- Severity STEPfile::AppendExchangeFile ( const char * filename, int useTechCor ) {
122+ Severity STEPfile::AppendExchangeFile ( const std::string filename, int useTechCor ) {
121123 _error.ClearErrorMsg ();
122124 _errorCount = 0 ;
123125 istream * in = OpenInputFile ( filename );
@@ -130,7 +132,7 @@ Severity STEPfile::AppendExchangeFile( const char * filename, int useTechCor ) {
130132 return rval;
131133}
132134
133- Severity STEPfile::ReadWorkingFile ( const char * filename, int useTechCor ) {
135+ Severity STEPfile::ReadWorkingFile ( const std::string filename, int useTechCor ) {
134136 _error.ClearErrorMsg ();
135137 _errorCount = 0 ;
136138 istream * in = OpenInputFile ( filename );
@@ -150,7 +152,7 @@ Severity STEPfile::ReadWorkingFile( const char * filename, int useTechCor ) {
150152}
151153
152154
153- Severity STEPfile::AppendWorkingFile ( const char * filename, int useTechCor ) {
155+ Severity STEPfile::AppendWorkingFile ( const std::string filename, int useTechCor ) {
154156 _error.ClearErrorMsg ();
155157 _errorCount = 0 ;
156158 istream * in = OpenInputFile ( filename );
@@ -165,33 +167,33 @@ Severity STEPfile::AppendWorkingFile( const char * filename, int useTechCor ) {
165167 return rval;
166168}
167169
168- istream * STEPfile::OpenInputFile ( const char * filename ) {
170+ istream * STEPfile::OpenInputFile ( const std::string filename ) {
169171 // if there's no filename to use, fail
170- if ( !( strcmp ( filename, " " ) || strcmp ( FileName (), " " ) ) ) {
172+ if ( filename. empty () && FileName (). empty ( ) ) {
171173 _error.AppendToUserMsg ( " Unable to open file for input. No current file name.\n " );
172174 _error.GreaterSeverity ( SEVERITY_INPUT_ERROR );
173- return ( 0 );
175+ return ( 0 );
174176 } else {
175- if ( ! SetFileName ( filename ) && ( strcmp ( filename, " -" ) != 0 ) ) {
177+ if ( SetFileName ( filename ). empty () && ( filename. compare ( " -" ) != 0 ) ) {
176178 char msg[BUFSIZ];
177- sprintf ( msg, " Unable to find file for input: \' %s\' . File not read.\n " , filename );
179+ sprintf ( msg, " Unable to find file for input: \' %s\' . File not read.\n " , filename. c_str () );
178180 _error.AppendToUserMsg ( msg );
179181 _error.GreaterSeverity ( SEVERITY_INPUT_ERROR );
180- return ( 0 );
182+ return ( 0 );
181183 }
182184 }
183185
184186 std::istream * in;
185187
186- if ( strcmp ( filename, " -" ) == 0 ) {
188+ if ( filename. compare ( " -" ) == 0 ) {
187189 in = &std::cin;
188190 } else {
189- in = new ifstream ( FileName () );
191+ in = new ifstream ( FileName (). c_str () );
190192 }
191193
192194 if ( !in || !( in -> good () ) ) {
193195 char msg[BUFSIZ];
194- sprintf ( msg, " Unable to open file for input: \' %s\' . File not read.\n " , filename );
196+ sprintf ( msg, " Unable to open file for input: \' %s\' . File not read.\n " , filename. c_str () );
195197 _error.AppendToUserMsg ( msg );
196198 _error.GreaterSeverity ( SEVERITY_INPUT_ERROR );
197199 return ( 0 );
@@ -206,27 +208,25 @@ void STEPfile::CloseInputFile( istream * in ) {
206208 }
207209}
208210
209- ofstream * STEPfile::OpenOutputFile ( const char * filename ) {
210- if ( ! filename ) {
211- if ( ! FileName () ) {
211+ ofstream * STEPfile::OpenOutputFile ( std::string filename ) {
212+ if ( filename. empty () ) {
213+ if ( FileName (). empty () ) {
212214 _error.AppendToUserMsg ( " No current file name.\n " );
213215 _error.GreaterSeverity ( SEVERITY_INPUT_ERROR );
214216 }
215217 } else {
216- if ( ! SetFileName ( filename ) ) {
218+ if ( SetFileName ( filename ). empty ( ) ) {
217219 char msg[BUFSIZ];
218- sprintf ( msg, " can't find file: %s\n File not written.\n " , filename );
220+ sprintf ( msg, " can't find file: %s\n File not written.\n " , filename. c_str () );
219221 _error.AppendToUserMsg ( msg );
220222 _error.GreaterSeverity ( SEVERITY_INPUT_ERROR );
221223 }
222224 }
223225
224- if ( _currentDir->FileExists ( TruncFileName ( FileName () ) ) ) {
226+ if ( _currentDir->FileExists ( TruncFileName ( filename ) ) ) {
225227 MakeBackupFile ();
226228 }
227-
228- ofstream * out = new ofstream ( FileName () );
229- // default for ostream is writeonly and protections are set to 644
229+ ofstream * out = new ofstream ( filename.c_str () );
230230 if ( !out ) {
231231 _error.AppendToUserMsg ( " unable to open file for output\n " );
232232 _error.GreaterSeverity ( SEVERITY_INPUT_ERROR );
0 commit comments