MeshLib C++ Docs
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{
12
13
15MR_BIND_IGNORE MRMESH_API FILE * fopen( const std::filesystem::path & filename, const char * mode );
16
19{
20public:
21 File() = default;
22 File( const File & ) = delete;
23 File( File && r ) : handle_( r.handle_ ) { r.detach(); }
24 File( const std::filesystem::path & filename, const char * mode ) { open( filename, mode ); }
25 ~File() { close(); }
26
27 File& operator =( const File & ) = delete;
28 File& operator =( File && r ) { close(); handle_ = r.handle_; r.detach(); return * this; }
29
30 operator FILE *() const { return handle_; }
31
32 MRMESH_API FILE * open( const std::filesystem::path & filename, const char * mode );
33 MRMESH_API void close();
34
36 void detach() { handle_ = nullptr; }
38 void attach( FILE * h ) { if ( handle_ != h ) { close(); handle_ = h; } }
39
40private:
41 FILE * handle_ = nullptr;
42};
43
44}
the class to open C FILE handle and automatically close it in the destructor
Definition MRFile.h:19
void attach(FILE *h)
gives control over the handle to this object
Definition MRFile.h:38
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:36
~File()
Definition MRFile.h:25
MRMESH_API void close()
std::array< Vector3f, 3 > MR_BIND_IGNORE
Definition MRMeshBuilderTypes.h:13
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
File(const std::filesystem::path &filename, const char *mode)
Definition MRFile.h:24
File()=default
File(File &&r)
Definition MRFile.h:23
only for bindings generation
Definition MRCameraOrientationPlugin.h:8