MeshLib Documentation
Loading...
Searching...
No Matches
MRFile.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include "MRPch/MRBindingMacros.h"
5#include <filesystem>
6#include <cstdio>
7
8namespace MR
9{
10
12MR_BIND_IGNORE MRMESH_API FILE * fopen( const std::filesystem::path & filename, const char * mode );
13
15class MR_BIND_IGNORE File
16{
17public:
18 File() = default;
19 File( const File & ) = delete;
20 File( File && r ) : handle_( r.handle_ ) { r.detach(); }
21 File( const std::filesystem::path & filename, const char * mode ) { open( filename, mode ); }
22 ~File() { close(); }
23
24 File& operator =( const File & ) = delete;
25 File& operator =( File && r ) { close(); handle_ = r.handle_; r.detach(); return * this; }
26
27 operator FILE *() const { return handle_; }
28
29 MRMESH_API FILE * open( const std::filesystem::path & filename, const char * mode );
31
33 void detach() { handle_ = nullptr; }
35 void attach( FILE * h ) { if ( handle_ != h ) { close(); handle_ = h; } }
36
37private:
38 FILE * handle_ = nullptr;
39};
40
41} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
the class to open C FILE handle and automatically close it in the destructor
Definition MRFile.h:16
void attach(FILE *h)
gives control over the handle to this object
Definition MRFile.h:35
MRMESH_API FILE * open(const std::filesystem::path &filename, const char *mode)
File(const File &)=delete
void detach()
the user takes control over the handle
Definition MRFile.h:33
~File()
Definition MRFile.h:22
MRMESH_API void close()
File(const std::filesystem::path &filename, const char *mode)
Definition MRFile.h:21
File()=default
File(File &&r)
Definition MRFile.h:20
Definition MRCameraOrientationPlugin.h:8
MR_BIND_IGNORE MRMESH_API FILE * fopen(const std::filesystem::path &filename, const char *mode)
this version of fopen unlike std::fopen supports unicode file names on Windows