mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-24 00:39:49 +00:00
Starting rewrite to boost::shared_ptr. Not done, not tested.
This commit is contained in:
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
|
||||
{
|
||||
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(); }
|
||||
|
@ -18,11 +18,6 @@ class OpenAL_Audiere_Factory : public InputFilter
|
||||
set(new OpenAL_Factory,
|
||||
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
|
||||
less memory due to shared buffers.
|
||||
*/
|
||||
class Sound;
|
||||
typedef boost::shared_ptr<Sound> 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<SoundFactory> SoundFactoryPtr;
|
||||
|
||||
}} // Namespaces
|
||||
|
||||
#endif
|
||||
|
@ -40,6 +40,8 @@ class SampleSource : public Stream::Stream
|
||||
size_t size() const { assert(0); }
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<SampleSource> 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<SampleSourceLoader> SampleSourceLoaderPtr;
|
||||
|
||||
}} // namespaces
|
||||
#endif
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#include <audiere.h>
|
||||
#include <assert.h>
|
||||
#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<audiere::File>, _SWrapper
|
||||
class AudiereFile : public audiere::RefImplementation<audiere::File>
|
||||
{
|
||||
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)
|
||||
|
@ -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 <assert.h>
|
||||
#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
|
||||
|
||||
|
@ -15,7 +15,7 @@ class BufferStream : public MemoryStream
|
||||
std::vector<char> 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<BufferStream> BufferStreamPtr;
|
||||
|
||||
}} // namespaces
|
||||
#endif
|
||||
|
@ -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<SliceStream> SliceStreamPtr;
|
||||
|
||||
}} // namespaces
|
||||
#endif
|
||||
|
@ -22,5 +22,7 @@ class FileStream : public StdStream
|
||||
~FileStream() { file.close(); }
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<FileStream> FileStreamPtr;
|
||||
|
||||
}} // namespaces
|
||||
#endif
|
||||
|
@ -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<MemoryStream> MemoryStreamPtr;
|
||||
// depends on it.
|
||||
class MemoryStream;
|
||||
typedef boost::shared_ptr<MemoryStream> 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;
|
||||
}
|
||||
|
@ -31,5 +31,7 @@ class OgreStream : public Stream
|
||||
bool eof() const { return inp->eof(); }
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<OgreStream> OgreStreamPtr;
|
||||
|
||||
}} // namespaces
|
||||
#endif
|
||||
|
@ -30,5 +30,7 @@ class PhysFile : public Stream
|
||||
bool eof() const { return PHYSFS_eof(file); }
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<PhysFile> PhysFilePtr;
|
||||
|
||||
}} // namespaces
|
||||
#endif
|
||||
|
@ -51,5 +51,7 @@ class StdStream : public Stream
|
||||
{ return inf->eof(); }
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<StdStream> StdStreamPtr;
|
||||
|
||||
}} // namespaces
|
||||
#endif
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define MANGLE_STREAM_INPUT_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "../tools/shared_ptr.h"
|
||||
|
||||
namespace Mangle {
|
||||
namespace Stream {
|
||||
@ -46,5 +47,7 @@ class Stream
|
||||
virtual bool eof() const = 0;
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<Stream> StreamPtr;
|
||||
|
||||
}} // namespaces
|
||||
#endif
|
||||
|
3
tools/shared_ptr.h
Normal file
3
tools/shared_ptr.h
Normal file
@ -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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <OgreArchive.h>
|
||||
#include <assert.h>
|
||||
#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; }
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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); }
|
||||
};
|
||||
|
||||
|
25
vfs/vfs.h
25
vfs/vfs.h
@ -29,6 +29,9 @@ struct FileInfo
|
||||
|
||||
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
|
||||
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<VFS> VFSPtr;
|
||||
|
||||
}} // namespaces
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user