Main MRPT website > C++ reference for MRPT 1.5.9
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-2017, 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 
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:
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
This class provides simple critical sections functionality.
std::vector< uint8_t > vector_byte
Definition: types_simple.h:26
This class is a bulk sequence of bytes with MultiThread (MT)-safe read and write operations.
Definition: MT_buffer.h:23
GLdouble s
Definition: glext.h:3602
void readAndClear(vector_byte &d)
Definition: MT_buffer.h:58
virtual ~MT_buffer()
Definition: MT_buffer.h:32
void leave() const MRPT_OVERRIDE
Leave.
void enter() const MRPT_OVERRIDE
Enter.
void read(vector_byte &d)
Definition: MT_buffer.h:66
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void appendData(const vector_byte &d)
Definition: MT_buffer.h:51
CCriticalSection m_cs
Definition: MT_buffer.h:27
vector_byte m_data
Definition: MT_buffer.h:26



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020