use tr1 smart_ptr.

git-svn-id: https://profuse.googlecode.com/svn/branches/profuse_interim@341 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
ksherlock 2011-02-20 23:05:09 +00:00
parent 1fd924ae1b
commit 4cdfc52c04
17 changed files with 62 additions and 35 deletions

View File

@ -23,16 +23,15 @@ using ProFUSE::Exception;
using ProFUSE::POSIXException;
BlockCache::BlockCache(BlockDevice *device)
BlockCache::BlockCache(BlockDevicePointer device) :
_device(device)
{
_device = device;
_blocks = device->blocks();
_readOnly = device->readOnly();
}
BlockCache::~BlockCache()
{
delete _device;
}
void BlockCache::write(unsigned block, const void *bp)
@ -50,11 +49,11 @@ void BlockCache::read(unsigned block, void *bp)
}
BlockCache *BlockCache::Create(BlockDevice *device)
BlockCachePointer BlockCache::Create(BlockDevicePointer device)
{
if (!device) return NULL;
if (!device.get()) return BlockCachePointer();
return device->createBlockCache();
return device->createBlockCache(device);
}

View File

@ -3,12 +3,13 @@
#include <stdint.h>
#include <vector>
#include <Device/Device.h>
class MappedFile;
namespace Device {
class BlockDevice;
enum BlockReleaseFlags {
kBlockDirty = 1,
@ -19,13 +20,13 @@ enum BlockReleaseFlags {
class BlockCache {
public:
static BlockCache *Create(BlockDevice *device);
static BlockCachePointer Create(BlockDevicePointer device);
virtual ~BlockCache();
bool readOnly() { return _readOnly; }
unsigned blocks() { return _blocks; }
BlockDevice *device() { return _device; }
BlockDevicePointer device() { return _device; }
virtual void sync() = 0;
@ -46,16 +47,16 @@ public:
}
protected:
BlockCache(BlockDevice *device);
BlockCache(BlockDevicePointer device);
BlockDevice *_device;
BlockDevicePointer _device;
private:
unsigned _blocks;
bool _readOnly;
};
} // namespace
#endif

View File

@ -59,7 +59,7 @@ using ProFUSE::POSIXException;
ConcreteBlockCache::ConcreteBlockCache(BlockDevice *device, unsigned size) :
ConcreteBlockCache::ConcreteBlockCache(BlockDevicePointer device, unsigned size) :
BlockCache(device)
{
if (size < 16) size = 16;

View File

@ -9,7 +9,7 @@ namespace Device {
class ConcreteBlockCache : public BlockCache {
public:
ConcreteBlockCache(BlockDevice *device, unsigned size = 16);
ConcreteBlockCache(BlockDevicePointer device, unsigned size = 16);
virtual ~ConcreteBlockCache();
virtual void sync();

View File

@ -20,7 +20,7 @@ using ProFUSE::Exception;
using ProFUSE::POSIXException;
MappedBlockCache::MappedBlockCache(BlockDevice *device, void *data) :
MappedBlockCache::MappedBlockCache(BlockDevicePointer device, void *data) :
BlockCache(device)
{
_data = (uint8_t *)data;

View File

@ -8,7 +8,7 @@ namespace Device {
class MappedBlockCache : public BlockCache {
public:
MappedBlockCache(BlockDevice *, void *data);
MappedBlockCache(BlockDevicePointer device, void *data);
virtual ~MappedBlockCache();
virtual void sync();

View File

@ -233,9 +233,9 @@ void BlockDevice::sync(TrackSector ts)
}
*/
BlockCache *BlockDevice::createBlockCache()
BlockCachePointer BlockDevice::createBlockCache(BlockDevicePointer device)
{
unsigned b = blocks();
unsigned size = std::max(16u, b / 16);
return new ConcreteBlockCache(this, size);
return BlockCachePointer(new ConcreteBlockCache(device, size));
}

View File

@ -4,11 +4,11 @@
#include <stdint.h>
#include <sys/types.h>
#include <ProFUSE/Exception.h>
#include <Device/Device.h>
#include <Device/TrackSector.h>
#include <Cache/BlockCache.h>
#include <ProFUSE/Exception.h>
#include <File/File.h>
@ -30,7 +30,7 @@ public:
virtual ~BlockDevice();
virtual BlockCache *createBlockCache();
virtual BlockCachePointer createBlockCache(BlockDevicePointer device);
virtual void read(unsigned block, void *bp) = 0;

View File

@ -158,8 +158,9 @@ DavexDiskImage *DavexDiskImage::Create(const char *name, size_t blocks, const ch
}
BlockCache *DavexDiskImage::createBlockCache()
BlockCachePointer DavexDiskImage::createBlockCache(BlockDevicePointer device)
{
return new MappedBlockCache(this, 512 + (uint8_t *)address());
// need a smart pointer, but only have this....
return BlockCachePointer(new MappedBlockCache(device, 512 + (uint8_t *)address()));
}

View File

@ -20,7 +20,7 @@ public:
static DavexDiskImage *Create(const char *name, size_t blocks, const char *vname);
static DavexDiskImage *Open(MappedFile *);
virtual BlockCache *createBlockCache();
virtual BlockCachePointer createBlockCache(BlockDevicePointer device);
private:

26
Device/Device.h Normal file
View File

@ -0,0 +1,26 @@
//
// Device.h
// profuse
//
// Created by Kelvin Sherlock on 2/19/2011.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#ifndef __DEVICE_DEVICE_H__
#define __DEVICE_DEVICE_H__
#include <tr1/memory>
namespace Device {
class BlockDevice;
class BlockCache;
typedef std::tr1::shared_ptr<BlockDevice> BlockDevicePointer;
typedef std::tr1::shared_ptr<BlockCache> BlockCachePointer;
}
#endif

View File

@ -218,11 +218,11 @@ void DiskCopy42Image::write(unsigned block, const void *bp)
}
BlockCache *DiskCopy42Image::createBlockCache()
BlockCachePointer DiskCopy42Image::createBlockCache(BlockDevicePointer device)
{
// if not readonly, mark changed so crc will be updated at close.
if (!readOnly()) _changed = true;
return new MappedBlockCache(this, address());
return BlockCachePointer(new MappedBlockCache(device, address()));
}

View File

@ -22,7 +22,7 @@ public:
virtual void write(unsigned block, const void *bp);
virtual BlockCache *createBlockCache();
virtual BlockCachePointer createBlockCache(BlockDevicePointer device);
private:

View File

@ -138,9 +138,9 @@ void ProDOSOrderDiskImage::Validate(MappedFile *f)
}
BlockCache *ProDOSOrderDiskImage::createBlockCache()
BlockCachePointer ProDOSOrderDiskImage::createBlockCache(BlockDevicePointer device)
{
return new MappedBlockCache(this, address());
return BlockCachePointer(new MappedBlockCache(device, address()));
}
#pragma mark -

View File

@ -61,7 +61,7 @@ public:
static ProDOSOrderDiskImage *Open(MappedFile *);
virtual BlockCache *createBlockCache();
virtual BlockCachePointer createBlockCache(BlockDevicePointer device);
private:
ProDOSOrderDiskImage();

View File

@ -141,14 +141,14 @@ bool UniversalDiskImage::readOnly()
}
BlockCache *UniversalDiskImage::createBlockCache()
BlockCachePointer UniversalDiskImage::createBlockCache(BlockDevicePointer device)
{
if (_format == 1)
{
return new MappedBlockCache(this, _dataOffset + (uint8_t *)address());
return BlockCachePointer(new MappedBlockCache(device, _dataOffset + (uint8_t *)address()));
}
return DiskImage::createBlockCache();
return DiskImage::createBlockCache(device);
}

View File

@ -19,7 +19,7 @@ public:
virtual bool readOnly();
virtual BlockCache *createBlockCache();
virtual BlockCachePointer createBlockCache(BlockDevicePointer device);
private: