1 #ifndef CFILE_DEVICE_BASE_HPP_INCLUDED 2 #define CFILE_DEVICE_BASE_HPP_INCLUDED 10 #include <mds_utils/file_utils/detail/cfile_stream_fwd.hpp> 12 #include <boost/iostreams/categories.hpp> 13 #include <boost/iostreams/traits.hpp> 14 #include <boost/iostreams/positioning.hpp> 15 #include <boost/type_traits/is_same.hpp> 16 #include <boost/mpl/if.hpp> 17 #include <boost/mpl/not.hpp> 22 namespace mds_utils {
namespace file_utils {
28 template<
class Derived>
29 class cFile_Device_base {
37 typedef char char_type;
38 struct category :
virtual boost::iostreams::device_tag,
39 virtual boost::mpl::if_<
40 boost::is_same<Derived,cFile_Sink>,
41 boost::iostreams::output_seekable,
42 typename boost::mpl::if_<
43 boost::is_same<Derived,cFile_Source>,
44 boost::iostreams::input_seekable,
45 boost::iostreams::seekable
48 virtual boost::mpl::if_<boost::mpl::not_<
49 boost::is_same<Derived,cFile_Source> >,
50 boost::iostreams::flushable_tag,
51 boost::iostreams::any_tag
54 cFile_Device_base() {}
55 cFile_Device_base(FILE *ptr) : file_ptr(ptr) {}
57 void set_FILEp(FILE *ptr) { file_ptr = ptr; }
59 boost::iostreams::stream_offset
60 seek(boost::iostreams::stream_offset off,std::ios_base::seekdir way) {
62 using namespace boost::iostreams;
78 throw ios_base::failure(
"Bad seek direction (cFile_Device_base::seek)");
82 fseeko(file_ptr,off,whence);
83 next = ftello(file_ptr);
85 fseek(file_ptr,off,whence);
86 next = ftell(file_ptr);
96 std::streamsize read(char_type *s,std::streamsize n) { \ 97 if (feof(file_ptr)) return -1; \ 98 return fread(reinterpret_cast<void*>(s),sizeof(char),n,file_ptr); \ 102 std::streamsize write(const char_type *s,std::streamsize n) { \ 103 return fwrite(reinterpret_cast<const void*>(s),sizeof(char),n,file_ptr); \ 107 bool flush() { return (fflush(file_ptr) == 0); }
Main namespace of all Michele De Stefano's C++ utilities.