Main MRPT website
>
C++ reference for MRPT 1.4.0
mrpt
synch
MT_buffer.h
Go to the documentation of this file.
1
/* +---------------------------------------------------------------------------+
2
| Mobile Robot Programming Toolkit (MRPT) |
3
| http://www.mrpt.org/ |
4
| |
5
| Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6
| See: http://www.mrpt.org/Authors - All rights reserved. |
7
| Released under BSD License. See details in http://www.mrpt.org/License |
8
+---------------------------------------------------------------------------+ */
9
#ifndef mrpt_synch_mt_buffer_H
10
#define mrpt_synch_mt_buffer_H
11
12
#include <
mrpt/synch/CCriticalSection.h
>
13
#include <
mrpt/utils/types_simple.h
>
14
15
namespace
mrpt
16
{
17
namespace
synch
18
{
19
20
/** This class is a bulk sequence of bytes with MultiThread (MT)-safe read and write operations.
21
* \ingroup synch_grp
22
*/
23
class
MT_buffer
24
{
25
private
:
26
vector_byte
m_data
;
27
CCriticalSection
m_cs
;
28
29
public
:
30
MT_buffer
()
//!< Default constructor
31
{}
32
virtual
~MT_buffer
()
//!< Destructor
33
{}
34
35
void
clear
()
//!< Empty the buffer
36
{
37
m_cs
.
enter
();
38
m_data
.clear();
39
m_cs
.
leave
();
40
}
41
42
size_t
size
()
//!< Return the number of available bytes at this moment.
43
{
44
size_t
s;
45
m_cs
.
enter
();
46
s =
m_data
.size();
47
m_cs
.
leave
();
48
return
s;
49
}
50
51
void
appendData
(
const
vector_byte
&d)
//!< Append new data to the stream
52
{
53
m_cs
.
enter
();
54
m_data
.insert(
m_data
.begin(), d.begin(),d.end() );
55
m_cs
.
leave
();
56
}
57
58
void
readAndClear
(
vector_byte
&d)
//!< Read the whole buffer and empty it.
59
{
60
m_cs
.
enter
();
61
d.clear();
62
m_data
.swap(d);
63
m_cs
.
leave
();
64
}
65
66
void
read
(
vector_byte
&d)
//!< Read the whole buffer.
67
{
68
m_cs
.
enter
();
69
d =
m_data
;
70
m_cs
.
leave
();
71
}
72
73
};
// end of MT_buffer
74
75
76
}
// End of namespace
77
}
// End of namespace
78
79
#endif
mrpt::synch::MT_buffer::m_cs
CCriticalSection m_cs
Definition:
MT_buffer.h:27
mrpt::synch::MT_buffer::readAndClear
void readAndClear(vector_byte &d)
Definition:
MT_buffer.h:58
mrpt::synch::MT_buffer::MT_buffer
MT_buffer()
Definition:
MT_buffer.h:30
mrpt::synch::MT_buffer::~MT_buffer
virtual ~MT_buffer()
Definition:
MT_buffer.h:32
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition:
CParticleFilter.h:16
mrpt::synch::CCriticalSection::leave
void leave() const
Leave.
mrpt::synch::MT_buffer::clear
void clear()
Definition:
MT_buffer.h:35
types_simple.h
mrpt::vector_byte
std::vector< uint8_t > vector_byte
Definition:
types_simple.h:26
mrpt::synch::CCriticalSection
This class provides simple critical sections functionality.
Definition:
CCriticalSection.h:31
mrpt::synch::MT_buffer::m_data
vector_byte m_data
Definition:
MT_buffer.h:26
mrpt::synch::MT_buffer::size
size_t size()
Definition:
MT_buffer.h:42
mrpt::synch::MT_buffer::read
void read(vector_byte &d)
Definition:
MT_buffer.h:66
mrpt::synch::MT_buffer::appendData
void appendData(const vector_byte &d)
Definition:
MT_buffer.h:51
mrpt::synch::CCriticalSection::enter
void enter() const
Enter.
CCriticalSection.h
mrpt::synch::MT_buffer
This class is a bulk sequence of bytes with MultiThread (MT)-safe read and write operations.
Definition:
MT_buffer.h:23
Page generated by
Doxygen 1.8.16
for MRPT 1.4.0 SVN: at Mon Oct 14 23:08:25 UTC 2019