file.h Source File - ClanLib SDK
Description: file.h Source File

file.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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#pragma once
30
31#include "iodevice.h"
32#include "../System/databuffer.h"
33
34namespace clan
35{
38
40 class File : public IODevice
41 {
42 public:
44 static std::string read_text(const std::string &filename);
45
47 static DataBuffer read_bytes(const std::string &filename);
48
50 static void write_text(const std::string &filename, const std::string &text, bool write_bom = false);
51
53 static void write_bytes(const std::string &filename, const DataBuffer &bytes);
54
56
57 enum AccessFlags
58 {
60 access_read = 1,
61
63 access_write = 2,
64
66 access_read_write = access_read | access_write
67 };
68
70 enum ShareFlags
71 {
73 share_read = 1,
74
76 share_write = 2,
77
79 share_delete = 4,
80
82 share_all = share_read + share_write + share_delete
83 };
84
86 enum OpenMode
87 {
89 open_always,
90
92 open_existing,
93
95 open_existing_truncate,
96
98 create_always,
99
101 create_new
102 };
103
105 enum Flags
106 {
107 flag_write_through = 1,
108 flag_no_buffering = 2,
109 flag_random_access = 4,
110 flag_sequential_scan = 8
111 };
112
114 File();
115
119 File(
120 const std::string &filename);
121
125 File(
126 const std::string &filename,
127 OpenMode mode,
128 unsigned int access,
129 unsigned int share = share_all,
130 unsigned int flags = 0);
131
132 ~File();
133
137 bool open(
138 const std::string &filename);
139
143 bool open(
144 const std::string &filename,
145 OpenMode mode,
146 unsigned int access,
147 unsigned int share = share_all,
148 unsigned int flags = 0);
149
151 void close();
152
153 private:
154 };
155
157}
clan::DataBuffer
General purpose data buffer.
Definition databuffer.h:42
clan::File
File I/O device.
Definition file.h:41
clan::File::read_text
static std::string read_text(const std::string &filename)
Loads an UTF-8 text file into a string.
clan::File::read_bytes
static DataBuffer read_bytes(const std::string &filename)
Loads an file into a byte buffer.
clan::File::Flags
Flags
Optimization Flags.
Definition file.h:106
clan::File::flag_random_access
@ flag_random_access
Definition file.h:109
clan::File::flag_no_buffering
@ flag_no_buffering
Definition file.h:108
clan::File::flag_write_through
@ flag_write_through
Definition file.h:107
clan::File::flag_sequential_scan
@ flag_sequential_scan
Definition file.h:110
clan::File::open
bool open(const std::string &filename, OpenMode mode, unsigned int access, unsigned int share=share_all, unsigned int flags=0)
Opens a file.
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::ShareFlags
ShareFlags
File sharing flags.
Definition file.h:71
clan::File::share_all
@ share_all
All other sharing flags combined.
Definition file.h:82
clan::File::share_write
@ share_write
Allow others to open the file for writing.
Definition file.h:76
clan::File::share_delete
@ share_delete
Allow others to delete the file.
Definition file.h:79
clan::File::share_read
@ share_read
Allow others to open the file for reading.
Definition file.h:73
clan::File::open
bool open(const std::string &filename)
Opens a file read only.
clan::File::File
File()
Constructs a file object.
clan::File::close
void close()
Close file.
clan::File::write_bytes
static void write_bytes(const std::string &filename, const DataBuffer &bytes)
Saves a byte buffer to file.
clan::File::~File
~File()
clan::File::AccessFlags
AccessFlags
Access flags.
Definition file.h:58
clan::File::access_write
@ access_write
Generic write access.
Definition file.h:63
clan::File::access_read_write
@ access_read_write
Generic read write access.
Definition file.h:66
clan::File::access_read
@ access_read
Generic read access.
Definition file.h:60
clan::File::OpenMode
OpenMode
File opening modes.
Definition file.h:87
clan::File::create_new
@ create_new
Create a new file. Fails if it already exists.
Definition file.h:101
clan::File::open_existing
@ open_existing
Open existing file. Fails if it does not exist.
Definition file.h:92
clan::File::open_existing_truncate
@ open_existing_truncate
Open existing file and truncate it.
Definition file.h:95
clan::File::create_always
@ create_always
Create file, even if it already exists.
Definition file.h:98
clan::File::open_always
@ open_always
Open file or create it if it does not exist.
Definition file.h:89
clan::File::File
File(const std::string &filename, OpenMode mode, unsigned int access, unsigned int share=share_all, unsigned int flags=0)
Constructs a file object.
clan::File::File
File(const std::string &filename)
Constructs a file object read only.
clan::IODevice
I/O Device interface.
Definition iodevice.h:50
clan
Definition clanapp.h:36