CUBRID Engine  latest
filesys.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * filesys.hpp: File System namespace & functionality
21  */
22 #ifndef _FILESYS_H_
23 #define _FILESYS_H_
24 
25 #include <stdio.h>
26 #include <memory>
27 #ifdef LINUX
28 #include <unistd.h>
29 #elif WINDOWS
30 #include <io.h>
31 #endif
32 
33 namespace filesys //File System
34 {
35  struct file_closer //predicate|operator used as custom deleter in std::unique_ptr
36  {
37  void operator() (FILE *fp) const
38  {
39  fclose (fp);
40  }
41  };
42 
43  using auto_close_file = std::unique_ptr<FILE, file_closer>;//normal unique_ptr with a custom deleter
44 
45 
46  struct file_deleter //predicate|operator used as custom deleter in std::unique_ptr
47  {
48  void operator() (const char *filename) const
49  {
50 #ifdef LINUX
51  unlink (filename);
52 #elif WINDOWS
53  _unlink (filename);
54 #endif
55  }
56  };
57 
58  using auto_delete_file = std::unique_ptr<const char, file_deleter>;//normal unique_ptr with a custom deleter
59 }
60 
61 #endif //_FILESYS_H_
void operator()(FILE *fp) const
Definition: filesys.hpp:37
std::unique_ptr< FILE, file_closer > auto_close_file
Definition: filesys.hpp:43
std::unique_ptr< const char, file_deleter > auto_delete_file
Definition: filesys.hpp:58