file.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28
29
30 #pragma once
31
32 #include "iodevice.h"
33 #include "../System/databuffer.h"
34
35 namespace clan
36 {
39
41 class File : public IODevice
42 {
45 public:
47 static std::string read_text(const std::string &filename);
48
50 static DataBuffer read_bytes(const std::string &filename);
51
53 static void write_text(const std::string &filename, const std::string &text, bool write_bom = false);
54
56 static void write_bytes(const std::string &filename, const DataBuffer &bytes);
58
61 public:
63
64 enum AccessFlags
65 {
67 access_read = 1,
68
70 access_write = 2,
71
73 access_read_write = access_read | access_write
74 };
75
77 enum ShareFlags
78 {
80 share_read = 1,
81
83 share_write = 2,
84
86 share_delete = 4,
87
89 share_all = share_read + share_write + share_delete
90 };
91
93 enum OpenMode
94 {
96 open_always,
97
99 open_existing,
100
102 open_existing_truncate,
103
105 create_always,
106
108 create_new
109 };
110
112 enum Flags
113 {
114 flag_write_through = 1,
115 flag_no_buffering = 2,
116 flag_random_access = 4,
117 flag_sequential_scan = 8
118 };
119
123
124 public:
126 File();
127
131 File(
132 const std::string &filename);
133
137 File(
138 const std::string &filename,
139 OpenMode mode,
140 unsigned int access,
141 unsigned int share = share_all,
142 unsigned int flags = 0);
143
144 ~File();
145
149
150 public:
151
155
156 public:
160 bool open(
161 const std::string &filename);
162
166 bool open(
167 const std::string &filename,
168 OpenMode mode,
169 unsigned int access,
170 unsigned int share = share_all,
171 unsigned int flags = 0);
172
174 void close();
175
179
180 private:
182 };
183
184 }
185
clan
Definition: clanapp.h:35
clan::File::access_write
Generic write access.
Definition: file.h:70
clan::File::open
bool open(const std::string &filename)
Opens a file read only.
clan::File::flag_sequential_scan
Definition: file.h:117
clan::IODevice
I/O Device interface.
Definition: iodevice.h:50
clan::File::access_read_write
Generic read write access.
Definition: file.h:73
clan::File::close
void close()
Close file.
clan::File::Flags
Flags
Optimization Flags.
Definition: file.h:112
clan::File::open_existing_truncate
Open existing file and truncate it.
Definition: file.h:102
clan::File::share_delete
Allow others to delete the file.
Definition: file.h:86
clan::File::ShareFlags
ShareFlags
File sharing flags.
Definition: file.h:77
clan::File::share_read
Allow others to open the file for reading.
Definition: file.h:80
clan::File::File
File()
Constructs a file object.
clan::StyleTokenType::string
@ keyword
clan::File::write_text
static void write_text(const std::string &filename, const std::string &text, bool write_bom=false)
Saves an UTF-8 text string to file.
clan::File
File I/O device.
Definition: file.h:41
clan::File::access_read
Generic read access.
Definition: file.h:67
clan::File::create_new
Create a new file. Fails if it already exists.
Definition: file.h:108
clan::File::open_existing
Open existing file. Fails if it does not exist.
Definition: file.h:99
clan::File::share_all
All other sharing flags combined.
Definition: file.h:89
clan::File::read_text
static std::string read_text(const std::string &filename)
Loads an UTF-8 text file into a string.
clan::File::flag_no_buffering
Definition: file.h:115
clan::File::share_write
Allow others to open the file for writing.
Definition: file.h:83
clan::File::flag_random_access
Definition: file.h:116
clan::File::open_always
Open file or create it if it does not exist.
Definition: file.h:96
clan::File::OpenMode
OpenMode
File opening modes.
Definition: file.h:93
clan::File::create_always
Create file, even if it already exists.
Definition: file.h:105
clan::File::read_bytes
static DataBuffer read_bytes(const std::string &filename)
Loads an file into a byte buffer.
clan::File::write_bytes
static void write_bytes(const std::string &filename, const DataBuffer &bytes)
Saves a byte buffer to file.
clan::DataBuffer
General purpose data buffer.
Definition: databuffer.h:42
clan::File::~File
~File()
clan::File::flag_write_through
Definition: file.h:114
clan::File::AccessFlags
AccessFlags
Access flags.
Definition: file.h:64