YARP
Yet Another Robot Platform
FixedSizeBuffersManager.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_DEV_IMPL_FIXEDSIZEBUFFERSMANAGER_H
10 #define YARP_DEV_IMPL_FIXEDSIZEBUFFERSMANAGER_H
11 
12 #include <vector>
13 #include <mutex>
14 
15 
16 namespace yarp {
17 namespace dev {
18 namespace impl {
19 
20 
25 template <typename T>
26 class Buffer
27 {
28 public:
29  uint32_t key;
30  T* dataPtr;
31  uint32_t numOfElements;
32 
36  Buffer();
37 
41  ~Buffer();
42 
46  T* getData();
47 
51  uint32_t getSize();
52 
59  T getValue(uint32_t index);
60 
67  void setValue(uint32_t index, T value);
68 
72  T& operator[](uint32_t index);
73 };
74 
75 
86 template <typename T>
88 {
89 public:
95  explicit FixedSizeBuffersManager(uint32_t sizeOfBuffers, std::size_t initialNumOfBuffers = 3);
96 
103 
112 
116  std::size_t getBufferSize();
117 
126 
132  void printBuffers();
133 
134 private:
135  std::mutex m_mutex;
136  std::vector<T*> m_buffers;
137  std::vector<bool> m_usedBuffers;
138  std::size_t m_numElem;
139  uint32_t m_firstFreeBuff; //euristic
140 };
141 
142 
143 } // namespace impl
144 } // namespace dev
145 } // namespace yarp
146 
148 
149 #endif // YARP_DEV_IMPL_FIXEDSIZEBUFFERSMANAGER_H
yarp::dev::impl::FixedSizeBuffersManager::FixedSizeBuffersManager
FixedSizeBuffersManager(uint32_t sizeOfBuffers, std::size_t initialNumOfBuffers=3)
Constructor.
Definition: FixedSizeBuffersManager-inl.h:72
yarp::dev::impl::Buffer::~Buffer
~Buffer()
Destructor.Note that the memory will not deallocated.
Definition: FixedSizeBuffersManager-inl.h:23
yarp::dev::impl::Buffer::getData
T * getData()
Return the data pointer.
Definition: FixedSizeBuffersManager-inl.h:29
yarp::dev::impl::FixedSizeBuffersManager
A manager of fixed size buffers in multi-thread environment.
Definition: FixedSizeBuffersManager.h:88
yarp::dev::impl::FixedSizeBuffersManager::getBuffer
Buffer< T > getBuffer()
Get a buffer and fill its information in @buffer.
Definition: FixedSizeBuffersManager-inl.h:87
yarp::dev::impl::Buffer::numOfElements
uint32_t numOfElements
Definition: FixedSizeBuffersManager.h:31
yarp::dev::impl::Buffer::getValue
T getValue(uint32_t index)
Return the value contained in the buffer at index index.
Definition: FixedSizeBuffersManager-inl.h:43
yarp::dev::impl::Buffer::operator[]
T & operator[](uint32_t index)
Access specified element.
Definition: FixedSizeBuffersManager-inl.h:65
FixedSizeBuffersManager-inl.h
yarp::dev::impl::Buffer::getSize
uint32_t getSize()
Return the number of element of buffer.
Definition: FixedSizeBuffersManager-inl.h:36
yarp::dev::impl::FixedSizeBuffersManager::getBufferSize
std::size_t getBufferSize()
Get the number of elements of a buffer.
Definition: FixedSizeBuffersManager-inl.h:193
yarp::dev::impl::Buffer
Buffer contains info about a buffer of type T and it is used to exchange information with yarp::dev::...
Definition: FixedSizeBuffersManager.h:27
buffer
Definition: V4L_camera.h:75
yarp::dev::impl::FixedSizeBuffersManager::printBuffers
void printBuffers()
Prints info of buffers.
Definition: FixedSizeBuffersManager-inl.h:172
yarp::dev::impl::FixedSizeBuffersManager::releaseBuffer
void releaseBuffer(Buffer< T > &buffer)
Release a buffer.
Definition: FixedSizeBuffersManager-inl.h:156
yarp::dev::impl::FixedSizeBuffersManager::~FixedSizeBuffersManager
~FixedSizeBuffersManager()
Destructor.
Definition: FixedSizeBuffersManager-inl.h:184
yarp::dev::impl::Buffer::Buffer
Buffer()
Constructor.
Definition: FixedSizeBuffersManager-inl.h:16
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::dev::impl::Buffer::key
uint32_t key
Definition: FixedSizeBuffersManager.h:29
yarp::dev::impl::Buffer::setValue
void setValue(uint32_t index, T value)
Set the value @value in the buffer at index index.
Definition: FixedSizeBuffersManager-inl.h:54
yarp::dev::impl::Buffer::dataPtr
T * dataPtr
Definition: FixedSizeBuffersManager.h:30