streamclone.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "streamclone.h"
00025
00026
00027 namespace OpenRaw {
00028 namespace IO {
00029
00030 StreamClone::StreamClone(Stream *clone, off_t offset)
00031 : Stream(clone->get_path().c_str()),
00032 m_cloned(clone), m_offset(offset)
00033 {
00034
00035 }
00036
00037 StreamClone::~StreamClone()
00038 {
00039 }
00040
00041
00042 Stream::Error StreamClone::open()
00043 {
00044 if (m_cloned == NULL) {
00045 set_error(OR_ERROR_CLOSED_STREAM);
00046 return OR_ERROR_CLOSED_STREAM;
00047 }
00048 m_cloned->seek(m_offset, SEEK_SET);
00049
00050
00051
00052 return OR_ERROR_NONE;
00053 }
00054
00055 int StreamClone::close()
00056 {
00057 m_cloned = NULL;
00058 return 0;
00059 }
00060
00061
00062 int StreamClone::seek(off_t offset, int whence)
00063 {
00064 if (m_cloned == NULL) {
00065 set_error(OR_ERROR_CLOSED_STREAM);
00066 return -1;
00067 }
00068 if (whence == SEEK_SET) {
00069 offset += m_offset;
00070 }
00071 return m_cloned->seek(offset, whence);
00072 }
00073
00074
00075 int StreamClone::read(void *buf, size_t count)
00076 {
00077 if (m_cloned == NULL) {
00078 set_error(OR_ERROR_CLOSED_STREAM);
00079 return -1;
00080 }
00081 return m_cloned->read(buf, count);
00082 }
00083
00084
00085 off_t StreamClone::filesize()
00086 {
00087 if (m_cloned == NULL) {
00088 set_error(OR_ERROR_CLOSED_STREAM);
00089 return -1;
00090 }
00091 return m_cloned->filesize();
00092 }
00093
00094 }
00095 }