From c45170f4206189eb6124213083880013c03f3907 Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Thu, 31 Dec 2009 15:37:01 +0100 Subject: [PATCH] Starting rewrite to boost::shared_ptr. Not done, not tested. --- sound/buffer.h | 57 -------------------------------- sound/filters/input_filter.h | 14 ++++---- sound/filters/openal_audiere.h | 5 --- sound/output.h | 13 +++++--- sound/source.h | 8 +++-- stream/clients/audiere_file.h | 9 ++--- stream/clients/iwrapper.h | 30 ----------------- stream/clients/ogre_datastream.h | 15 +++++---- stream/filters/buffer_stream.h | 4 ++- stream/filters/slice_stream.h | 6 ++-- stream/servers/file_stream.h | 2 ++ stream/servers/memory_stream.h | 12 +++---- stream/servers/ogre_datastream.h | 2 ++ stream/servers/phys_stream.h | 2 ++ stream/servers/std_stream.h | 2 ++ stream/stream.h | 3 ++ tools/shared_ptr.h | 3 ++ vfs/clients/ogre_archive.cpp | 16 ++++----- vfs/clients/ogre_archive.h | 13 ++++---- vfs/clients/wrapper.h | 30 ----------------- vfs/servers/ogre_vfs.cpp | 12 +++---- vfs/servers/ogre_vfs.h | 18 +++++----- vfs/servers/physfs_vfs.h | 20 +++++------ vfs/vfs.h | 25 ++++++++------ 24 files changed, 116 insertions(+), 205 deletions(-) delete mode 100644 sound/buffer.h delete mode 100644 stream/clients/iwrapper.h create mode 100644 tools/shared_ptr.h delete mode 100644 vfs/clients/wrapper.h diff --git a/sound/buffer.h b/sound/buffer.h deleted file mode 100644 index 9cb27bd9c..000000000 --- a/sound/buffer.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef MANGLE_SOUND_BUFFER_H -#define MANGLE_SOUND_BUFFER_H - -#include "source.h" -#include "sources/memsource.h" -#include -#include - -namespace Mangle { -namespace Sound { - -/** A sample buffer is a factory that creates SampleSources from one - single sound source. It is helpful when you have many instances of - one sound and want to use one shared memory buffer. - - This is just a helper class - you don't have to include it in your - program if you don't need it. -*/ -class SampleBuffer -{ - std::vector buffer; - - public: - /// Reads the source into a memory buffer. Not heavily optimized. - SampleBuffer(SampleSource *source) - { - size_t final = 0; - - while(!source->eof()) - { - const int add = 16*1024; - - // Allocate more memory - size_t newSize = final + add; - buffer.resize(newSize); - - // Fill in data - size_t read = source->read(&buffer[final], add); - - // If we couldn't read enough data, we should be at the end - // of the stream - assert(read == add || source->eof()); - - final += read; - } - - // Downsize the buffer to the actual length - buffer.resize(final); - } - - /// Get a new source - SampleSource *get() - { return new MemorySource(&buffer[0], buffer.size()); } -}; - -}} -#endif diff --git a/sound/filters/input_filter.h b/sound/filters/input_filter.h index 85a97321d..17dda5534 100644 --- a/sound/filters/input_filter.h +++ b/sound/filters/input_filter.h @@ -20,19 +20,19 @@ namespace Sound { class InputFilter : public SoundFactory { protected: - SoundFactory *snd; - SampleSourceLoader *inp; + SoundFactoryPtr snd; + SampleSourceLoaderPtr inp; public: /// Empty constructor InputFilter() {} /// Assign an input manager and a sound manager to this object - InputFilter(SoundFactory *_snd, SampleSourceLoader *_inp) + InputFilter(SoundFactoryPtr _snd, SampleSourceLoaderPtr _inp) { set(_snd, _inp); } /// Assign an input manager and a sound manager to this object - void set(SoundFactory *_snd, SampleSourceLoader *_inp) + void set(SoundFactoryPtr _snd, SampleSourceLoaderPtr _inp) { inp = _inp; snd = _snd; @@ -50,13 +50,13 @@ class InputFilter : public SoundFactory assert(canLoadSource && canLoadFile); } - virtual Sound *load(const std::string &file, bool stream=false) + virtual SoundPtr load(const std::string &file) { return load(inp->load(file), stream); } - virtual Sound *load(Stream::Stream *input, bool stream=false) + virtual SoundPtr load(Stream::StreamPtr input) { return load(inp->load(input), stream); } - virtual Sound *load(InputSource *input, bool stream=false) + virtual SoundPtr load(SampleSourcePtr input) { return snd->load(input, stream); } virtual void update() { snd->update(); } diff --git a/sound/filters/openal_audiere.h b/sound/filters/openal_audiere.h index 45024094a..9a2bfcf8c 100644 --- a/sound/filters/openal_audiere.h +++ b/sound/filters/openal_audiere.h @@ -18,11 +18,6 @@ class OpenAL_Audiere_Factory : public InputFilter set(new OpenAL_Factory, new AudiereLoader); } - ~OpenAL_Audiere_Factory() - { - delete snd; - delete inp; - } }; }} diff --git a/sound/output.h b/sound/output.h index 0829e4789..dfd190241 100644 --- a/sound/output.h +++ b/sound/output.h @@ -23,6 +23,9 @@ namespace Sound { file. Cloned sounds will often (depending on the back-end) use less memory due to shared buffers. */ +class Sound; +typedef boost::shared_ptr SoundPtr; + class Sound { public: @@ -61,7 +64,7 @@ class Sound /** Playback status is not cloned, only the sound data itself. Back-ends can use this as a means of sharing data and saving memory. */ - virtual Sound* clone() const = 0; + virtual SoundPtr clone() const = 0; /// Virtual destructor virtual ~Sound() {} @@ -117,7 +120,7 @@ class SoundFactory large files, but they are not required to. @return a new Sound object */ - virtual Sound *load(SampleSource *input) = 0; + virtual SoundPtr load(SampleSource *input) = 0; /** @brief Load a sound file from stream. Only valid if canLoadStream @@ -127,7 +130,7 @@ class SoundFactory @param stream true if the file should be streamed @see load(InputSource*,bool) */ - virtual Sound *load(Stream::Stream *input) = 0; + virtual SoundPtr load(Stream::Stream *input) = 0; /** @brief Load a sound directly from file. Only valid if canLoadFile @@ -137,7 +140,7 @@ class SoundFactory @param stream true if the file should be streamed @see load(InputSource*,bool) */ - virtual Sound *load(const std::string &file) = 0; + virtual SoundPtr load(const std::string &file) = 0; /// Call this every frame if needsUpdate is true /** @@ -161,6 +164,8 @@ class SoundFactory float ux, float uy, float uz) = 0; }; +typedef boost::shared_ptr SoundFactoryPtr; + }} // Namespaces #endif diff --git a/sound/source.h b/sound/source.h index db5bc6b47..0301f4bae 100644 --- a/sound/source.h +++ b/sound/source.h @@ -40,6 +40,8 @@ class SampleSource : public Stream::Stream size_t size() const { assert(0); } }; +typedef boost::shared_ptr SampleSourcePtr; + /// A factory interface for loading SampleSources from file or stream class SampleSourceLoader { @@ -51,14 +53,16 @@ class SampleSourceLoader bool canLoadFile; /// Load a sound input source from file (if canLoadFile is true) - virtual SampleSource *load(const std::string &file) = 0; + virtual SampleSourcePtr load(const std::string &file) = 0; /// Load a sound input source from stream (if canLoadStream is true) - virtual SampleSource *load(Stream::Stream *input) = 0; + virtual SampleSourcePtr load(Stream::StreamPtr input) = 0; /// Virtual destructor virtual ~SampleSourceLoader() {} }; +typedef boost::shared_ptr SampleSourceLoaderPtr; + }} // namespaces #endif diff --git a/stream/clients/audiere_file.h b/stream/clients/audiere_file.h index 87833e6b3..ec67fd1b7 100644 --- a/stream/clients/audiere_file.h +++ b/stream/clients/audiere_file.h @@ -3,7 +3,6 @@ #include #include -#include "iwrapper.h" namespace Mangle { namespace Stream { @@ -13,11 +12,13 @@ namespace Stream { This lets Audiere read sound files from any generic archive or file manager that supports Mangle streams. */ -class AudiereFile : public audiere::RefImplementation, _SWrapper +class AudiereFile : public audiere::RefImplementation { + StreamPtr inp; + public: - AudiereFile(Stream *inp, bool autoDel=false) - : _SWrapper(inp, autoDel) {} + AudiereFile(StreamPtr _inp) + : inp(_inp) {} /// Read 'count' bytes, return bytes successfully read int read(void *buf, int count) diff --git a/stream/clients/iwrapper.h b/stream/clients/iwrapper.h deleted file mode 100644 index cc12d5b7e..000000000 --- a/stream/clients/iwrapper.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef MANGLE_STREAM_IWRAPPER_H -#define MANGLE_STREAM_IWRAPPER_H - -#include "../stream.h" -#include - -namespace Mangle { -namespace Stream { - -/** A generic wrapper class for a Stream::Stream object. - - This is used by other implementations. - */ -class _SWrapper -{ - private: - bool autoDel; - - protected: - Stream *inp; - - public: - _SWrapper(Stream *_inp, bool _autoDel = false) - : inp(_inp), autoDel(_autoDel) { assert(inp != NULL); } - - virtual ~_SWrapper() { if(autoDel) delete inp; } -}; - -}} // namespaces -#endif diff --git a/stream/clients/ogre_datastream.h b/stream/clients/ogre_datastream.h index 6d0979930..23ab94fd4 100644 --- a/stream/clients/ogre_datastream.h +++ b/stream/clients/ogre_datastream.h @@ -3,7 +3,7 @@ #include #include -#include "iwrapper.h" +#include "../stream.h" namespace Mangle { namespace Stream { @@ -14,8 +14,10 @@ namespace Stream { to make your own modifications if you're working with newer (or older) versions. */ -class MangleDataStream : public Ogre::DataStream, _SWrapper +class MangleDataStream : public Ogre::DataStream { + StreamPtr inp; + void init() { // Get the size, if possible @@ -25,13 +27,12 @@ class MangleDataStream : public Ogre::DataStream, _SWrapper public: /// Constructor without name - MangleDataStream(Stream *inp, bool autoDel=false) - : _SWrapper(inp, autoDel) { init(); } + MangleDataStream(StreamPtr _inp) + : inp(_inp) { init(); } /// Constructor for a named data stream - MangleDataStream(const Ogre::String &name, Stream *inp, bool autoDel=false) - : _SWrapper(inp, autoDel), Ogre::DataStream(name) { init(); } - + MangleDataStream(const Ogre::String &name, StreamPtr _inp) + : inp(_inp), Ogre::DataStream(name) { init(); } // Only implement the DataStream functions we have to implement diff --git a/stream/filters/buffer_stream.h b/stream/filters/buffer_stream.h index 7790a7542..f04411f98 100644 --- a/stream/filters/buffer_stream.h +++ b/stream/filters/buffer_stream.h @@ -15,7 +15,7 @@ class BufferStream : public MemoryStream std::vector buffer; public: - BufferStream(Stream *input) + BufferStream(StreamPtr input) { // Allocate memory, read the stream into it. Then call set() if(input->hasSize) @@ -62,5 +62,7 @@ class BufferStream : public MemoryStream } }; +typedef boost::shared_ptr BufferStreamPtr; + }} // namespaces #endif diff --git a/stream/filters/slice_stream.h b/stream/filters/slice_stream.h index 5bd47d978..49f0ec31d 100644 --- a/stream/filters/slice_stream.h +++ b/stream/filters/slice_stream.h @@ -10,11 +10,11 @@ namespace Stream { */ class SliceStream : public Stream { - Stream *src; + StreamPtr src; size_t offset, length, pos; public: - SliceStream(Stream *_src, size_t _offset, size_t _length) + SliceStream(StreamPtr _src, size_t _offset, size_t _length) : src(_src), offset(_offset), length(_length), pos(0) { assert(src->hasSize); @@ -50,5 +50,7 @@ class SliceStream : public Stream size_t size() { return length; } }; +typedef boost::shared_ptr SliceStreamPtr; + }} // namespaces #endif diff --git a/stream/servers/file_stream.h b/stream/servers/file_stream.h index 1d6f92032..bb4df4d38 100644 --- a/stream/servers/file_stream.h +++ b/stream/servers/file_stream.h @@ -22,5 +22,7 @@ class FileStream : public StdStream ~FileStream() { file.close(); } }; +typedef boost::shared_ptr FileStreamPtr; + }} // namespaces #endif diff --git a/stream/servers/memory_stream.h b/stream/servers/memory_stream.h index 03f7a42f2..94b2f61d9 100644 --- a/stream/servers/memory_stream.h +++ b/stream/servers/memory_stream.h @@ -8,9 +8,9 @@ namespace Mangle { namespace Stream { // Do this before the class declaration, since the class itself -// depends on it. TODO: Postponed for later -//class MemoryStream; -//typedef boost::shared_ptr MemoryStreamPtr; +// depends on it. +class MemoryStream; +typedef boost::shared_ptr MemoryStreamPtr; /** A Stream wrapping a memory buffer @@ -88,12 +88,10 @@ class MemoryStream : public Stream No memory is copied during this operation, the new stream is just another 'view' into the same shared memory buffer. - - TODO: Rewrite to use smart pointers */ - MemoryStream* clone(bool setPos=false) const + MemoryStreamPtr clone(bool setPos=false) const { - MemoryStream* res = new MemoryStream(data, length); + MemoryStreamPtr res(new MemoryStream(data, length)); if(setPos) res->seek(pos); return res; } diff --git a/stream/servers/ogre_datastream.h b/stream/servers/ogre_datastream.h index 184fa1668..a5be98c84 100644 --- a/stream/servers/ogre_datastream.h +++ b/stream/servers/ogre_datastream.h @@ -31,5 +31,7 @@ class OgreStream : public Stream bool eof() const { return inp->eof(); } }; +typedef boost::shared_ptr OgreStreamPtr; + }} // namespaces #endif diff --git a/stream/servers/phys_stream.h b/stream/servers/phys_stream.h index 3660391fd..4312ac041 100644 --- a/stream/servers/phys_stream.h +++ b/stream/servers/phys_stream.h @@ -30,5 +30,7 @@ class PhysFile : public Stream bool eof() const { return PHYSFS_eof(file); } }; +typedef boost::shared_ptr PhysFilePtr; + }} // namespaces #endif diff --git a/stream/servers/std_stream.h b/stream/servers/std_stream.h index e93295f15..0e91ebb78 100644 --- a/stream/servers/std_stream.h +++ b/stream/servers/std_stream.h @@ -51,5 +51,7 @@ class StdStream : public Stream { return inf->eof(); } }; +typedef boost::shared_ptr StdStreamPtr; + }} // namespaces #endif diff --git a/stream/stream.h b/stream/stream.h index 7116b8e2a..75f84cbd2 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -2,6 +2,7 @@ #define MANGLE_STREAM_INPUT_H #include +#include "../tools/shared_ptr.h" namespace Mangle { namespace Stream { @@ -46,5 +47,7 @@ class Stream virtual bool eof() const = 0; }; +typedef boost::shared_ptr StreamPtr; + }} // namespaces #endif diff --git a/tools/shared_ptr.h b/tools/shared_ptr.h new file mode 100644 index 000000000..00af6084b --- /dev/null +++ b/tools/shared_ptr.h @@ -0,0 +1,3 @@ +// This file should include whatever it needs to define the boost/tr1 +// shared_ptr<> template. +#include diff --git a/vfs/clients/ogre_archive.cpp b/vfs/clients/ogre_archive.cpp index 936eda9b6..0def218db 100644 --- a/vfs/clients/ogre_archive.cpp +++ b/vfs/clients/ogre_archive.cpp @@ -38,10 +38,10 @@ static void fill(Ogre::StringVector &out, FileInfoList &in) Ogre::StringVectorPtr MangleArchive::list(bool recursive, bool dirs) { assert(vfs->hasList); - FileInfoList lst = vfs->list("", recursive, dirs); + FileInfoListPtr lst = vfs->list("", recursive, dirs); Ogre::StringVector *res = new Ogre::StringVector; - fill(*res, lst); + fill(*res, *lst); return Ogre::StringVectorPtr(res); } @@ -49,10 +49,10 @@ Ogre::StringVectorPtr MangleArchive::list(bool recursive, bool dirs) Ogre::FileInfoListPtr MangleArchive::listFileInfo(bool recursive, bool dirs) { assert(vfs->hasList); - FileInfoList lst = vfs->list("", recursive, dirs); + FileInfoListPtr lst = vfs->list("", recursive, dirs); Ogre::FileInfoList *res = new Ogre::FileInfoList; - fill(*res, lst); + fill(*res, *lst); return Ogre::FileInfoListPtr(res); } @@ -63,10 +63,10 @@ Ogre::StringVectorPtr MangleArchive::find(const Ogre::String& pattern, bool dirs) { assert(vfs->hasFind); - FileInfoList lst = vfs->find(pattern, recursive, dirs); + FileInfoListPtr lst = vfs->find(pattern, recursive, dirs); Ogre::StringVector *res = new Ogre::StringVector; - fill(*res, lst); + fill(*res, *lst); return Ogre::StringVectorPtr(res); } @@ -76,10 +76,10 @@ Ogre::FileInfoListPtr MangleArchive::findFileInfo(const Ogre::String& pattern, bool dirs) { assert(vfs->hasFind); - FileInfoList lst = vfs->find(pattern, recursive, dirs); + FileInfoListPtr lst = vfs->find(pattern, recursive, dirs); Ogre::FileInfoList *res = new Ogre::FileInfoList; - fill(*res, lst); + fill(*res, *lst); return Ogre::FileInfoListPtr(res); } diff --git a/vfs/clients/ogre_archive.h b/vfs/clients/ogre_archive.h index 70e6045c4..84f23eb8a 100644 --- a/vfs/clients/ogre_archive.h +++ b/vfs/clients/ogre_archive.h @@ -3,7 +3,7 @@ #include #include -#include "wrapper.h" +#include "../vfs.h" namespace Mangle { namespace VFS { @@ -15,13 +15,14 @@ namespace VFS { to make your own modifications if you're working with newer (or older) versions. */ -class MangleArchive : public Ogre::Archive, _Wrapper +class MangleArchive : public Ogre::Archive { + VFSPtr vfs; + public: - MangleArchive(VFS *vfs, const std::string &name, - const std::string &archType = "Mangle", - bool autoDel=false) - : _Wrapper(vfs, autoDel), Ogre::Archive(name, archType) {} + MangleArchive(VFSPtr _vfs, const std::string &name, + const std::string &archType = "Mangle") + : vfs(_vfs), Ogre::Archive(name, archType) {} bool isCaseSensitive() const { return vfs->isCaseSensitive; } diff --git a/vfs/clients/wrapper.h b/vfs/clients/wrapper.h deleted file mode 100644 index 357bc8b4f..000000000 --- a/vfs/clients/wrapper.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef MANGLE_VFS_WRAPPER_H -#define MANGLE_VFS_WRAPPER_H - -#include "../vfs.h" -#include - -namespace Mangle { -namespace VFS { - -/** A generic wrapper class for a VFS::VFS object. - - This is used by other implementations. - */ -class _Wrapper -{ - private: - bool autoDel; - - protected: - VFS *vfs; - - public: - _Wrapper(VFS *_vfs, bool _autoDel = false) - : vfs(_vfs), autoDel(_autoDel) { assert(vfs != NULL); } - - virtual ~_Wrapper() { if(autoDel) delete vfs; } -}; - -}} // namespaces -#endif diff --git a/vfs/servers/ogre_vfs.cpp b/vfs/servers/ogre_vfs.cpp index af1f7c963..0fc051a8a 100644 --- a/vfs/servers/ogre_vfs.cpp +++ b/vfs/servers/ogre_vfs.cpp @@ -18,10 +18,10 @@ OgreVFS::OgreVFS(const std::string &_group) group = gm->getWorldResourceGroupName(); } -Mangle::Stream::Stream *OgreVFS::open(const std::string &name) +Mangle::Stream::StreamPtr OgreVFS::open(const std::string &name) { Ogre::DataStreamPtr data = gm->openResource(name, group); - return new Stream::OgreStream(data); + return Strea::StreamPtr(new Stream::OgreStream(data)); } static void fill(FileInfoList &out, Ogre::FileInfoList &in, bool dirs) @@ -44,8 +44,8 @@ FileInfoList OgreVFS::list(const std::string& dir, bool dirs) const { Ogre::FileInfoListPtr olist = gm->listResourceFileInfo(group, dirs); - FileInfoList res; - fill(res, *olist, dirs); + FileInfoListPtr res(new FileInfoList); + fill(*res, *olist, dirs); return res; } @@ -54,7 +54,7 @@ FileInfoList OgreVFS::find(const std::string& pattern, bool dirs) const { Ogre::FileInfoListPtr olist = gm->findResourceFileInfo(group, pattern, dirs); - FileInfoList res; - fill(res, *olist, dirs); + FileInfoListPtr res(new FileInfoList); + fill(*res, *olist, dirs); return res; } diff --git a/vfs/servers/ogre_vfs.h b/vfs/servers/ogre_vfs.h index 8fe2cca1c..f212432f8 100644 --- a/vfs/servers/ogre_vfs.h +++ b/vfs/servers/ogre_vfs.h @@ -36,7 +36,7 @@ class OgreVFS : public VFS /// Open a new data stream. Deleting the object should be enough to /// close it. - virtual Stream::Stream *open(const std::string &name); + virtual Stream::StreamPtr open(const std::string &name); /// Check for the existence of a file virtual bool isFile(const std::string &name) const @@ -47,23 +47,23 @@ class OgreVFS : public VFS { return false; } /// This doesn't work. - virtual FileInfo stat(const std::string &name) const - { return FileInfo(); } + virtual FileInfoPtr stat(const std::string &name) const + { return FileInfoPtr(); } /// List all entries in a given directory. A blank dir should be /// interpreted as a the root/current directory of the archive. If /// dirs is true, list directories instead of files. OGRE note: The /// ogre resource systemd does not support recursive listing of /// files. We might make a separate filter for this later. - virtual FileInfoList list(const std::string& dir = "", - bool recurse=true, - bool dirs=false) const; + virtual FileInfoListPtr list(const std::string& dir = "", + bool recurse=true, + bool dirs=false) const; /// Find files after a given pattern. Wildcards (*) are /// supported. - virtual FileInfoList find(const std::string& pattern, - bool recursive=true, - bool dirs=false) const; + virtual FileInfoListPtr find(const std::string& pattern, + bool recursive=true, + bool dirs=false) const; }; }} // namespaces diff --git a/vfs/servers/physfs_vfs.h b/vfs/servers/physfs_vfs.h index c25a0035c..f85cc54b8 100644 --- a/vfs/servers/physfs_vfs.h +++ b/vfs/servers/physfs_vfs.h @@ -26,8 +26,8 @@ class PhysVFS : public VFS /// Open a new data stream. Deleting the object should be enough to /// close it. - virtual Stream::Stream *open(const std::string &name) - { return new Stream::PhysFile(PHYSFS_openRead(name.c_str())); } + virtual Stream::StreamPtr open(const std::string &name) + { return new Stream::StreamPtr(Stream::PhysFile(PHYSFS_openRead(name.c_str()))); } /// Check for the existence of a file virtual bool isFile(const std::string &name) const @@ -38,15 +38,15 @@ class PhysVFS : public VFS { return PHYSFS_isDirectory(name.c_str()); } /// This doesn't work - virtual FileInfo stat(const std::string &name) const - { assert(0); return FileInfo(); } + virtual FileInfoPtr stat(const std::string &name) const + { assert(0); return FileInfoPtr(); } - virtual FileInfoList list(const std::string& dir = "", + virtual FileInfoListPtr list(const std::string& dir = "", bool recurse=true, bool dirs=false) const { char **files = PHYSFS_enumerateFiles(dir.c_str()); - FileInfoList lst; + FileInfoListPtr lst(new FileInfoList); // Add all teh files int i = 0; @@ -56,14 +56,14 @@ class PhysVFS : public VFS fi.name = files[i]; fi.isDir = false; - lst.push_back(fi); + lst->push_back(fi); } return lst; } - virtual FileInfoList find(const std::string& pattern, - bool recursive=true, - bool dirs=false) const + virtual FileInfoListPtr find(const std::string& pattern, + bool recursive=true, + bool dirs=false) const { assert(0); } }; diff --git a/vfs/vfs.h b/vfs/vfs.h index 4054c6069..c52bcaebb 100644 --- a/vfs/vfs.h +++ b/vfs/vfs.h @@ -29,6 +29,9 @@ struct FileInfo typedef std::vector FileInfoList; +typedef boost::shared_ptr FileInfoPtr; +typedef boost::shared_ptr FileInfoListPtr; + /** An interface to any file system or other provider of named data streams */ @@ -49,9 +52,9 @@ class VFS /// Virtual destructor virtual ~VFS() {} - /// Open a new data stream. Deleting the object should be enough to - /// close it. - virtual Stream::Stream *open(const std::string &name) = 0; + /// Open a new data stream. Deleting the object (letting all the + /// pointers to it go out of scope) should be enough to close it. + virtual Stream::StreamPtr open(const std::string &name) = 0; /// Check for the existence of a file virtual bool isFile(const std::string &name) const = 0; @@ -60,23 +63,25 @@ class VFS virtual bool isDir(const std::string &name) const = 0; /// Get info about a single file - virtual FileInfo stat(const std::string &name) const = 0; + virtual FileInfoPtr stat(const std::string &name) const = 0; /// List all entries in a given directory. A blank dir should be /// interpreted as a the root/current directory of the archive. If /// dirs is true, list directories instead of files. - virtual FileInfoList list(const std::string& dir = "", - bool recurse=true, - bool dirs=false) const = 0; + virtual FileInfoListPtr list(const std::string& dir = "", + bool recurse=true, + bool dirs=false) const = 0; /// Find files after a given pattern. Wildcards (*) are /// supported. Only valid if 'hasFind' is true. Don't implement your /// own pattern matching here if the backend doesn't support it /// natively; use a filter instead. - virtual FileInfoList find(const std::string& pattern, - bool recursive=true, - bool dirs=false) const = 0; + virtual FileInfoListPtr find(const std::string& pattern, + bool recursive=true, + bool dirs=false) const = 0; }; +typedef boost::shared_ptr VFSPtr; + }} // namespaces #endif