forked from ravinet/mahimahi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp_file.hh
53 lines (37 loc) · 1.11 KB
/
temp_file.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* -*-mode:c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#ifndef TEMP_FILE_HH
#define TEMP_FILE_HH
#include <string>
#include <vector>
#include "file_descriptor.hh"
class UniqueFile
{
private:
std::vector<char> mutable_temp_filename_;
FileDescriptor fd_;
protected:
bool moved_away_;
public:
UniqueFile( const std::string & filename_template );
virtual ~UniqueFile() {}
std::string name( void ) const;
void write( const std::string & contents );
FileDescriptor & fd( void ) { return fd_; }
/* ban copying */
UniqueFile( const UniqueFile & other ) = delete;
UniqueFile & operator=( const UniqueFile & other ) = delete;
/* allow move constructor */
UniqueFile( UniqueFile && other );
/* ... but not move assignment operator */
UniqueFile & operator=( UniqueFile && other ) = delete;
};
/* TempFile is deleted when object destroyed */
class TempFile : public UniqueFile
{
public:
using UniqueFile::UniqueFile;
/* allow move constructor */
TempFile( TempFile && other ) : UniqueFile( std::move( other ) ) {}
~TempFile();
};
#endif