Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
buffer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Roc Streaming authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_core/buffer.h
10//! @brief Buffer.
11
12#ifndef ROC_CORE_BUFFER_H_
13#define ROC_CORE_BUFFER_H_
14
17#include "roc_core/stddefs.h"
18
19namespace roc {
20namespace core {
21
22//! Buffer.
23template <class T>
24class Buffer : public RefCounted<Buffer<T>, FactoryAllocation<BufferFactory<T> > > {
26
27public:
28 //! Initialize empty buffer.
30 : Base(factory) {
31 new (data()) T[size()];
32 }
33
34 //! Get maximum number of elements.
35 size_t size() const {
36 return Base::factory().buffer_size();
37 }
38
39 //! Get buffer data.
40 T* data() {
41 return (T*)(((char*)this) + sizeof(Buffer));
42 }
43
44 //! Get pointer to buffer from the pointer to its data.
45 static Buffer* container_of(void* data) {
46 return (Buffer*)((char*)data - sizeof(Buffer));
47 }
48};
49
50} // namespace core
51} // namespace roc
52
53#endif // ROC_CORE_BUFFER_H_
Buffer factory.
Buffer.
Definition: buffer.h:24
T * data()
Get buffer data.
Definition: buffer.h:40
Buffer(BufferFactory< T > &factory)
Initialize empty buffer.
Definition: buffer.h:29
static Buffer * container_of(void *data)
Get pointer to buffer from the pointer to its data.
Definition: buffer.h:45
size_t size() const
Get maximum number of elements.
Definition: buffer.h:35
Allocation policy for objects (de)allocated using speciailized factory.
BufferFactory< T > & factory() const
Get factory.
Base class for reference counted object.
Definition: ref_counted.h:39
Root namespace.
Base class for reference counted object.
Commonly used types and functions.