ReactOS  r73918
File Class Reference

#include <File.h>

Collaboration diagram for File:

Public Member Functions

 File ()
 
 File (const char *filename, const char *mode)
 
 ~File ()
 
bool open (const char *filename, const char *mode)
 
bool seek (long offset)
 
int get ()
 
bool put (int c)
 
std::string getline (bool strip_crlf=false)
 
bool next_line (std::string &line, bool strip_crlf)
 
bool enum_lines (bool(*callback)(const std::string &line, int line_number, long lparam), long lparam, bool strip_crlf)
 
bool read (void *data, unsigned len)
 
bool write (const void *data, unsigned len)
 
size_t length ()
 
void close ()
 
bool isopened ()
 
bool eof ()
 
FILEoperator* ()
 

Static Public Member Functions

static bool LoadIntoString (std::string &s, const char *filename)
 
static bool SaveFromString (const char *filename, const std::string &s, bool binary)
 

Private Member Functions

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

Private Attributes

FILE_f
 

Detailed Description

Definition at line 15 of file File.h.

Constructor & Destructor Documentation

File::File ( )
inline

Definition at line 18 of file File.h.

18  : _f(0)
19  {
20  }
FILE * _f
Definition: File.h:108
File::File ( const char filename,
const char mode 
)
inline

Definition at line 22 of file File.h.

22  : _f(0)
23  {
24  open ( filename, mode );
25  }
LPCSTR filename
Definition: alphablend.c:63
FILE * _f
Definition: File.h:108
bool open(const char *filename, const char *mode)
Definition: File.cpp:10
File::~File ( )
inline

Definition at line 27 of file File.h.

28  {
29  close();
30  }
void close()
Definition: File.cpp:99
File::File ( const File )
inlineprivate

Definition at line 105 of file File.h.

105 {}

Member Function Documentation

void File::close ( void  )

Definition at line 99 of file File.cpp.

Referenced by open(), and ~File().

