Util--  1.1
system.hh
Go to the documentation of this file.
1 #ifndef UTILMM_SYSTEM_HH
2 #define UTILMM_SYSTEM_HH
3 
4 #include <boost/noncopyable.hpp>
5 #include <boost/filesystem/path.hpp>
6 
7 namespace utilmm
8 {
14  class unix_error : public std::exception
15  {
16  char m_desc[512];
17  void init_description(std::string const& desc);
18 
19  public:
20  explicit unix_error(std::string const& desc, int error);
21  explicit unix_error(std::string const& desc);
22  explicit unix_error(int error);
23  explicit unix_error();
24  ~unix_error() throw ();
25 
26  int error() const;
27  char const* what() const throw();
28 
29  private:
30  int m_error;
31  };
32 
39  class auto_close : boost::noncopyable
40  {
41  public:
42  auto_close();
43  explicit auto_close(int fileno);
44  explicit auto_close(FILE* stream);
45  ~auto_close();
46 
53  template<typename T> T handle() const;
54 
56  void close();
57 
62  void reset(int fd);
63 
68  void reset(FILE* stream);
69 
73  void detach();
74 
75  private:
76  int m_fileno;
77  FILE* m_stream;
78  };
79  template<>
80  FILE* auto_close::handle<FILE*>() const;
81  template<>
82  int auto_close::handle<int>() const;
83 
89  class tempfile : boost::noncopyable
90  {
91  boost::filesystem::path m_path;
92  auto_close m_guard;
93 
94  public:
101  tempfile();
102 
104  ~tempfile();
105 
112  tempfile(std::string const& basename);
113 
120  FILE* detach();
121 
126  static FILE* mkstemp(std::string const& base, boost::filesystem::path& path);
127 
133  boost::filesystem::path path() const;
134 
136  FILE* handle() const;
137 
142  static FILE* create();
143  };
144 }
145 
146 #endif
147 
Definition: system.hh:39
char const * what() const
Definition: system.hh:14
Definition: auto_flag.hh:6
int error() const
Definition: system.hh:89

Generated on Mon Oct 8 2018 08:38:45 for Util-- by doxygen 1.8.11
SourceForge.net Project Page