ReactOS 0.4.15-dev-7934-g1dc8d80
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() [1/3]

◆ File() [2/3]

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 }
#define open
Definition: acwin.h:95
GLenum mode
Definition: glext.h:6217
const char * filename
Definition: ioapi.h:137

◆ ~File()

File::~File ( )
inline

Definition at line 27 of file File.h.

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

◆ File() [3/3]

File::File ( const File )
inlineprivate

Definition at line 105 of file File.h.

105{}

Member Function Documentation

◆ close()

void File::close ( )

Definition at line 99 of file File.cpp.

100{
101 if ( _f )
102 {
103 fclose(_f);
104 _f = 0;
105 }
106}
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)

Referenced by close(), open(), QMyDialog::SaveClicked(), and ~File().

◆ enum_lines()

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);
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}
@ lparam
Definition: SystemMenu.c:31
bool eof()
Definition: File.h:91
GLdouble s
Definition: gl.h:2039
static IPrintDialogCallback callback
Definition: printdlg.c:326
#define getline
Definition: schily.h:567
static long line_number
Definition: main.cpp:17

Referenced by enum_lines().

◆ eof()

bool File::eof ( )
inline

Definition at line 91 of file File.h.

92 {
93 return feof(_f) ? true : false;
94 }
_Check_return_ _CRTIMP int __cdecl feof(_In_ FILE *_File)
#define true
Definition: stdbool.h:36

Referenced by enum_lines(), and next_line().

◆ get()

int File::get ( )
inline

Definition at line 39 of file File.h.

40 {
41 return fgetc ( _f );
42 }
_Check_return_opt_ _CRTIMP int __cdecl fgetc(_Inout_ FILE *_File)

◆ getline()

std::string File::getline ( bool  strip_crlf = false)

Definition at line 17 of file File.cpp.

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 * strchr(const char *String, int ch)
Definition: utclib.c:501
char * strpbrk(const char *String, const char *Delimiters)
Definition: utclib.c:302
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLfloat GLfloat p
Definition: glext.h:8902
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)

Referenced by getline().

◆ isopened()

bool File::isopened ( )
inline

Definition at line 86 of file File.h.

87 {
88 return _f != 0;
89 }

◆ length()

size_t File::length ( )

Definition at line 88 of file File.cpp.

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}
#define fileno
Definition: acwin.h:102
#define fstat
Definition: acwin.h:100
static char * file_stat(DOS_FILE *file)
Definition: check.c:279
_Check_return_ _CRTIMP int __cdecl _fileno(_In_ FILE *_File)
_Check_return_ _CRTIMP long __cdecl _filelength(_In_ int _FileHandle)
Definition: stat.h:55

Referenced by CCabinet::GetAttributesOnFile(), CCabinet::GetFileTimes(), and length().

◆ LoadIntoString()

bool File::LoadIntoString ( std::string &  s,
const char filename 
)
static

Definition at line 108 of file File.cpp.

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}
Definition: File.h:16
GLuint in
Definition: glext.h:9616
GLenum GLsizei len
Definition: glext.h:6722

Referenced by LoadIntoString().

◆ next_line()

bool File::next_line ( std::string &  line,
bool  strip_crlf 
)

Definition at line 47 of file File.cpp.

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}
Definition: parser.c:49

Referenced by next_line().

◆ open()

bool File::open ( const char filename,
const char mode 
)

Definition at line 10 of file File.cpp.

11{
12 close();
13 _f = fopen ( filename, mode );
14 return _f != 0;
15}
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)

Referenced by generate_random(), open(), QMyDialog::QMyDialog(), and QMyDialog::SaveClicked().

◆ operator*()

FILE * File::operator* ( )
inline

Definition at line 96 of file File.h.

97 {
98 return _f;
99 }

◆ operator=()

const File & File::operator= ( const File )
inlineprivate

Definition at line 106 of file File.h.

106{ return *this; }

◆ put()

bool File::put ( int  c)
inline

Definition at line 44 of file File.h.

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

◆ read()

bool File::read ( void data,
unsigned  len 
)
inline

Definition at line 72 of file File.h.

73 {
74 return len == fread ( data, 1, len, _f );
75 }
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
_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)

◆ SaveFromString()

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}
const GLuint GLenum const GLvoid * binary
Definition: glext.h:7538
static FILE * out
Definition: regtests2xml.c:44

Referenced by SaveFromString().

◆ seek()

bool File::seek ( long  offset)
inline

Definition at line 34 of file File.h.

35 {
36 return !fseek ( _f, offset, SEEK_SET );
37 }
GLintptr offset
Definition: glext.h:5920
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
#define SEEK_SET
Definition: jmemansi.c:26

◆ write()

bool File::write ( const void data,
unsigned  len 
)
inline

Definition at line 77 of file File.h.

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)

Member Data Documentation

◆ _f

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: