YARP
Yet Another Robot Platform
FixedSizeBuffersManager.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef YARP_DEV_IMPL_FIXEDSIZEBUFFERSMANAGER_H
7#define YARP_DEV_IMPL_FIXEDSIZEBUFFERSMANAGER_H
8
9#include <vector>
10#include <mutex>
11
12
13namespace yarp::dev::impl {
14
15
20template <typename T>
21class Buffer
22{
23public:
24 uint32_t key;
26 uint32_t numOfElements;
27
31 Buffer();
32
36 ~Buffer();
37
41 T* getData();
42
46 uint32_t getSize();
47
54 T getValue(uint32_t index);
55
62 void setValue(uint32_t index, T value);
63
67 T& operator[](uint32_t index);
68};
69
70
81template <typename T>
83{
84public:
90 explicit FixedSizeBuffersManager(uint32_t sizeOfBuffers, std::size_t initialNumOfBuffers = 3);
91
98
107
112
121
127 void printBuffers();
128
129private:
130 std::mutex m_mutex;
131 std::vector<T*> m_buffers;
132 std::vector<bool> m_usedBuffers;
133 std::size_t m_numElem;
134 uint32_t m_firstFreeBuff; //euristic
135};
136
137
138} // namespace yarp::dev::impl
139
141
142#endif // YARP_DEV_IMPL_FIXEDSIZEBUFFERSMANAGER_H
Buffer contains info about a buffer of type T and it is used to exchange information with yarp::dev::...
T * getData()
Return the data pointer.
~Buffer()
Destructor.Note that the memory will not deallocated.
T & operator[](uint32_t index)
Access specified element.
T getValue(uint32_t index)
Return the value contained in the buffer at index index.
uint32_t getSize()
Return the number of element of buffer.
void setValue(uint32_t index, T value)
Set the value @value in the buffer at index index.
A manager of fixed size buffers in multi-thread environment.
FixedSizeBuffersManager(uint32_t sizeOfBuffers, std::size_t initialNumOfBuffers=3)
Constructor.
std::size_t getBufferSize()
Get the number of elements of a buffer.
Buffer< T > getBuffer()
Get a buffer and fill its information in @buffer.
void releaseBuffer(Buffer< T > &buffer)
Release a buffer.