100 {
101  if ( _f )
102  {
103  fclose(_f);
104  _f = 0;
105  }
106 }
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
FILE * _f
Definition: File.h:108
bool File::enum_lines ( bool(*)(const std::string &line, int line_number, long lparam callback,
long  lparam,
bool  strip_crlf 
)

Definition at line 69 of file File.cpp.

70 {
71  int line_number = 0;
72  for ( ;; )
73  {
74  std::string s = getline(strip_crlf);
75  line_number++;
76  if ( !s.size() )
77  {
78  if ( eof() )
79  return true;
80  else
81  continue;
82  }
83  if ( !(*callback) ( s, line_number, lparam ) )
84  return false;
85  }
86 }
int line_number
Definition: parser.yy.c:773
std::string getline(bool strip_crlf=false)
Definition: File.cpp:17
MmuTrapHandler callback[0x30]
Definition: mmuobject.c:44
bool eof()
Definition: File.h:91
GLdouble s
Definition: gl.h:2039
UINT WPARAM LPARAM lparam
Definition: msvc.h:92
char string[160]
Definition: util.h:11
bool File::eof ( )
inline

Definition at line 91 of file File.h.

Referenced by enum_lines(), and next_line().

92  {
93  return feof(_f) ? true : false;
94  }
_Check_return_ _CRTIMP int __cdecl feof(_In_ FILE *_File)
FILE * _f
Definition: File.h:108
int File::get ( )
inline

Definition at line 39 of file File.h.

40  {
41  return fgetc ( _f );
42  }
FILE * _f
Definition: File.h:108
_Check_return_opt_ _CRTIMP int __cdecl fgetc(_Inout_ FILE *_File)
std::string File::getline ( bool  strip_crlf = false)

Definition at line 17 of file File.cpp.

Referenced by enum_lines(), and next_line().

18 {
19  std::string s = "";
20  char buf[256];
21  for ( ;; )
22  {
23  *buf = 0;
24  fgets ( buf, sizeof(buf)-1, _f );
25  if ( !*buf )
26  break;
27  s += buf;
28  if ( strchr ( "\r\n", buf[strlen(buf)-1] ) )
29  break;
30  }
31  if ( strip_crlf )
32  {
33  char* p = strpbrk ( &s[0], "\r\n" );
34  if ( p )
35  {
36  *p = '\0';
37  s.resize ( p-&s[0] );
38  }
39  }
40  return s;
41 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strpbrk(const char *String, const char *Delimiters)
Definition: utclib.c:302
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLdouble s
Definition: gl.h:2039
FILE * _f
Definition: File.h:108
char string[160]
Definition: util.h:11
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
char * strchr(const char *String, int ch)
Definition: utclib.c:501
GLfloat GLfloat p
Definition: glext.h:8902
bool File::isopened ( )
inline

Definition at line 86 of file File.h.

Referenced by LoadIntoString(), main(), and SaveFromString().

87  {
88  return _f != 0;
89  }
FILE * _f
Definition: File.h:108
size_t File::length ( )

Definition at line 88 of file File.cpp.

Referenced by LoadIntoString().

89 {
90 #ifdef WIN32
91  return _filelength ( _fileno(_f) );
92 #elif defined(UNIX)
93  struct stat file_stat;
94  verify(fstat(fileno(_f), &file_stat) == 0);
95  return file_stat.st_size;
96 #endif
97 }
_Check_return_ _CRTIMP long __cdecl _filelength(_In_ int _FileHandle)
_Check_return_ _CRTIMP int __cdecl fileno(_In_ FILE *_File)
Definition: stat.h:55
FILE * _f
Definition: File.h:108
static char * file_stat(DOS_FILE *file)
Definition: check.c:248
_CRTIMP int __cdecl fstat(int _Desc, struct stat *_Stat)
Definition: stat.h:341
_Check_return_ _CRTIMP int __cdecl _fileno(_In_ FILE *_File)
bool File::LoadIntoString ( std::string s,
const char filename 
)
static

Definition at line 108 of file File.cpp.

Referenced by import_file().

109 {
110  File in ( filename, "rb" );
111  if ( !in.isopened() )
112  return false;
113  size_t len = in.length();
114  s.resize ( len + 1 );
115  if ( !in.read ( &s[0], len ) )
116  return false;
117  s[len] = '\0';
118  s.resize ( len );
119  return true;
120 }
LPCSTR filename
Definition: alphablend.c:63
GLdouble s
Definition: gl.h:2039
GLenum GLsizei len
Definition: glext.h:6722
GLfloat CONST GLvector4f * in
Definition: m_xform.h:122
Definition: File.h:15
bool File::next_line ( std::string line,
bool  strip_crlf 
)

Definition at line 47 of file File.cpp.

Referenced by main().

48 {
49  line = getline(strip_crlf);
50  // indicate that we're done *if*:
51  // 1) there's no more data, *and*
52  // 2) we're at the end of the file
53  return line.size()>0 || !eof();
54 }
std::string getline(bool strip_crlf=false)
Definition: File.cpp:17
Definition: parser.c:48
bool eof()
Definition: File.h:91
bool File::open ( const char filename,
const char mode 
)

Definition at line 10 of file File.cpp.

Referenced by File().

11 {
12  close();
13  _f = fopen ( filename, mode );
14  return _f != 0;
15 }
LPCSTR filename
Definition: alphablend.c:63
void close()
Definition: File.cpp:99
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
FILE * _f
Definition: File.h:108
FILE* File::operator* ( )
inline

Definition at line 96 of file File.h.

97  {
98  return _f;
99  }
FILE * _f
Definition: File.h:108
const File& File::operator= ( const File )
inlineprivate

Definition at line 106 of file File.h.

106 { return *this; }
bool File::put ( int  c)
inline

Definition at line 44 of file File.h.

45  {
46  return fputc ( c, _f ) != EOF;
47  }
_Check_return_opt_ _CRTIMP int __cdecl fputc(_In_ int _Ch, _Inout_ FILE *_File)
const GLubyte * c
Definition: glext.h:8905
FILE * _f
Definition: File.h:108
#define EOF
Definition: stdio.h:24
bool File::read ( void data,
unsigned  len 
)
inline

Definition at line 72 of file File.h.

Referenced by LoadIntoString().

73  {
74  return len == fread ( data, 1, len, _f );
75  }
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
GLenum GLsizei len
Definition: glext.h:6722
FILE * _f
Definition: File.h:108
bool File::SaveFromString ( const char filename,
const std::string s,
bool  binary 
)
static

Definition at line 122 of file File.cpp.

123 {
124  File out ( filename, binary ? "wb" : "w" );
125  if ( !out.isopened() )
126  return false;
127  out.write ( s.c_str(), s.size() );
128  return true;
129 }
LPCSTR filename
Definition: alphablend.c:63
static FILE * out
Definition: regtests2xml.c:44
const GLuint GLenum const GLvoid * binary
Definition: glext.h:7538
GLdouble s
Definition: gl.h:2039
Definition: File.h:15
bool File::seek ( long  offset)
inline

Definition at line 34 of file File.h.

35  {
36  return !fseek ( _f, offset, SEEK_SET );
37  }
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
#define SEEK_SET
Definition: jmemansi.c:26
FILE * _f
Definition: File.h:108
GLintptr offset
Definition: glext.h:5920
bool File::write ( const void data,
unsigned  len 
)
inline

Definition at line 77 of file File.h.

Referenced by SaveFromString().

78  {
79  return len == fwrite ( data, 1, len, _f );
80  }
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
GLenum GLsizei len
Definition: glext.h:6722
FILE * _f
Definition: File.h:108

Member Data Documentation

FILE* File::_f
private

Definition at line 108 of file File.h.

Referenced by close(), eof(), get(), getline(), isopened(), length(), open(), operator*(), put(), read(), seek(), and write().


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