file.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 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 "../api_core.h"
33 #include "iodevice.h"
34 #include "../System/databuffer.h"
35 
36 namespace clan
37 {
40 
42 class CL_API_CORE File : public IODevice
43 {
46 public:
48  static std::string read_text(const std::string &filename);
49 
51  static DataBuffer read_bytes(const std::string &filename);
52 
54  static void write_text(const std::string &filename, const std::string &text, bool write_bom = false);
55 
57  static void write_bytes(const std::string &filename, const DataBuffer &bytes);
59 
62 public:
64 
66  {
68  access_read = 1,
69 
71  access_write = 2,
72 
74  access_read_write = access_read | access_write
75  };
76 
79  {
81  share_read = 1,
82 
84  share_write = 2,
85 
87  share_delete = 4,
88 
90  share_all = share_read + share_write + share_delete
91  };
92 
94  enum OpenMode
95  {
98 
101 
104 
107 
109  create_new
110  };
111 
113  enum Flags
114  {
115  flag_write_through = 1,
116  flag_no_buffering = 2,
117  flag_random_access = 4,
118  flag_sequential_scan = 8
119  };
120 
124 
125 public:
127  File();
128 
132  File(
133  const std::string &filename);
134 
138  File(
139  const std::string &filename,
140  OpenMode mode,
141  unsigned int access,
142  unsigned int share = share_all,
143  unsigned int flags = 0);
144 
145  ~File();
146 
150 
151 public:
152 
156 
157 public:
161  bool open(
162  const std::string &filename);
163 
167  bool open(
168  const std::string &filename,
169  OpenMode mode,
170  unsigned int access,
171  unsigned int share = share_all,
172  unsigned int flags = 0);
173 
175  void close();
176 
180 
181 private:
183 };
184 
185 }
186 
I/O Device interface.
Definition: iodevice.h:51
Flags
Optimization Flags.
Definition: file.h:113
Open existing file and truncate it.
Definition: file.h:103
ShareFlags
File sharing flags.
Definition: file.h:78
Definition: buffer_usage.h:59
File I/O device.
Definition: file.h:42
Open existing file. Fails if it does not exist.
Definition: file.h:100
Open file or create it if it does not exist.
Definition: file.h:97
OpenMode
File opening modes.
Definition: file.h:94
Create file, even if it already exists.
Definition: file.h:106
General purpose data buffer.
Definition: databuffer.h:43
AccessFlags
Access flags.
Definition: file.h:65