rllib  1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Member Functions | Private Attributes | List of all members
rlFileLoad Class Reference

#include <rlfileload.h>

Collaboration diagram for rlFileLoad:
Collaboration graph
[legend]

Public Member Functions

 rlFileLoad ()
 
virtual ~rlFileLoad ()
 
int load (const char *filename)
 
void unload ()
 
const char * firstLine ()
 
const char * nextLine ()
 
void setDebug (int state)
 

Private Attributes

int loaded
 
int debug
 
rlFileLines file_lines
 
rlFileLinescurrent_line
 

Detailed Description

This class loads a text file to memory.
Then you can iterate to it's lines.

Definition at line 31 of file rlfileload.h.

Constructor & Destructor Documentation

rlFileLoad::rlFileLoad ( )

Definition at line 20 of file rlfileload.cpp.

{
loaded = debug = 0;
file_lines.line = NULL;
file_lines.next = NULL;
current_line = NULL;
}
rlFileLoad::~rlFileLoad ( )
virtual

Definition at line 28 of file rlfileload.cpp.

{
unload();
}

Member Function Documentation

const char * rlFileLoad::firstLine ( )

Definition at line 81 of file rlfileload.cpp.

{
if(loaded == 0) return NULL;
if(current_line == NULL) return NULL;
if(debug) printf("rlFileLoad::firstLine=%s",current_line->line);
return current_line->line;
}
int rlFileLoad::load ( const char *  filename)

Definition at line 33 of file rlfileload.cpp.

{
FILE *fin;
char line[rl_PRINTF_LENGTH], *cptr;
unload();
fin = fopen(filename,"r");
if(fin == NULL) return -1;
fl = &file_lines;
while(fgets(line,sizeof(line)-1,fin) != NULL)
{
cptr = strchr(line,'\n');
if(cptr != NULL) *cptr = '\0';
cptr = strchr(line,0x0D);
if(cptr != NULL) *cptr = '\0';
if(debug) printf("rlFileLoad::load line=%s\n",line);
fl->next = new rlFileLines;
fl = fl->next;
fl->line = new char [strlen(line)+1];
strcpy(fl->line,line);
fl->next = NULL;
}
fclose(fin);
loaded = 1;
return 1;
}
const char * rlFileLoad::nextLine ( )

Definition at line 91 of file rlfileload.cpp.

{
if(loaded == 0) return NULL;
if(current_line == NULL) return NULL;
if(debug) printf("rlFileLoad::nextLine=%s",current_line->line);
return current_line->line;
}
void rlFileLoad::setDebug ( int  state)

Definition at line 100 of file rlfileload.cpp.

{
if(state == 0) debug = 0;
else debug = 1;
}
void rlFileLoad::unload ( )

Definition at line 63 of file rlfileload.cpp.

{
rlFileLines *fl,*flold;
if(loaded == 0) return;
fl = &file_lines;
fl = fl->next;
while(fl != NULL)
{
if(debug) printf("rlFileLoad::unload line=%s",fl->line);
delete [] fl->line;
flold = fl;
fl = fl->next;
delete flold;
}
loaded = 0;
}

Member Data Documentation

rlFileLines* rlFileLoad::current_line
private

Definition at line 45 of file rlfileload.h.

int rlFileLoad::debug
private

Definition at line 43 of file rlfileload.h.

rlFileLines rlFileLoad::file_lines
private

Definition at line 44 of file rlfileload.h.

int rlFileLoad::loaded
private

Definition at line 42 of file rlfileload.h.


The documentation for this class was generated from the following files: