Starting rewrite to boost::shared_ptr. Not done, not tested.

actorid
Nicolay Korslund 15 years ago
parent 674ac556cc
commit c45170f420

@ -1,57 +0,0 @@
#ifndef MANGLE_SOUND_BUFFER_H
#define MANGLE_SOUND_BUFFER_H
#include "source.h"
#include "sources/memsource.h"
#include <vector>
#include <assert.h>
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<uint8_t> 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

@ -20,19 +20,19 @@ namespace Sound {
class InputFilter : public SoundFactory class InputFilter : public SoundFactory
{ {
protected: protected:
SoundFactory *snd; SoundFactoryPtr snd;
SampleSourceLoader *inp; SampleSourceLoaderPtr inp;
public: public:
/// Empty constructor /// Empty constructor
InputFilter() {} InputFilter() {}
/// Assign an input manager and a sound manager to this object /// Assign an input manager and a sound manager to this object
InputFilter(SoundFactory *_snd, SampleSourceLoader *_inp) InputFilter(SoundFactoryPtr _snd, SampleSourceLoaderPtr _inp)
{ set(_snd, _inp); } { set(_snd, _inp); }
/// Assign an input manager and a sound manager to this object /// 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; inp = _inp;
snd = _snd; snd = _snd;
@ -50,13 +50,13 @@ class InputFilter : public SoundFactory
assert(canLoadSource && canLoadFile); 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); } { 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); } { return load(inp->load(input), stream); }
virtual Sound *load(InputSource *input, bool stream=false) virtual SoundPtr load(SampleSourcePtr input)
{ return snd->load(input, stream); } { return snd->load(input, stream); }
virtual void update() { snd->update(); } virtual void update() { snd->update(); }

@ -18,11 +18,6 @@ class OpenAL_Audiere_Factory : public InputFilter
set(new OpenAL_Factory, set(new OpenAL_Factory,
new AudiereLoader); new AudiereLoader);
} }
~OpenAL_Audiere_Factory()
{
delete snd;
delete inp;
}
}; };
}} }}

