class tmpfstreamTempl : public bio::stream<Device, Tr, Alloc>
{
private:
- std::string filename;
+ std::string tmpfilename;
bool unlinked;
public:
int buffer_size = -1 , int pback_size = -1);
std::string get_tmp_filename()
- { return filename; }
+ { return tmpfilename; }
bool set_file_mode(int mode);
bool move(const std::string& targetpath, bool overwrite=false);
};
+template< typename Device,
+ typename Tr =
+ BOOST_IOSTREAMS_CHAR_TRAITS(
+ BOOST_DEDUCED_TYPENAME bio::char_type_of<Device>::type
+ ),
+ typename Alloc =
+ std::allocator<
+ BOOST_DEDUCED_TYPENAME bio::char_type_of<Device>::type
+ > >
+class tmpfcopystreamTempl : public tmpfstreamTempl<Device, Tr, Alloc>
+{
+private:
+ std::string originalfilename;
+ bool full_sync;
+
+public:
+ static const std::string default_template_suffix;
+
+ tmpfcopystreamTempl()
+ : tmpfstreamTempl<Device, Tr, Alloc>()
+ { }
+
+ tmpfcopystreamTempl(const std::string& filename,
+ std::ios_base::open_mode mode = std::ios_base::out,
+ int buffer_size = -1 , int pback_size = -1)
+ : originalfilename(filename),
+ tmpfstreamTempl<Device, Tr, Alloc>
+ (filename+default_template_suffix,mode,buffer_size,pback_size)
+ { }
+
+ tmpfcopystreamTempl(const std::string& filename,
+ const std::string& tmpnametemplate,
+ std::ios_base::open_mode mode = std::ios_base::out,
+ int buffer_size = -1 , int pback_size = -1)
+ : originalfilename(filename),
+ tmpfstreamTempl<Device, Tr, Alloc>
+ (tmpnametemplate,mode,buffer_size,pback_size)
+ { }
+
+ bool open(const std::string& filename,
+ std::ios_base::open_mode mode = std::ios_base::out,
+ int buffer_size = -1 , int pback_size = -1)
+ {
+ originalfilename=filename;
+ return tmpfstreamTempl<Device, Tr, Alloc>
+ ::open(filename+default_template_suffix,mode,buffer_size,pback_size);
+ }
+
+ bool open(const std::string& filename,
+ const std::string& tmpnametemplate,
+ std::ios_base::open_mode mode = std::ios_base::out,
+ int buffer_size = -1 , int pback_size = -1)
+ {
+ originalfilename=filename;
+ return tmpfstreamTempl<Device, Tr, Alloc>
+ ::open(tmpnametemplate,mode,buffer_size,pback_size);
+ }
+
+ std::string get_original_filename()
+ { return originalfilename; }
+
+ void set_full_sync(bool do_full_sync=true)
+ { full_sync=do_full_sync; }
+
+ bool get_full_sync()
+ { return full_sync; }
+
+ void close();
+
+private:
+
+ // forbid users to call these functions, no need to disturbe the internals here
+ bool unlink()
+ { return tmpfcopystreamTempl<Device, Tr, Alloc>::unlink(); }
+
+ bool move(const std::string& targetpath, bool overwrite=false)
+ { return tmpfcopystreamTempl<Device, Tr, Alloc>::move(targetpath,overwrite); }
+};
+
typedef tmpfstreamTempl<bio::file_descriptor_sink> tmpofstream;
typedef tmpfstreamTempl<bio::file_descriptor> tmpfstream;
+typedef tmpfcopystreamTempl<bio::file_descriptor_sink> tmpofcopystream;
+typedef tmpfcopystreamTempl<bio::file_descriptor> tmpfcopystream;
+
}
#endif