Allow TextFile to return its own filename

This commit is contained in:
Ryan Curtin
2010-04-28 14:43:59 +00:00
parent 5b2be37ec8
commit b7e7052f4e
2 changed files with 16 additions and 2 deletions
@@ -108,6 +108,7 @@ void TextLineReader::Error(const char *format, ...) {
success_t TextLineReader::Open(const char *fname) {
f_ = fopen(fname, "r");
fname_ = strncpy(new char[strlen(fname) + 1], fname, strlen(fname) + 1);
line_num_ = 0;
has_line_ = false;
line_.Init();
@@ -62,6 +62,7 @@ class TextLineReader {
private:
FILE *f_;
char *fname_;
String line_;
int line_num_;
bool has_line_;
@@ -70,15 +71,17 @@ class TextLineReader {
/** Creates an unitialized object. */
TextLineReader() {
f_ = NULL;
fname_ = NULL;
}
/**
* Automatically closes the file.
*/
~TextLineReader() {
if (f_) {
if(f_)
::fclose(f_);
}
if(fname_)
delete[] fname_;
}
/**
@@ -96,6 +99,16 @@ class TextLineReader {
void Close() {
(void)fclose(f_);
f_ = NULL;
if(fname_)
delete[] fname_;
}
/**
* Return the name of the file we are working with.
* This will return NULL if no file has been opened yet.
*/
const char *filename() const {
return fname_;
}
/**