libdcp
file.h
1 /*
2  Copyright (C) 2022 Carl Hetherington <cth@carlh.net>
3 
4  This file is part of libdcp.
5 
6  libdcp is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  libdcp is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with libdcp. If not, see <http://www.gnu.org/licenses/>.
18 
19  In addition, as a special exception, the copyright holders give
20  permission to link the code of portions of this program with the
21  OpenSSL library under certain conditions as described in each
22  individual source file, and distribute linked combinations
23  including the two.
24 
25  You must obey the GNU General Public License in all respects
26  for all of the code used other than OpenSSL. If you modify
27  file(s) with this exception, you may extend this exception to your
28  version of the file(s), but you are not obligated to do so. If you
29  do not wish to do so, delete this exception statement from your
30  version. If you delete this exception statement from all source
31  files in the program, then also delete it here.
32 */
33 
34 
35 #ifndef LIBDCP_FILE_H
36 #define LIBDCP_FILE_H
37 
38 
39 #include <boost/filesystem/path.hpp>
40 
41 
42 namespace dcp {
43 
44 
48 class File
49 {
50 public:
54  File(boost::filesystem::path, std::string mode);
55 
56  File(File&& other);
57  File& operator=(File&& other);
58 
59  ~File();
60 
61  File(File const&) = delete;
62  File& operator=(File const&) = delete;
63 
64  operator bool() const;
65 
67  size_t write(const void *ptr, size_t size, size_t nmemb);
69  size_t read(void *ptr, size_t size, size_t nmemb);
71  int eof();
73  char *gets(char *s, int size);
75  int puts(char const *s);
77  int seek(int64_t offset, int whence);
79  int64_t tell();
81  int error();
82 
83  void checked_write(void const * ptr, size_t size);
84  void checked_read(void* ptr, size_t size);
85 
89  void close();
90 
91  boost::filesystem::path path() const {
92  return _path;
93  }
94 
98  FILE* take();
99 
100  FILE* get() {
101  return _file;
102  }
103 
107  int open_error() const {
108  return _open_error;
109  }
110 
111 private:
112  boost::filesystem::path _path;
113  FILE* _file = nullptr;
114  int _open_error = 0;
115 };
116 
117 
118 }
119 
120 
121 #endif
Definition: file.h:49
int eof()
Definition: file.cc:122
int64_t tell()
Definition: file.cc:201
File(boost::filesystem::path, std::string mode)
Definition: file.cc:53
char * gets(char *s, int size)
Definition: file.cc:130
void close()
Definition: file.cc:96
int puts(char const *s)
Definition: file.cc:138
FILE * take()
Definition: file.cc:180
size_t write(const void *ptr, size_t size, size_t nmemb)
Definition: file.cc:106
size_t read(void *ptr, size_t size, size_t nmemb)
Definition: file.cc:114
int open_error() const
Definition: file.h:107
int error()
Definition: file.cc:214
int seek(int64_t offset, int whence)
Definition: file.cc:189
Namespace for everything in libdcp.
Definition: array_data.h:50