libopenraw
|
00001 /* 00002 * libopenraw - stream.h 00003 * 00004 * Copyright (C) 2006 Hubert Figuière 00005 * 00006 * This library is free software: you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public License 00008 * as published by the Free Software Foundation, either version 3 of 00009 * the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library. If not, see 00018 * <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 00022 #ifndef __IO_STREAM_H__ 00023 #define __IO_STREAM_H__ 00024 00025 #include <sys/types.h> 00026 #include <unistd.h> 00027 00028 #include <string> 00029 00030 #include <libopenraw/libopenraw.h> 00031 00032 #include "exception.h" 00033 00034 namespace OpenRaw { 00035 namespace IO { 00036 00040 class Stream 00041 { 00042 public: 00046 Stream(const char *filename); 00047 virtual ~Stream(); 00048 00052 typedef ::or_error Error; 00053 00054 // file APIs 00056 virtual Error open() = 0; 00058 virtual int close() = 0; 00060 virtual int seek(off_t offset, int whence) = 0; 00062 virtual int read(void *buf, size_t count) = 0; 00063 virtual off_t filesize() = 0; 00064 // virtual void *mmap(size_t l, off_t offset) = 0; 00065 // virtual int munmap(void *addr, size_t l) = 0; 00066 00067 Error get_error() 00068 { 00069 return m_error; 00070 } 00071 00073 const std::string &get_path() const 00074 { 00075 return m_fileName; 00076 } 00077 00078 uint8_t readByte() throw(Internals::IOException); 00079 protected: 00080 void set_error(Error error) 00081 { 00082 m_error = error; 00083 } 00084 00085 private: 00087 Stream(const Stream& f); 00089 Stream & operator=(const Stream&); 00090 00092 std::string m_fileName; 00093 Error m_error; 00094 }; 00095 00096 } 00097 } 00098 00099 00100 #endif