ReactOS 0.4.16-dev-109-gf4cb10f
File.h
Go to the documentation of this file.
1// File.h
2// This file is (C) 2002-2003 Royce Mitchell III and released under the BSD license
3
4#ifndef FILE_H
5#define FILE_H
6
7#ifdef WIN32
8# include <io.h>
9#elif defined(UNIX)
10# include <sys/stat.h>
11# include <unistd.h>
12#endif
13#include <string>
14
15class File
16{
17public:
18 File() : _f(0)
19 {
20 }
21
22 File ( const char* filename, const char* mode ) : _f(0)
23 {
24 open ( filename, mode );
25 }
26
28 {
29 close();
30 }
31
32 bool open ( const char* filename, const char* mode );
33
34 bool seek ( long offset )
35 {
36 return !fseek ( _f, offset, SEEK_SET );
37 }
38
39 int get()
40 {
41 return fgetc ( _f );
42 }
43
44 bool put ( int c )
45 {
46 return fputc ( c, _f ) != EOF;
47 }
48
49 std::string getline ( bool strip_crlf = false );
50
51 // this function searches for the next end-of-line and puts all data it
52 // finds until then in the 'line' parameter.
53 //
54 // call continuously until the function returns false ( no more data )
55 bool next_line ( std::string& line, bool strip_crlf );
56
57 /*
58 example usage:
59
60 bool mycallback ( const std::string& line, int line_number, long lparam )
61 {
62 std::cout << line << std::endl;
63 return true; // continue enumeration
64 }
65
66 File f ( "file.txt", "rb" ); // open file for binary read-only ( i.e. "rb" )
67 f.enum_lines ( mycallback, 0, true );
68 */
69
70 bool enum_lines ( bool (*callback)(const std::string& line, int line_number, long lparam), long lparam, bool strip_crlf );
71
72 bool read ( void* data, unsigned len )
73 {
74 return len == fread ( data, 1, len, _f );
75 }
76
77 bool write ( const void* data, unsigned len )
78 {
79 return len == fwrite ( data, 1, len, _f );
80 }
81
82 size_t length();
83
84 void close();
85
86 bool isopened()
87 {
88 return _f != 0;
89 }
90
91 bool eof()
92 {
93 return feof(_f) ? true : false;
94 }
95
97 {
98 return _f;
99 }
100
101 static bool LoadIntoString ( std::string& s, const char* filename );
102 static bool SaveFromString ( const char* filename, const std::string& s, bool binary );
103
104private:
105 File(const File&) {}
106 const File& operator = ( const File& ) { return *this; }
107
109};
110
111#endif//FILE_H
@ lparam
Definition: SystemMenu.c:31
#define open
Definition: acwin.h:95
Definition: File.h:16
FILE * _f
Definition: File.h:108
bool next_line(std::string &line, bool strip_crlf)
Definition: File.cpp:47
static bool SaveFromString(const char *filename, const std::string &s, bool binary)
Definition: File.cpp:122
static bool LoadIntoString(std::string &s, const char *filename)
Definition: File.cpp:108
bool write(const void *data, unsigned len)
Definition: File.h:77
bool seek(long offset)
Definition: File.h:34
int get()
Definition: File.h:39
FILE * operator*()
Definition: File.h:96
bool eof()
Definition: File.h:91
size_t length()
Definition: File.cpp:88
void close()
Definition: File.cpp:99
bool read(void *data, unsigned len)
Definition: File.h:72
bool enum_lines(bool(*callback)(const std::string &line, int line_number, long lparam), long lparam, bool strip_crlf)
Definition: File.cpp:69
bool put(int c)
Definition: File.h:44
~File()
Definition: File.h:27
bool isopened()
Definition: File.h:86
File()
Definition: File.h:18
File(const char *filename, const char *mode)
Definition: File.h:22
const File & operator=(const File &)
Definition: File.h:106
File(const File &)
Definition: File.h:105
GLdouble s
Definition: gl.h:2039
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
const GLubyte * c
Definition: glext.h:8905
GLenum mode
Definition: glext.h:6217
const GLuint GLenum const GLvoid * binary
Definition: glext.h:7538
GLenum GLsizei len
Definition: glext.h:6722
GLintptr offset
Definition: glext.h:5920
_Check_return_opt_ _CRTIMP int __cdecl fgetc(_Inout_ FILE *_File)
#define EOF
Definition: stdio.h:24
_Check_return_ _CRTIMP int __cdecl feof(_In_ FILE *_File)
_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)
_Check_return_opt_ _CRTIMP int __cdecl fputc(_In_ int _Ch, _Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
_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)
const char * filename
Definition: ioapi.h:137
#define SEEK_SET
Definition: jmemansi.c:26
static IPrintDialogCallback callback
Definition: printdlg.c:326
#define getline
Definition: schily.h:567
static long line_number
Definition: main.cpp:17
#define true
Definition: stdbool.h:36
Definition: parser.c:49