Main MRPT website > C++ reference for MRPT 1.4.0
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
14
15namespace mrpt
16{
17namespace 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 */
24{
25private:
28
29public:
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
This class provides simple critical sections functionality.
void leave() const
Leave.
void enter() const
Enter.
This class is a bulk sequence of bytes with MultiThread (MT)-safe read and write operations.
Definition: MT_buffer.h:24
CCriticalSection m_cs
Definition: MT_buffer.h:27
void appendData(const vector_byte &d)
Definition: MT_buffer.h:51
void read(vector_byte &d)
Definition: MT_buffer.h:66
void readAndClear(vector_byte &d)
Definition: MT_buffer.h:58
virtual ~MT_buffer()
Definition: MT_buffer.h:32
vector_byte m_data
Definition: MT_buffer.h:26
std::vector< uint8_t > vector_byte
Definition: types_simple.h:26
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.



Page generated by Doxygen 1.9.6 for MRPT 1.4.0 SVN: at Tue Jan 17 22:40:29 UTC 2023