btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / package / hpkg / PoolBuffer.h
blobd82cd130af86ad11a35681ac5838c8f8988ad71b
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
4 * Distributed under the terms of the MIT License.
5 */
6 #ifndef _PACKAGE__HPKG__PRIVATE__POOL_BUFFER_H_
7 #define _PACKAGE__HPKG__PRIVATE__POOL_BUFFER_H_
10 #include <stddef.h>
12 #include <util/DoublyLinkedList.h>
14 #include <package/hpkg/BufferPool.h>
17 namespace BPackageKit {
19 namespace BHPKG {
21 namespace BPrivate {
24 class PoolBuffer : public DoublyLinkedListLinkImpl<PoolBuffer> {
25 public:
26 PoolBuffer(size_t size);
27 ~PoolBuffer();
29 void* Buffer() const { return fBuffer; }
30 size_t Size() const { return fSize; }
33 // implementation private
34 PoolBuffer** Owner() const { return fOwner; }
35 void SetOwner(PoolBuffer** owner)
36 { fOwner = owner; }
38 void SetCached(bool cached) { fCached = cached; }
39 bool IsCached() const { return fCached; }
41 private:
42 PoolBuffer** fOwner;
43 void* fBuffer;
44 size_t fSize;
45 bool fCached;
49 class PoolBufferPutter {
50 public:
51 PoolBufferPutter(BBufferPool* pool, PoolBuffer** owner)
53 fPool(pool),
54 fOwner(owner),
55 fBuffer(NULL)
59 PoolBufferPutter(BBufferPool* pool, PoolBuffer* buffer)
61 fPool(pool),
62 fOwner(NULL),
63 fBuffer(buffer)
67 ~PoolBufferPutter()
69 if (fPool != NULL) {
70 if (fOwner != NULL)
71 fPool->PutBufferAndCache(fOwner);
72 else if (fBuffer != NULL)
73 fPool->PutBuffer(&fBuffer);
77 private:
78 BBufferPool* fPool;
79 PoolBuffer** fOwner;
80 PoolBuffer* fBuffer;
84 } // namespace BPrivate
86 } // namespace BHPKG
88 } // namespace BPackageKit
91 #endif // _PACKAGE__HPKG__PRIVATE__POOL_BUFFER_H_