streamclone.cpp

00001 /*
00002  * libopenraw - streamclone.cpp
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
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of 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, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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             //no-op
00050             //FIXME determine what is the policy for opening clone 
00051             //streams
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 }

Generated on Sat Jan 27 11:36:13 2007 for libopenraw by  doxygen 1.4.7