From: Christian P. <cp...@us...> - 2005-01-30 17:17:09
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv513/src/System Added Files: StorageDevice.common.cpp Log Message: Added StorageDevice. --- NEW FILE: StorageDevice.common.cpp --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/System/StorageDevice.h" #include "IOHandle.h" namespace P { namespace System { StorageDevice::StorageDevice() throw() : _handle(0) { } StorageDevice::StorageDevice(const std::string& path, AccessMode access, ShareMode share) throw(IO::IOError) : _handle(0) { open(path,access,share); } StorageDevice::~StorageDevice() throw() { if(valid()) { try { close(); } catch(...) { } } } void StorageDevice::open(const std::string& str, AccessMode access, ShareMode share) throw(IO::IOError) { if(valid()) close(); _handle = (unsigned long)new IOHandle(str, access, IO::IODevice::OpenFail, share); } void StorageDevice::_close() throw(IO::IOError) { delete (IOHandle*)_handle; _handle = 0; } size_t StorageDevice::_read(char* buffer, size_t count) throw(IO::IOError) { return ((IOHandle*)_handle)->read(buffer, count); } size_t StorageDevice::_peek(char* buffer, size_t count) throw(IO::IOError) { return ((IOHandle*)_handle)->peek(buffer, count); } size_t StorageDevice::_write(const char* buffer, size_t count) throw(IO::IOError) { return ((IOHandle*)_handle)->write(buffer, count); } offset_t StorageDevice::_seek(offset_t offset, SeekMode mode) throw(IO::IOError) { return ((IOHandle*)_handle)->seek(offset, mode); } bool StorageDevice::_isSeekable() const throw() { return ((IOHandle*)_handle)->isSeekable(); } void StorageDevice::_sync() const throw(IO::IOError) { ((IOHandle*)_handle)->sync(); } offset_t StorageDevice::_size() const throw(IO::IOError) { return ((IOHandle*)_handle)->size(); } unsigned long StorageDevice::handle() const throw() { return ((IOHandle*)_handle)->handle(); } } // !namespace System } // !namespace P |