@ -23,6 +23,9 @@ namespace Sound {
file. Cloned sounds will often (depending on the back-end) use file. Cloned sounds will often (depending on the back-end) use
less memory due to shared buffers. less memory due to shared buffers.
*/ */
class Sound;
typedef boost::shared_ptr<Sound> SoundPtr;
class Sound class Sound
{ {
public: public:
@ -61,7 +64,7 @@ class Sound
/** Playback status is not cloned, only the sound data /** Playback status is not cloned, only the sound data
itself. Back-ends can use this as a means of sharing data and itself. Back-ends can use this as a means of sharing data and
saving memory. */ saving memory. */
virtual Sound* clone() const = 0; virtual SoundPtr clone() const = 0;
/// Virtual destructor /// Virtual destructor
virtual ~Sound() {} virtual ~Sound() {}
@ -117,7 +120,7 @@ class SoundFactory
large files, but they are not required to. large files, but they are not required to.
@return a new Sound object @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 @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 @param stream true if the file should be streamed
@see load(InputSource*,bool) @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 @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 @param stream true if the file should be streamed
@see load(InputSource*,bool) @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 /// Call this every frame if needsUpdate is true
/** /**
@ -161,6 +164,8 @@ class SoundFactory
float ux, float uy, float uz) = 0; float ux, float uy, float uz) = 0;
}; };
typedef boost::shared_ptr<SoundFactory> SoundFactoryPtr;
}} // Namespaces }} // Namespaces
#endif #endif

@ -40,6 +40,8 @@ class SampleSource : public Stream::Stream
size_t size() const { assert(0); } size_t size() const { assert(0); }
}; };
typedef boost::shared_ptr<SampleSource> SampleSourcePtr;
/// A factory interface for loading SampleSources from file or stream /// A factory interface for loading SampleSources from file or stream
class SampleSourceLoader class SampleSourceLoader
{ {
@ -51,14 +53,16 @@ class SampleSourceLoader
bool canLoadFile; bool canLoadFile;
/// Load a sound input source from file (if canLoadFile is true) /// 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) /// 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 destructor
virtual ~SampleSourceLoader() {} virtual ~SampleSourceLoader() {}
}; };
typedef boost::shared_ptr<SampleSourceLoader> SampleSourceLoaderPtr;
}} // namespaces }} // namespaces
#endif #endif

@ -3,7 +3,6 @@
#include <audiere.h> #include <audiere.h>
#include <assert.h> #include <assert.h>
#include "iwrapper.h"
namespace Mangle { namespace Mangle {
namespace Stream { namespace Stream {
@ -13,11 +12,13 @@ namespace Stream {
This lets Audiere read sound files from any generic archive or This lets Audiere read sound files from any generic archive or
file manager that supports Mangle streams. file manager that supports Mangle streams.
*/ */
class AudiereFile : public audiere::RefImplementation<audiere::File>, _SWrapper class AudiereFile : public audiere::RefImplementation<audiere::File>
{ {
StreamPtr inp;
public: public:
AudiereFile(Stream *inp, bool autoDel=false) AudiereFile(StreamPtr _inp)
: _SWrapper(inp, autoDel) {} : inp(_inp) {}
/// Read 'count' bytes, return bytes successfully read /// Read 'count' bytes, return bytes successfully read
int read(void *buf, int count) int read(void *buf, int count)

@ -1,30 +0,0 @@
#ifndef MANGLE_STREAM_IWRAPPER_H
#define MANGLE_STREAM_IWRAPPER_H
#include "../stream.h"
#include <assert.h>
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

@ -3,7 +3,7 @@
#include <OgreDataStream.h> #include <OgreDataStream.h>
#include <assert.h> #include <assert.h>
#include "iwrapper.h" #include "../stream.h"
namespace Mangle { namespace Mangle {
namespace Stream { namespace Stream {
@ -14,8 +14,10 @@ namespace Stream {
to make your own modifications if you're working with newer (or to make your own modifications if you're working with newer (or
older) versions. older) versions.
*/ */
class MangleDataStream : public Ogre::DataStream, _SWrapper class MangleDataStream : public Ogre::DataStream
{ {
StreamPtr inp;
void init() void init()
{ {
// Get the size, if possible // Get the size, if possible
@ -25,13 +27,12 @@ class MangleDataStream : public Ogre::DataStream, _SWrapper
public: public:
/// Constructor without name /// Constructor without name
MangleDataStream(Stream *inp, bool autoDel=false) MangleDataStream(StreamPtr _inp)
: _SWrapper(inp, autoDel) { init(); } : inp(_inp) { init(); }
/// Constructor for a named data stream /// Constructor for a named data stream
MangleDataStream(const Ogre::String &name, Stream *inp, bool autoDel=false) MangleDataStream(const Ogre::String &name, StreamPtr _inp)
: _SWrapper(inp, autoDel), Ogre::DataStream(name) { init(); } : inp(_inp), Ogre::DataStream(name) { init(); }
// Only implement the DataStream functions we have to implement // Only implement the DataStream functions we have to implement

@ -15,7 +15,7 @@ class BufferStream : public MemoryStream
std::vector<char> buffer; std::vector<char> buffer;
public: public:
BufferStream(Stream *input) BufferStream(StreamPtr input)
{ {
// Allocate memory, read the stream into it. Then call set() // Allocate memory, read the stream into it. Then call set()
if(input->hasSize) if(input->hasSize)
@ -62,5 +62,7 @@ class BufferStream : public MemoryStream
} }
}; };
typedef boost::shared_ptr<BufferStream> BufferStreamPtr;
}} // namespaces }} // namespaces
#endif #endif

@ -10,11 +10,11 @@ namespace Stream {
*/ */
class SliceStream : public Stream class SliceStream : public Stream
{ {
Stream *src; StreamPtr src;
size_t offset, length, pos; size_t offset, length, pos;
public: 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) : src(_src), offset(_offset), length(_length), pos(0)
{ {
assert(src->hasSize); assert(src->hasSize);
@ -50,5 +50,7 @@ class SliceStream : public Stream
size_t size() { return length; } size_t size() { return length; }
}; };
typedef boost::shared_ptr<SliceStream> SliceStreamPtr;
}} // namespaces }} // namespaces
#endif #endif

@ -22,5 +22,7 @@ class FileStream : public StdStream
~FileStream() { file.close(); } ~FileStream() { file.close(); }
}; };
typedef boost::shared_ptr<FileStream> FileStreamPtr;
}} // namespaces }} // namespaces
#endif #endif

@ -8,9 +8,9 @@ namespace Mangle {
namespace Stream { namespace Stream {
// Do this before the class declaration, since the class itself // Do this before the class declaration, since the class itself
// depends on it. TODO: Postponed for later // depends on it.
//class MemoryStream; class MemoryStream;
//typedef boost::shared_ptr<MemoryStream> MemoryStreamPtr; typedef boost::shared_ptr<MemoryStream> MemoryStreamPtr;
/** A Stream wrapping a memory buffer /** 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 No memory is copied during this operation, the new stream is
just another 'view' into the same shared memory buffer. 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); if(setPos) res->seek(pos);
return res; return res;
} }

@ -31,5 +31,7 @@ class OgreStream : public Stream
bool eof() const { return inp->eof(); } bool eof() const { return inp->eof(); }
}; };
typedef boost::shared_ptr<OgreStream> OgreStreamPtr;
}} // namespaces }} // namespaces
#endif #endif

@ -30,5 +30,7 @@ class PhysFile : public Stream
bool eof() const { return PHYSFS_eof(file); } bool eof() const { return PHYSFS_eof(file); }
}; };
typedef boost::shared_ptr<PhysFile> PhysFilePtr;
}} // namespaces }} // namespaces
#endif #endif

@ -51,5 +51,7 @@ class StdStream : public Stream
{ return inf->eof(); } { return inf->eof(); }
}; };
typedef boost::shared_ptr<StdStream> StdStreamPtr;
}} // namespaces }} // namespaces
#endif #endif

@ -2,6 +2,7 @@
#define MANGLE_STREAM_INPUT_H #define MANGLE_STREAM_INPUT_H
#include <stdlib.h> #include <stdlib.h>
#include "../tools/shared_ptr.h"
namespace Mangle { namespace Mangle {
namespace Stream { namespace Stream {
@ -46,5 +47,7 @@ class Stream
virtual bool eof() const = 0; virtual bool eof() const = 0;
}; };
typedef boost::shared_ptr<Stream> StreamPtr;
}} // namespaces }} // namespaces
#endif #endif

@ -0,0 +1,3 @@
// This file should include whatever it needs to define the boost/tr1
// shared_ptr<> template.
#include <boost/smart_ptr.h>

@ -38,10 +38,10 @@ static void fill(Ogre::StringVector &out, FileInfoList &in)
Ogre::StringVectorPtr MangleArchive::list(bool recursive, bool dirs) Ogre::StringVectorPtr MangleArchive::list(bool recursive, bool dirs)
{ {
assert(vfs->hasList); assert(vfs->hasList);
FileInfoList lst = vfs->list("", recursive, dirs); FileInfoListPtr lst = vfs->list("", recursive, dirs);
Ogre::StringVector *res = new Ogre::StringVector; Ogre::StringVector *res = new Ogre::StringVector;
fill(*res, lst); fill(*res, *lst);
return Ogre::StringVectorPtr(res); return Ogre::StringVectorPtr(res);
} }
@ -49,10 +49,10 @@ Ogre::StringVectorPtr MangleArchive::list(bool recursive, bool dirs)
Ogre::FileInfoListPtr MangleArchive::listFileInfo(bool recursive, bool dirs) Ogre::FileInfoListPtr MangleArchive::listFileInfo(bool recursive, bool dirs)
{ {
assert(vfs->hasList); assert(vfs->hasList);
FileInfoList lst = vfs->list("", recursive, dirs); FileInfoListPtr lst = vfs->list("", recursive, dirs);
Ogre::FileInfoList *res = new Ogre::FileInfoList; Ogre::FileInfoList *res = new Ogre::FileInfoList;
fill(*res, lst); fill(*res, *lst);
return Ogre::FileInfoListPtr(res); return Ogre::FileInfoListPtr(res);
} }
@ -63,10 +63,10 @@ Ogre::StringVectorPtr MangleArchive::find(const Ogre::String& pattern,
bool dirs) bool dirs)
{ {
assert(vfs->hasFind); assert(vfs->hasFind);
FileInfoList lst = vfs->find(pattern, recursive, dirs); FileInfoListPtr lst = vfs->find(pattern, recursive, dirs);
Ogre::StringVector *res = new Ogre::StringVector; Ogre::StringVector *res = new Ogre::StringVector;
fill(*res, lst); fill(*res, *lst);
return Ogre::StringVectorPtr(res); return Ogre::StringVectorPtr(res);
} }
@ -76,10 +76,10 @@ Ogre::FileInfoListPtr MangleArchive::findFileInfo(const Ogre::String& pattern,
bool dirs) bool dirs)
{ {
assert(vfs->hasFind); assert(vfs->hasFind);
FileInfoList lst = vfs->find(pattern, recursive, dirs); FileInfoListPtr lst = vfs->find(pattern, recursive, dirs);
Ogre::FileInfoList *res = new Ogre::FileInfoList; Ogre::FileInfoList *res = new Ogre::FileInfoList;
fill(*res, lst); fill(*res, *lst);
return Ogre::FileInfoListPtr(res); return Ogre::FileInfoListPtr(res);
} }

@ -3,7 +3,7 @@
#include <OgreArchive.h> #include <OgreArchive.h>
#include <assert.h> #include <assert.h>
#include "wrapper.h" #include "../vfs.h"
namespace Mangle { namespace Mangle {
namespace VFS { namespace VFS {
@ -15,13 +15,14 @@ namespace VFS {
to make your own modifications if you're working with newer (or to make your own modifications if you're working with newer (or
older) versions. older) versions.
*/ */
class MangleArchive : public Ogre::Archive, _Wrapper class MangleArchive : public Ogre::Archive
{ {
VFSPtr vfs;
public: public:
MangleArchive(VFS *vfs, const std::string &name, MangleArchive(VFSPtr _vfs, const std::string &name,
const std::string &archType = "Mangle", const std::string &archType = "Mangle")
bool autoDel=false) : vfs(_vfs), Ogre::Archive(name, archType) {}
: _Wrapper(vfs, autoDel), Ogre::Archive(name, archType) {}
bool isCaseSensitive() const { return vfs->isCaseSensitive; } bool isCaseSensitive() const { return vfs->isCaseSensitive; }

@ -1,30 +0,0 @@
#ifndef MANGLE_VFS_WRAPPER_H
#define MANGLE_VFS_WRAPPER_H
#include "../vfs.h"
#include <assert.h>
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

@ -18,10 +18,10 @@ OgreVFS::OgreVFS(const std::string &_group)
group = gm->getWorldResourceGroupName(); 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); 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) static void fill(FileInfoList &out, Ogre::FileInfoList &in, bool dirs)
@ -44,8 +44,8 @@ FileInfoList OgreVFS::list(const std::string& dir,
bool dirs) const bool dirs) const
{ {
Ogre::FileInfoListPtr olist = gm->listResourceFileInfo(group, dirs); Ogre::FileInfoListPtr olist = gm->listResourceFileInfo(group, dirs);
FileInfoList res; FileInfoListPtr res(new FileInfoList);
fill(res, *olist, dirs); fill(*res, *olist, dirs);
return res; return res;
} }
@ -54,7 +54,7 @@ FileInfoList OgreVFS::find(const std::string& pattern,
bool dirs) const bool dirs) const
{ {
Ogre::FileInfoListPtr olist = gm->findResourceFileInfo(group, pattern, dirs); Ogre::FileInfoListPtr olist = gm->findResourceFileInfo(group, pattern, dirs);
FileInfoList res; FileInfoListPtr res(new FileInfoList);
fill(res, *olist, dirs); fill(*res, *olist, dirs);
return res; return res;
} }

@ -36,7 +36,7 @@ class OgreVFS : public VFS
/// Open a new data stream. Deleting the object should be enough to /// Open a new data stream. Deleting the object should be enough to
/// close it. /// 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 /// Check for the existence of a file
virtual bool isFile(const std::string &name) const virtual bool isFile(const std::string &name) const
@ -47,23 +47,23 @@ class OgreVFS : public VFS
{ return false; } { return false; }
/// This doesn't work. /// This doesn't work.
virtual FileInfo stat(const std::string &name) const virtual FileInfoPtr stat(const std::string &name) const
{ return FileInfo(); } { return FileInfoPtr(); }
/// List all entries in a given directory. A blank dir should be /// List all entries in a given directory. A blank dir should be
/// interpreted as a the root/current directory of the archive. If /// interpreted as a the root/current directory of the archive. If
/// dirs is true, list directories instead of files. OGRE note: The /// dirs is true, list directories instead of files. OGRE note: The
/// ogre resource systemd does not support recursive listing of /// ogre resource systemd does not support recursive listing of
/// files. We might make a separate filter for this later. /// files. We might make a separate filter for this later.
virtual FileInfoList list(const std::string& dir = "", virtual FileInfoListPtr list(const std::string& dir = "",
bool recurse=true, bool recurse=true,
bool dirs=false) const; bool dirs=false) const;
/// Find files after a given pattern. Wildcards (*) are /// Find files after a given pattern. Wildcards (*) are
/// supported. /// supported.
virtual FileInfoList find(const std::string& pattern, virtual FileInfoListPtr find(const std::string& pattern,
bool recursive=true, bool recursive=true,
bool dirs=false) const; bool dirs=false) const;
}; };
}} // namespaces }} // namespaces

@ -26,8 +26,8 @@ class PhysVFS : public VFS
/// Open a new data stream. Deleting the object should be enough to /// Open a new data stream. Deleting the object should be enough to
/// close it. /// close it.
virtual Stream::Stream *open(const std::string &name) virtual Stream::StreamPtr open(const std::string &name)
{ return new Stream::PhysFile(PHYSFS_openRead(name.c_str())); } { return new Stream::StreamPtr(Stream::PhysFile(PHYSFS_openRead(name.c_str()))); }
/// Check for the existence of a file /// Check for the existence of a file
virtual bool isFile(const std::string &name) const virtual bool isFile(const std::string &name) const
@ -38,15 +38,15 @@ class PhysVFS : public VFS
{ return PHYSFS_isDirectory(name.c_str()); } { return PHYSFS_isDirectory(name.c_str()); }
/// This doesn't work /// This doesn't work
virtual FileInfo stat(const std::string &name) const virtual FileInfoPtr stat(const std::string &name) const
{ assert(0); return FileInfo(); } { assert(0); return FileInfoPtr(); }
virtual FileInfoList list(const std::string& dir = "", virtual FileInfoListPtr list(const std::string& dir = "",
bool recurse=true, bool recurse=true,
bool dirs=false) const bool dirs=false) const
{ {
char **files = PHYSFS_enumerateFiles(dir.c_str()); char **files = PHYSFS_enumerateFiles(dir.c_str());
FileInfoList lst; FileInfoListPtr lst(new FileInfoList);
// Add all teh files // Add all teh files
int i = 0; int i = 0;
@ -56,14 +56,14 @@ class PhysVFS : public VFS
fi.name = files[i]; fi.name = files[i];
fi.isDir = false; fi.isDir = false;
lst.push_back(fi); lst->push_back(fi);
} }
return lst; return lst;
} }
virtual FileInfoList find(const std::string& pattern, virtual FileInfoListPtr find(const std::string& pattern,
bool recursive=true, bool recursive=true,
bool dirs=false) const bool dirs=false) const
{ assert(0); } { assert(0); }
}; };

