5 #ifndef CVMFS_UTIL_BUFFER_H_
6 #define CVMFS_UTIL_BUFFER_H_
13 #ifdef CVMFS_NAMESPACE_GUARD
14 namespace CVMFS_NAMESPACE_GUARD {
18 template<
typename T,
class A = std::allocator<T> >
23 Buffer() : used_(0), size_(0), buffer_(NULL), initialized_(false) {}
41 buffer_ = allocator_.allocate(size_bytes());
47 typename A::pointer
ptr() {
51 const typename A::pointer
ptr()
const {
58 return buffer_ + used();
63 return buffer_ + used();
72 assert(bytes <= size_bytes());
73 assert(bytes %
sizeof(T) == 0);
74 used_ = bytes /
sizeof(T);
77 size_t size()
const {
return size_; }
79 size_t used()
const {
return used_; }
81 size_t free()
const {
return size_ - used_; }
92 allocator_.deallocate(buffer_, size_bytes());
107 #ifdef CVMFS_NAMESPACE_GUARD
111 #endif // CVMFS_UTIL_BUFFER_H_
Buffer(const size_t size)
bool IsInitialized() const
assert((mem||(size==0))&&"Out Of Memory")
size_t used_bytes() const
A::pointer free_space_ptr()
size_t free_bytes() const
const A::pointer free_space_ptr() const
void SetUsed(const size_t items)
void Allocate(const size_t size)
Buffer(const Buffer &other)
const A::pointer ptr() const
Buffer & operator=(const Buffer &other)
void SetUsedBytes(const size_t bytes)
size_t size_bytes() const