minor improvements
This commit is contained in:
		@@ -282,21 +282,26 @@ namespace sc {
 | 
				
			|||||||
                byte_order _saved_byte_order {byte_order::undefined};
 | 
					                byte_order _saved_byte_order {byte_order::undefined};
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		class mapped_file : std::istream {
 | 
					        class mapped_file : public std::istream {
 | 
				
			||||||
            public:
 | 
					            public:
 | 
				
			||||||
				mapped_file() = default;
 | 
					                mapped_file();
 | 
				
			||||||
                mapped_file(const std::string& path);
 | 
					                mapped_file(const std::string& path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // no copying
 | 
				
			||||||
                mapped_file(const mapped_file&) = delete;
 | 
					                mapped_file(const mapped_file&) = delete;
 | 
				
			||||||
                mapped_file& operator=(const mapped_file&) = delete;
 | 
					                mapped_file& operator=(const mapped_file&) = delete;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // moving allowed
 | 
				
			||||||
                mapped_file(mapped_file&& other);
 | 
					                mapped_file(mapped_file&& other);
 | 
				
			||||||
                mapped_file& operator=(mapped_file&& other);
 | 
					                mapped_file& operator=(mapped_file&& other);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                ~mapped_file();
 | 
					                ~mapped_file();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // it's an error to open an already opened mapped_file
 | 
				
			||||||
                void open(const std::string& path);
 | 
					                void open(const std::string& path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // direct (read-only) access to mapped memory
 | 
				
			||||||
 | 
					                const char* mapping() const { return _mapping; }
 | 
				
			||||||
                size_t size() const { return _length; }
 | 
					                size_t size() const { return _length; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            private:
 | 
					            private:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,6 +18,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
using namespace sc::io;
 | 
					using namespace sc::io;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					mapped_file::mapped_file() : std::istream {&_membuf} {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mapped_file::mapped_file(const std::string& path) : std::istream {&_membuf} {
 | 
					mapped_file::mapped_file(const std::string& path) : std::istream {&_membuf} {
 | 
				
			||||||
    open(path);
 | 
					    open(path);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -47,12 +49,15 @@ mapped_file::mapped_file(mapped_file&& other) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mapped_file& mapped_file::operator=(mapped_file &&other) {
 | 
					mapped_file& mapped_file::operator=(mapped_file &&other) {
 | 
				
			||||||
 | 
					    if (&other != this) {
 | 
				
			||||||
        mapped_file mf {std::move(other)};
 | 
					        mapped_file mf {std::move(other)};
 | 
				
			||||||
        std::swap(mf, *this);
 | 
					        std::swap(mf, *this);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    return *this;
 | 
					    return *this;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void mapped_file::open(const std::string& path) {
 | 
					void mapped_file::open(const std::string& path) {
 | 
				
			||||||
 | 
					    if (_fd != -1) throw std::runtime_error("already open");
 | 
				
			||||||
    _fd = ::open(path.c_str(), O_RDONLY);
 | 
					    _fd = ::open(path.c_str(), O_RDONLY);
 | 
				
			||||||
    throw_if_min1_msg(_fd, "could not open file");
 | 
					    throw_if_min1_msg(_fd, "could not open file");
 | 
				
			||||||
    struct stat st;
 | 
					    struct stat st;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user