Starting rewrite to boost::shared_ptr. Not done, not tested.
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
|
@ -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
|
@ -0,0 +1,3 @@
|
||||
// This file should include whatever it needs to define the boost/tr1
|
||||
// shared_ptr<> template.
|
||||
#include <boost/smart_ptr.h>
|
@ -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
|
Loading…
Reference in New Issue