19 #define OIIO_FILESYSTEM_H
35 #if defined(_WIN32) && defined(__GLIBCXX__)
36 # define OIIO_FILESYSTEM_USE_STDIO_FILEBUF 1
43 #define OIIO_FILESYSTEM_SUPPORTS_IOPROXY 1
49 #if OIIO_FILESYSTEM_USE_STDIO_FILEBUF
54 typedef basic_ifstream<char>
ifstream;
55 typedef basic_ofstream<char>
ofstream;
66 namespace Filesystem {
75 bool include_dot=
true) noexcept;
100 #if OIIO_VERSION_GREATER_EQUAL(2, 4, 0)
102 std::vector<std::string> &dirs,
103 bool validonly =
false)
109 std::vector<std::string> &dirs,
110 bool validonly =
false);
124 const std::vector<std::string> &dirs,
126 bool recursive =
false);
136 std::vector<std::string> &filenames,
137 bool recursive =
false,
143 bool dot_is_absolute=
false);
172 return copy (from, to, err);
181 return rename (from, to, err);
189 return remove (
path, err);
225 std::ios_base::openmode
mode = std::ios_base::in);
230 std::ios_base::openmode
mode = std::ios_base::out);
258 out.write((
const char*)data.
data(), data.
size() *
sizeof(
T));
305 std::vector<int> &numbers);
317 int framepadding_override,
329 const std::vector<int> &numbers,
330 std::vector<std::string> &filenames);
341 const std::vector<int> &numbers,
342 const std::vector<string_view> &views,
343 std::vector<std::string> &filenames);
354 const std::vector<string_view> &views,
355 std::vector<int> &frame_numbers,
356 std::vector<string_view> &frame_views,
357 std::vector<std::string> &filenames);
366 std::vector<int> &numbers,
367 std::vector<std::string> &filenames);
377 bool simple_glob =
true);
386 enum Mode { Closed = 0, Read =
'r', Write =
'w' };
389 : m_filename(filename), m_mode(mode) {}
393 virtual const char* proxytype ()
const = 0;
396 virtual int64_t
tell () {
return m_pos; }
398 virtual size_t read (
void *
buf,
size_t size);
399 virtual size_t write (
const void *
buf,
size_t size);
402 virtual size_t pread (
void *
buf,
size_t size, int64_t
offset);
403 virtual size_t pwrite (
const void *
buf,
size_t size, int64_t
offset);
404 virtual size_t size ()
const {
return 0; }
410 return read (buf.
data(), buf.
size()*
sizeof(
T));
413 return write (buf.
data(), buf.
size()*
sizeof(
T));
416 return write (buf.
data(), buf.
size());
419 return seek ((origin ==
SEEK_SET ? offset : 0) +
420 (origin ==
SEEK_CUR ? offset+tell() : 0) +
424 #define OIIO_IOPROXY_HAS_ERROR 1
448 virtual const char*
proxytype()
const {
return "file"; }
449 virtual void close();
450 virtual bool seek(int64_t
offset);
451 virtual size_t read(
void*
buf,
size_t size);
452 virtual size_t write(
const void*
buf,
size_t size);
453 virtual size_t pread(
void*
buf,
size_t size, int64_t
offset);
454 virtual size_t pwrite(
const void*
buf,
size_t size, int64_t
offset);
455 virtual size_t size()
const;
456 virtual void flush()
const;
462 FILE* m_file =
nullptr;
464 bool m_auto_close =
false;
485 virtual const char*
proxytype()
const {
return "vecoutput"; }
486 virtual size_t write(
const void*
buf,
size_t size);
487 virtual size_t pwrite(
const void*
buf,
size_t size, int64_t
offset);
488 virtual size_t size()
const {
return m_buf.size(); }
491 std::vector<unsigned char>&
buffer()
const {
return m_buf; }
506 , m_buf((const unsigned char*)buf, size)
514 virtual const char*
proxytype()
const {
return "memreader"; }
520 virtual size_t read(
void*
buf,
size_t size);
521 virtual size_t pread(
void*
buf,
size_t size, int64_t
offset);
522 virtual size_t size()
const {
return m_buf.size(); }
OIIO_UTIL_API bool is_directory(string_view path) noexcept
OIIO_UTIL_API std::string filename_to_regex(string_view pattern, bool simple_glob=true)
IOProxy(const std::wstring &filename, Mode mode)
GLenum GLuint GLenum GLsizei const GLchar * buf
OIIO_NAMESPACE_BEGIN typedef std::ifstream ifstream
OIIO_UTIL_API std::time_t last_write_time(string_view path) noexcept
OIIO_UTIL_API bool parse_pattern(const char *pattern, int framepadding_override, std::string &normalized_pattern, std::string &framespec)
OIIO_UTIL_API std::string parent_path(string_view filepath) noexcept
GT_API const UT_StringHolder time
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
GLsizei const GLchar *const * string
const GLuint GLenum const void * binary
GLsizei const GLchar *const * path
IOProxy(string_view filename, Mode mode)
OIIO_UTIL_API unsigned long long remove_all(string_view path, std::string &err)
virtual void flush() const
virtual const char * proxytype() const
OIIO_UTIL_API bool enumerate_file_sequence(const std::string &pattern, const std::vector< int > &numbers, std::vector< std::string > &filenames)
OIIO_UTIL_API void convert_native_arguments(int argc, const char *argv[])
Ensure command line arguments are UTF-8 everywhere.
String-related utilities, all in namespace Strutil.
bool write_binary_file(string_view filename, cspan< T > data)
OIIO_UTIL_API std::string searchpath_find(const std::string &filename, const std::vector< std::string > &dirs, bool testcwd=true, bool recursive=false)
OIIO_UTIL_API bool get_directory_entries(const std::string &dirname, std::vector< std::string > &filenames, bool recursive=false, const std::string &filter_regex=std::string())
virtual const char * proxytype() const
constexpr const_pointer data() const noexcept
OIIO_UTIL_API std::vector< std::string > searchpath_split(string_view searchpath, bool validonly=false)
IOMemReader(void *buf, size_t size)
constexpr size_type size() const noexcept
OIIO_UTIL_API std::string replace_extension(const std::string &filepath, const std::string &new_extension) noexcept
size_t read(span< T > buf)
OIIO_UTIL_API FILE * fopen(string_view path, string_view mode)
Version of fopen that can handle UTF-8 paths even on Windows.
OIIO_UTIL_API uint64_t file_size(string_view path) noexcept
virtual bool seek(int64_t offset)
virtual size_t size() const
OIIO_UTIL_API bool scan_for_matching_filenames(const std::string &pattern, const std::vector< string_view > &views, std::vector< int > &frame_numbers, std::vector< string_view > &frame_views, std::vector< std::string > &filenames)
OIIO_UTIL_API bool write_text_file(string_view filename, string_view str)
OIIO_UTIL_API bool create_directory(string_view path, std::string &err)
virtual const char * proxytype() const
OIIO_UTIL_API std::string current_path()
OIIO_UTIL_API std::string temp_directory_path()
size_t write(string_view buf)
constexpr size_type size() const noexcept
OIIO_UTIL_API bool exists(string_view path) noexcept
IOFile(const std::wstring &filename, Mode mode)
const std::string & filename() const
bool seek(int64_t offset, int origin)
OIIO_UTIL_API std::string filename(string_view filepath) noexcept
virtual size_t size() const
IOProxy subclass for reading that wraps an cspan<char>.
OIIO_UTIL_API int fseek(FILE *file, int64_t offset, int whence)
Version of fseek that works with 64 bit offsets on all systems.
virtual size_t size() const
OIIO_UTIL_API bool path_is_absolute(string_view path, bool dot_is_absolute=false)
OIIO_UTIL_API std::string generic_filepath(string_view filepath) noexcept
Utilities for dealing with fstream on MingW. Basically accepting wchar_t* filenames in the std::ifstr...
OIIO_UTIL_API bool rename(string_view from, string_view to, std::string &err)
virtual bool opened() const
IOMemReader(cspan< unsigned char > buf)
std::vector< unsigned char > & m_buf
OIIO_UTIL_API int64_t ftell(FILE *file)
Version of ftell that works with 64 bit offsets on all systems.
virtual bool seek(int64_t offset)
size_t write(span< T > buf)
OIIO_UTIL_API std::string unique_path(string_view model="%%%%-%%%%-%%%%-%%%%")
OIIO_UTIL_API void open(OIIO::ifstream &stream, string_view path, std::ios_base::openmode mode=std::ios_base::in)
#define OIIO_NAMESPACE_END
OIIO_UTIL_API bool is_regular(string_view path) noexcept
OIIO_UTIL_API bool read_text_file(string_view filename, std::string &str)
std::string OIIO_UTIL_API utf16_to_utf8(const std::wstring &utf16str) noexcept
OIIO_UTIL_API bool enumerate_sequence(string_view desc, std::vector< int > &numbers)
cspan< unsigned char > m_buf
std::vector< unsigned char > & buffer() const
constexpr pointer data() const noexcept
cspan< unsigned char > buffer() const noexcept
OIIO_UTIL_API std::string extension(string_view filepath, bool include_dot=true) noexcept
std::vector< unsigned char > m_local_buf
#define OIIO_NAMESPACE_BEGIN
IOVecOutput(std::vector< unsigned char > &buf)
OIIO_UTIL_API size_t read_bytes(string_view path, void *buffer, size_t n, size_t pos=0)