system.hh
Go to the documentation of this file.
00001 #ifndef UTILMM_SYSTEM_HH
00002 #define UTILMM_SYSTEM_HH
00003 
00004 #include <boost/noncopyable.hpp>
00005 #include <boost/filesystem/path.hpp>
00006 
00007 namespace utilmm
00008 {
00014     class unix_error : public std::exception
00015     {
00016         char m_desc[512];
00017         void init_description(std::string const& desc);
00018 
00019     public:
00020         explicit unix_error(std::string const& desc, int error);
00021         explicit unix_error(std::string const& desc);
00022         explicit unix_error(int error);
00023         explicit unix_error();
00024         ~unix_error() throw ();
00025         
00026         int error() const;
00027         char const* what() const throw();
00028 
00029     private:
00030         int m_error;
00031     };
00032     
00039     class auto_close : boost::noncopyable
00040     {
00041     public:
00042         auto_close();
00043         explicit auto_close(int fileno);
00044         explicit auto_close(FILE* stream);
00045         ~auto_close();
00046         
00053         template<typename T> T handle()  const;
00054             
00056         void  close();
00057 
00062         void  reset(int fd);
00063 
00068         void  reset(FILE* stream);
00069 
00073         void  detach();
00074 
00075     private:
00076         int m_fileno;
00077         FILE* m_stream;
00078     };
00079     template<> 
00080         FILE* auto_close::handle<FILE*>() const;
00081     template<> 
00082         int   auto_close::handle<int>()   const;
00083 
00089     class tempfile : boost::noncopyable
00090     {
00091         boost::filesystem::path m_path;
00092         auto_close              m_guard;
00093         
00094     public:
00101         tempfile();
00102 
00104         ~tempfile();
00105 
00112         tempfile(std::string const& basename);
00113 
00120         FILE* detach();
00121 
00126         static FILE* mkstemp(std::string const& base, boost::filesystem::path& path);
00127 
00133         boost::filesystem::path path() const;
00134 
00136         FILE* handle() const;
00137         
00142         static FILE* create();
00143     };
00144 }
00145 
00146 #endif
00147 


utilmm
Author(s): Sylvain Joyeux/sylvain.joyeux@m4x.org
autogenerated on Thu Jan 2 2014 11:38:31