mirror of
https://github.com/ksherlock/profuse.git
synced 2024-12-22 20:29:59 +00:00
use smart macros to make the future easier
git-svn-id: https://profuse.googlecode.com/svn/branches/v2@351 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
parent
89e80dcc10
commit
9746117f71
@ -51,7 +51,8 @@ void BlockCache::read(unsigned block, void *bp)
|
||||
|
||||
BlockCachePointer BlockCache::Create(BlockDevicePointer device)
|
||||
{
|
||||
if (!device.get()) return BlockCachePointer();
|
||||
// this just calls the device virtual function to create a cache.
|
||||
if (!device) return BlockCachePointer();
|
||||
|
||||
return device->createBlockCache();
|
||||
}
|
||||
|
@ -60,7 +60,9 @@ using ProFUSE::POSIXException;
|
||||
|
||||
BlockCachePointer ConcreteBlockCache::Create(BlockDevicePointer device, unsigned size)
|
||||
{
|
||||
return BlockCachePointer(new ConcreteBlockCache(device, size));
|
||||
//return BlockCachePointer(new ConcreteBlockCache(device, size));
|
||||
|
||||
return MAKE_SHARED(ConcreteBlockCache, device, size);
|
||||
}
|
||||
|
||||
ConcreteBlockCache::ConcreteBlockCache(BlockDevicePointer device, unsigned size) :
|
||||
|
@ -21,7 +21,8 @@ using ProFUSE::POSIXException;
|
||||
|
||||
BlockCachePointer MappedBlockCache::Create(BlockDevicePointer device, void *data)
|
||||
{
|
||||
return BlockCachePointer(new MappedBlockCache(device, data));
|
||||
//return BlockCachePointer(new MappedBlockCache(device, data));
|
||||
return MAKE_SHARED(MappedBlockCache, device, data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,13 +8,13 @@
|
||||
#include <Device/TrackSector.h>
|
||||
|
||||
#include <ProFUSE/Exception.h>
|
||||
|
||||
#include <ProFUSE/smart_pointers.h>
|
||||
|
||||
#include <File/File.h>
|
||||
|
||||
namespace Device {
|
||||
|
||||
class BlockDevice : public std::tr1::enable_shared_from_this<BlockDevice> {
|
||||
class BlockDevice : public ENABLE_SHARED_FROM_THIS(BlockDevice) {
|
||||
public:
|
||||
|
||||
|
||||
|
@ -91,7 +91,9 @@ BlockDevicePointer DavexDiskImage::Open(MappedFile *file)
|
||||
#define __METHOD__ "DavexDiskImage::Open"
|
||||
Validate(file);
|
||||
|
||||
return BlockDevicePointer(new DavexDiskImage(file));
|
||||
//return BlockDevicePointer(new DavexDiskImage(file));
|
||||
|
||||
return MAKE_SHARED(DavexDiskImage, file);
|
||||
}
|
||||
|
||||
BlockDevicePointer DavexDiskImage::Create(const char *name, size_t blocks)
|
||||
@ -154,7 +156,9 @@ BlockDevicePointer DavexDiskImage::Create(const char *name, size_t blocks, const
|
||||
std::memcpy(file->address(), header.buffer(), 512);
|
||||
file->sync();
|
||||
|
||||
return BlockDevicePointer(new DavexDiskImage(file));
|
||||
//return BlockDevicePointer(new DavexDiskImage(file));
|
||||
|
||||
return MAKE_SHARED(DavexDiskImage, file);
|
||||
}
|
||||
|
||||
|
||||
|
@ -9,18 +9,15 @@
|
||||
#ifndef __DEVICE_DEVICE_H__
|
||||
#define __DEVICE_DEVICE_H__
|
||||
|
||||
#include <tr1/memory>
|
||||
#include <ProFUSE/smart_pointers.h>
|
||||
|
||||
namespace Device {
|
||||
|
||||
class BlockDevice;
|
||||
class BlockCache;
|
||||
|
||||
|
||||
typedef std::tr1::shared_ptr<BlockDevice> BlockDevicePointer;
|
||||
typedef std::tr1::shared_ptr<BlockCache> BlockCachePointer;
|
||||
|
||||
|
||||
typedef SHARED_PTR(BlockDevice) BlockDevicePointer;
|
||||
typedef SHARED_PTR(BlockCache) BlockCachePointer;
|
||||
}
|
||||
|
||||
|
||||
|
@ -78,7 +78,9 @@ uint32_t DiskCopy42Image::Checksum(void *data, size_t size)
|
||||
BlockDevicePointer DiskCopy42Image::Open(MappedFile *f)
|
||||
{
|
||||
Validate(f);
|
||||
return BlockDevicePointer(new DiskCopy42Image(f));
|
||||
//return BlockDevicePointer(new DiskCopy42Image(f));
|
||||
|
||||
return MAKE_SHARED(DiskCopy42Image, f);
|
||||
}
|
||||
|
||||
static uint8_t DiskFormat(size_t blocks)
|
||||
@ -163,7 +165,9 @@ BlockDevicePointer DiskCopy42Image::Create(const char *name, size_t blocks, cons
|
||||
std::memcpy(file->address(), header.buffer(), oUserData);
|
||||
file->sync();
|
||||
|
||||
return BlockDevicePointer(new DiskCopy42Image(file));
|
||||
//return BlockDevicePointer(new DiskCopy42Image(file));
|
||||
|
||||
return MAKE_SHARED(DiskCopy42Image, file);
|
||||
}
|
||||
|
||||
void DiskCopy42Image::Validate(MappedFile *file)
|
||||
|
@ -115,13 +115,15 @@ ProDOSOrderDiskImage::ProDOSOrderDiskImage(MappedFile *file) :
|
||||
BlockDevicePointer ProDOSOrderDiskImage::Create(const char *name, size_t blocks)
|
||||
{
|
||||
MappedFile *file = MappedFile::Create(name, blocks * 512);
|
||||
return BlockDevicePointer(new ProDOSOrderDiskImage(file));
|
||||
//return BlockDevicePointer(new ProDOSOrderDiskImage(file));
|
||||
return MAKE_SHARED(ProDOSOrderDiskImage, file);
|
||||
}
|
||||
|
||||
BlockDevicePointer ProDOSOrderDiskImage::Open(MappedFile *file)
|
||||
{
|
||||
Validate(file);
|
||||
return BlockDevicePointer(new ProDOSOrderDiskImage(file));
|
||||
//return BlockDevicePointer(new ProDOSOrderDiskImage(file));
|
||||
return MAKE_SHARED(ProDOSOrderDiskImage, file);
|
||||
}
|
||||
|
||||
void ProDOSOrderDiskImage::Validate(MappedFile *f)
|
||||
@ -168,13 +170,16 @@ DOSOrderDiskImage::DOSOrderDiskImage(MappedFile *file) :
|
||||
BlockDevicePointer DOSOrderDiskImage::Create(const char *name, size_t blocks)
|
||||
{
|
||||
MappedFile *file = MappedFile::Create(name, blocks * 512);
|
||||
return BlockDevicePointer(new DOSOrderDiskImage(file));
|
||||
//return BlockDevicePointer(new DOSOrderDiskImage(file));
|
||||
return MAKE_SHARED(DOSOrderDiskImage, file);
|
||||
}
|
||||
|
||||
BlockDevicePointer DOSOrderDiskImage::Open(MappedFile *file)
|
||||
{
|
||||
Validate(file);
|
||||
return BlockDevicePointer(new DOSOrderDiskImage(file));
|
||||
//return BlockDevicePointer(new DOSOrderDiskImage(file));
|
||||
return MAKE_SHARED(DOSOrderDiskImage, file);
|
||||
|
||||
}
|
||||
|
||||
void DOSOrderDiskImage::Validate(MappedFile *f)
|
||||
|
@ -198,7 +198,8 @@ RawDevice::~RawDevice()
|
||||
|
||||
BlockDevicePointer RawDevice::Open(const char *name, File::FileFlags flags)
|
||||
{
|
||||
return BlockDevicePointer(new RawDevice(name, flags));
|
||||
//return BlockDevicePointer(new RawDevice(name, flags));
|
||||
return MAKE_SHARED(RawDevice, name, flags);
|
||||
}
|
||||
|
||||
|
||||
|
@ -81,13 +81,17 @@ BlockDevicePointer UniversalDiskImage::Create(const char *name, size_t blocks)
|
||||
std::memcpy(file->address(), header.buffer(), 64);
|
||||
|
||||
|
||||
return BlockDevicePointer(new UniversalDiskImage(file));
|
||||
//return BlockDevicePointer(new UniversalDiskImage(file));
|
||||
|
||||
return MAKE_SHARED(UniversalDiskImage, file);
|
||||
}
|
||||
|
||||
BlockDevicePointer UniversalDiskImage::Open(MappedFile *file)
|
||||
{
|
||||
Validate(file);
|
||||
return BlockDevicePointer(new UniversalDiskImage(file));
|
||||
|
||||
//return BlockDevicePointer(new UniversalDiskImage(file));
|
||||
return MAKE_SHARED(UniversalDiskImage, file);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,9 +1,7 @@
|
||||
#ifndef __PASCAL_ENTRY_H__
|
||||
#define __PASCAL_ENTRY_H__
|
||||
|
||||
#include <tr1/memory>
|
||||
|
||||
#include <Pascal/Date.h>
|
||||
#include <ProFUSE/smart_pointers.h>
|
||||
|
||||
|
||||
namespace Device {
|
||||
@ -34,13 +32,13 @@ namespace Pascal {
|
||||
class VolumeEntry;
|
||||
|
||||
|
||||
typedef std::tr1::shared_ptr<FileEntry> FileEntryPointer;
|
||||
typedef std::tr1::shared_ptr<VolumeEntry> VolumeEntryPointer;
|
||||
typedef SHARED_PTR(FileEntry) FileEntryPointer;
|
||||
typedef SHARED_PTR(VolumeEntry) VolumeEntryPointer;
|
||||
|
||||
typedef std::tr1::weak_ptr<FileEntry> FileEntryWeakPointer;
|
||||
typedef std::tr1::weak_ptr<VolumeEntry> VolumeEntryWeakPointer;
|
||||
typedef WEAK_PTR(FileEntry) FileEntryWeakPointer;
|
||||
typedef WEAK_PTR(VolumeEntry) VolumeEntryWeakPointer;
|
||||
|
||||
class Entry : public std::tr1::enable_shared_from_this<Entry> {
|
||||
class Entry : public ENABLE_SHARED_FROM_THIS(Entry) {
|
||||
|
||||
public:
|
||||
|
||||
|
@ -44,12 +44,14 @@ unsigned FileEntry::ValidName(const char *cp)
|
||||
|
||||
FileEntryPointer FileEntry::Open(void *vp)
|
||||
{
|
||||
return FileEntryPointer(new FileEntry(vp));
|
||||
//return FileEntryPointer(new FileEntry(vp));
|
||||
return MAKE_SHARED(FileEntry, vp);
|
||||
}
|
||||
|
||||
FileEntryPointer FileEntry::Create(const char *name, unsigned fileKind)
|
||||
{
|
||||
return FileEntryPointer(new FileEntry(name, fileKind));
|
||||
//return FileEntryPointer(new FileEntry(name, fileKind));
|
||||
return MAKE_SHARED(FileEntry, name, fileKind);
|
||||
}
|
||||
|
||||
FileEntry::FileEntry(void *vp) :
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define __PASCAL_FILEENTRY_H__
|
||||
|
||||
#include <Pascal/Entry.h>
|
||||
#include <Pascal/Date.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@ -61,7 +62,7 @@ namespace Pascal {
|
||||
|
||||
FileEntryPointer thisPointer()
|
||||
{
|
||||
return std::tr1::static_pointer_cast<FileEntry>(shared_from_this());
|
||||
return STATIC_POINTER_CAST(FileEntry, shared_from_this());
|
||||
}
|
||||
|
||||
|
||||
|
@ -64,15 +64,19 @@ unsigned VolumeEntry::ValidName(const char *cp)
|
||||
|
||||
VolumeEntryPointer VolumeEntry::Open(Device::BlockDevicePointer device)
|
||||
{
|
||||
VolumeEntryPointer ptr(new VolumeEntry(device));
|
||||
|
||||
VolumeEntryPointer ptr;
|
||||
|
||||
//ptr = new VolumeEntry(device));
|
||||
ptr = MAKE_SHARED(VolumeEntry, device);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
VolumeEntryPointer VolumeEntry::Create(Device::BlockDevicePointer device, const char *name)
|
||||
{
|
||||
VolumeEntryPointer ptr(new VolumeEntry(device, name));
|
||||
VolumeEntryPointer ptr;
|
||||
|
||||
//ptr = new VolumeEntry(device, name);
|
||||
ptr = MAKE_SHARED(VolumeEntry, device, name);
|
||||
|
||||
// set up the weak references from the file entry to this.
|
||||
if (ptr) ptr->setParents();
|
||||
|
@ -71,7 +71,7 @@ namespace Pascal {
|
||||
|
||||
VolumeEntryPointer thisPointer()
|
||||
{
|
||||
return std::tr1::static_pointer_cast<VolumeEntry>(shared_from_this());
|
||||
return STATIC_POINTER_CAST(VolumeEntry, shared_from_this());
|
||||
}
|
||||
|
||||
void init(void *);
|
||||
|
35
ProFUSE/smart_pointers.h
Normal file
35
ProFUSE/smart_pointers.h
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
#ifndef __PROFUSE_SMART_POINTERS_H__
|
||||
#define __PROFUSE_SMART_POINTERS_H__
|
||||
|
||||
#ifdef CPP0X
|
||||
//C++0x
|
||||
#include <memory>
|
||||
|
||||
|
||||
#define SHARED_PTR(T) std::shared_ptr<T>
|
||||
#define WEAK_PTR(T) std::weak_ptr<T>
|
||||
|
||||
#define MAKE_SHARED(T, ...) std::make_shared<T>(__VA_ARGS__)
|
||||
#define ENABLE_SHARED_FROM_THIS(T) std::enable_shared_from_this<T>
|
||||
|
||||
#define STATIC_POINTER_CAST(T, ARG) std::static_pointer_cast<T>(ARG)
|
||||
#define DYNAMIC_POINTER_CAST(T, ARG) std::dynamic_pointer_cast<T>(ARG)
|
||||
|
||||
#else
|
||||
|
||||
// tr1
|
||||
#include <tr1/memory>
|
||||
|
||||
#define SHARED_PTR(T) std::tr1::shared_ptr<T>
|
||||
#define WEAK_PTR(T) std::tr1::weak_ptr<T>
|
||||
|
||||
#define MAKE_SHARED(T, ...) std::tr1::shared_ptr<T>(new T(__VA_ARGS__))
|
||||
#define ENABLE_SHARED_FROM_THIS(T) std::tr1::enable_shared_from_this<T>
|
||||
|
||||
#define STATIC_POINTER_CAST(T, ARG) std::tr1::static_pointer_cast<T>(ARG)
|
||||
#define DYNAMIC_POINTER_CAST(T, ARG) std::tr1::dynamic_pointer_cast<T>(ARG)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user