95d84e4176
* added my own copyright to a couple of files that I changed git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40321 a95241bf-73f2-0310-859d-f6bbb57e9c96
92 lines
1.7 KiB
C++
92 lines
1.7 KiB
C++
/*
|
|
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
|
* Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _PACKAGE__HPKG__PRIVATE__BUFFER_CACHE_H_
|
|
#define _PACKAGE__HPKG__PRIVATE__BUFFER_CACHE_H_
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <util/DoublyLinkedList.h>
|
|
|
|
#include <package/hpkg/BufferCache.h>
|
|
|
|
|
|
namespace BPackageKit {
|
|
|
|
namespace BHPKG {
|
|
|
|
namespace BPrivate {
|
|
|
|
|
|
class CachedBuffer : public DoublyLinkedListLinkImpl<CachedBuffer> {
|
|
public:
|
|
CachedBuffer(size_t size);
|
|
~CachedBuffer();
|
|
|
|
void* Buffer() const { return fBuffer; }
|
|
size_t Size() const { return fSize; }
|
|
|
|
|
|
// implementation private
|
|
CachedBuffer** Owner() const { return fOwner; }
|
|
void SetOwner(CachedBuffer** owner)
|
|
{ fOwner = owner; }
|
|
|
|
void SetCached(bool cached) { fCached = cached; }
|
|
bool IsCached() const { return fCached; }
|
|
|
|
private:
|
|
CachedBuffer** fOwner;
|
|
void* fBuffer;
|
|
size_t fSize;
|
|
bool fCached;
|
|
};
|
|
|
|
|
|
class CachedBufferPutter {
|
|
public:
|
|
CachedBufferPutter(BBufferCache* cache, CachedBuffer** owner)
|
|
:
|
|
fCache(cache),
|
|
fOwner(owner),
|
|
fBuffer(NULL)
|
|
{
|
|
}
|
|
|
|
CachedBufferPutter(BBufferCache* cache, CachedBuffer* buffer)
|
|
:
|
|
fCache(cache),
|
|
fOwner(NULL),
|
|
fBuffer(buffer)
|
|
{
|
|
}
|
|
|
|
~CachedBufferPutter()
|
|
{
|
|
if (fCache != NULL) {
|
|
if (fOwner != NULL)
|
|
fCache->PutBufferAndCache(fOwner);
|
|
else if (fBuffer != NULL)
|
|
fCache->PutBuffer(&fBuffer);
|
|
}
|
|
}
|
|
|
|
private:
|
|
BBufferCache* fCache;
|
|
CachedBuffer** fOwner;
|
|
CachedBuffer* fBuffer;
|
|
};
|
|
|
|
|
|
} // namespace BPrivate
|
|
|
|
} // namespace BHPKG
|
|
|
|
} // namespace BPackageKit
|
|
|
|
|
|
#endif // _PACKAGE__HPKG__PRIVATE__BUFFER_CACHE_H_
|