Logo
~Sockets~
~Examples~
~Contact~


File Class Reference
[File handling]

IFile implementation of a disk file. More...

#include <File.h>

Inheritance diagram for File:

Inheritance graph
[legend]
Collaboration diagram for File:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 File ()
 ~File ()
bool fopen (const std::string &, const std::string &)
void fclose ()
size_t fread (char *, size_t, size_t)
size_t fwrite (const char *, size_t, size_t)
char * fgets (char *, int)
void fprintf (const char *format,...)
off_t size ()
bool eof ()

Private Member Functions

 File (const File &)
Fileoperator= (const File &)

Private Attributes

std::string m_path
std::string m_mode
FILE * m_fil

Detailed Description

IFile implementation of a disk file.

Definition at line 43 of file File.h.


Constructor & Destructor Documentation

File::File (  ) 

Definition at line 44 of file File.cpp.

00045 :m_fil(NULL)
00046 {
00047 }

File::~File (  ) 

Definition at line 50 of file File.cpp.

00051 {
00052 }

File::File ( const File  )  [inline, private]

Definition at line 62 of file File.h.

00062 {} // copy constructor


Member Function Documentation

bool File::fopen ( const std::string &  ,
const std::string &   
) [virtual]

Implements IFile.

Definition at line 55 of file File.cpp.

References m_fil, m_mode, and m_path.

00056 {
00057         m_path = path;
00058         m_mode = mode;
00059         m_fil = ::fopen(path.c_str(), mode.c_str());
00060         return m_fil ? true : false;
00061 }

void File::fclose (  )  [virtual]

Implements IFile.

Definition at line 64 of file File.cpp.

References m_fil.

00065 {
00066         if (m_fil)
00067 		::fclose(m_fil);
00068 }

size_t File::fread ( char *  ,
size_t  ,
size_t   
) [virtual]

Implements IFile.

Definition at line 72 of file File.cpp.

References m_fil.

00073 {
00074         return m_fil ? ::fread(ptr, size, nmemb, m_fil) : 0;
00075 }

size_t File::fwrite ( const char *  ,
size_t  ,
size_t   
) [virtual]

Implements IFile.

Definition at line 78 of file File.cpp.

References m_fil.

00079 {
00080         return m_fil ? ::fwrite(ptr, size, nmemb, m_fil) : 0;
00081 }

char * File::fgets ( char *  ,
int   
) [virtual]

Implements IFile.

Definition at line 85 of file File.cpp.

References m_fil.

00086 {
00087         return m_fil ? ::fgets(s, size, m_fil) : NULL;
00088 }

void File::fprintf ( const char *  format,
  ... 
) [virtual]

Implements IFile.

Definition at line 91 of file File.cpp.

References m_fil.

00092 {
00093         va_list ap;
00094         va_start(ap, format);
00095         vfprintf(m_fil, format, ap);
00096         va_end(ap);
00097 }

off_t File::size (  )  [virtual]

Implements IFile.

Definition at line 100 of file File.cpp.

References m_path.

00101 {
00102         struct stat st;
00103         if (stat(m_path.c_str(), &st) == -1)
00104         {
00105                 return 0;
00106         }
00107         return st.st_size;
00108 }

bool File::eof (  )  [virtual]

Implements IFile.

Definition at line 111 of file File.cpp.

References m_fil.

00112 {
00113         if (m_fil)
00114         {
00115                 if (feof(m_fil))
00116                         return true;
00117         }
00118         return false;
00119 }

File& File::operator= ( const File  )  [inline, private]

Definition at line 63 of file File.h.

00063 { return *this; } // assignment operator


Member Data Documentation

std::string File::m_path [private]

Definition at line 65 of file File.h.

Referenced by fopen(), and size().

std::string File::m_mode [private]

Definition at line 66 of file File.h.

Referenced by fopen().

FILE* File::m_fil [private]

Definition at line 67 of file File.h.

Referenced by eof(), fclose(), fgets(), fopen(), fprintf(), fread(), and fwrite().


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4