@ -29,6 +29,9 @@ struct FileInfo
typedef std::vector<FileInfo> FileInfoList; typedef std::vector<FileInfo> FileInfoList;
typedef boost::shared_ptr<FileInfo> FileInfoPtr;
typedef boost::shared_ptr<FileInfoList> FileInfoListPtr;
/** An interface to any file system or other provider of named data /** An interface to any file system or other provider of named data
streams streams
*/ */
@ -49,9 +52,9 @@ class VFS
/// Virtual destructor /// Virtual destructor
virtual ~VFS() {} virtual ~VFS() {}
/// Open a new data stream. Deleting the object should be enough to /// Open a new data stream. Deleting the object (letting all the
/// close it. /// pointers to it go out of scope) should be enough to close it.
virtual Stream::Stream *open(const std::string &name) = 0; virtual Stream::StreamPtr open(const std::string &name) = 0;
/// Check for the existence of a file /// Check for the existence of a file
virtual bool isFile(const std::string &name) const = 0; virtual bool isFile(const std::string &name) const = 0;
@ -60,23 +63,25 @@ class VFS
virtual bool isDir(const std::string &name) const = 0; virtual bool isDir(const std::string &name) const = 0;
/// Get info about a single file /// 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 /// List all entries in a given directory. A blank dir should be
/// interpreted as a the root/current directory of the archive. If /// interpreted as a the root/current directory of the archive. If
/// dirs is true, list directories instead of files. /// dirs is true, list directories instead of files.
virtual FileInfoList list(const std::string& dir = "", virtual FileInfoListPtr list(const std::string& dir = "",
bool recurse=true, bool recurse=true,
bool dirs=false) const = 0; bool dirs=false) const = 0;
/// Find files after a given pattern. Wildcards (*) are /// Find files after a given pattern. Wildcards (*) are
/// supported. Only valid if 'hasFind' is true. Don't implement your /// supported. Only valid if 'hasFind' is true. Don't implement your
/// own pattern matching here if the backend doesn't support it /// own pattern matching here if the backend doesn't support it
/// natively; use a filter instead. /// natively; use a filter instead.
virtual FileInfoList find(const std::string& pattern, virtual FileInfoListPtr find(const std::string& pattern,
bool recursive=true, bool recursive=true,
bool dirs=false) const = 0; bool dirs=false) const = 0;
}; };
typedef boost::shared_ptr<VFS> VFSPtr;
}} // namespaces }} // namespaces
#endif #endif

Loading…
Cancel
Save