1 | /* ************************************************************************** * |
---|
2 | * Copyright © IPSL/LSCE, XMLIOServer, Avril 2010 - Octobre 2011 * |
---|
3 | * ************************************************************************** */ |
---|
4 | |
---|
5 | #ifndef __CIRCULAR_BUFFER_HPP__ |
---|
6 | #define __CIRCULAR_BUFFER_HPP__ |
---|
7 | |
---|
8 | #ifndef __XIOS_NO_EXTERN |
---|
9 | |
---|
10 | // C++ standard headers |
---|
11 | #include <vector> |
---|
12 | |
---|
13 | #endif // __XIOS_NO_EXTERN |
---|
14 | |
---|
15 | // XMLIOServer headers |
---|
16 | #include "xmlioserver_spl.hpp" |
---|
17 | #include "buffer.hpp" |
---|
18 | #include "linear_buffer.hpp" |
---|
19 | |
---|
20 | // ////////////////////////////// Déclarations ///////////////////////////// // |
---|
21 | |
---|
22 | namespace xmlioserver |
---|
23 | { |
---|
24 | namespace comm |
---|
25 | { |
---|
26 | class CCircularBuffer : public CBuffer |
---|
27 | { |
---|
28 | |
---|
29 | public : // Définition de type |
---|
30 | |
---|
31 | typedef CBuffer SuperClass; |
---|
32 | |
---|
33 | public : // Construteurs |
---|
34 | |
---|
35 | explicit CCircularBuffer(std::size_t _size = 1E6); |
---|
36 | CCircularBuffer(const CCircularBuffer & _cbuffer_ref); |
---|
37 | CCircularBuffer(const CCircularBuffer * const _cbuffer_ptr); |
---|
38 | |
---|
39 | public : // Mutateurs |
---|
40 | |
---|
41 | virtual void clear(void); |
---|
42 | |
---|
43 | char * prepareNextData(std::size_t _data_size); |
---|
44 | std::size_t prepareNextDataPosition(std::size_t _data_size); |
---|
45 | |
---|
46 | void appendRequest(const CLinearBuffer & _brequest); |
---|
47 | |
---|
48 | void updateNbRequests(void); |
---|
49 | void updateNbRequests(std::size_t _data_begin, std::size_t _data_end); |
---|
50 | |
---|
51 | public : // Tests |
---|
52 | |
---|
53 | bool hasRequest(void) const ; |
---|
54 | bool isAvailable(std::size_t _data_size) const; |
---|
55 | |
---|
56 | public : // Accesseurs |
---|
57 | |
---|
58 | CLinearBuffer getNextRequest (void); |
---|
59 | std::size_t getNumberOfRequest(void) const; |
---|
60 | |
---|
61 | std::size_t getReadPosition (void) const; |
---|
62 | std::size_t getWritePosition (void) const; |
---|
63 | std::size_t getUnusedPosition(void) const; |
---|
64 | std::size_t getWaitPosition (void) const; |
---|
65 | |
---|
66 | public : // Sortie fichier ascii |
---|
67 | |
---|
68 | virtual void printToTextFile (const std::string & _filename); |
---|
69 | virtual void printToTextStream (std::ostream & _ostr); |
---|
70 | |
---|
71 | public : // Destructeur |
---|
72 | |
---|
73 | virtual ~CCircularBuffer(void); |
---|
74 | |
---|
75 | private : // Mutateurs privés |
---|
76 | |
---|
77 | void movePWrite(std::size_t _data_size); |
---|
78 | void movePRead (std::size_t _data_size); |
---|
79 | |
---|
80 | private : // Accesseurs privés |
---|
81 | |
---|
82 | std::size_t getNextRequestSize(void) const; |
---|
83 | |
---|
84 | private : // Propriétés privées |
---|
85 | |
---|
86 | std::size_t p_write, p_read, p_unused, p_wait, locked_data, nbrequest; |
---|
87 | |
---|
88 | }; // class CCircularBuffer |
---|
89 | } // namespace comm |
---|
90 | } // namespace xmlioserver |
---|
91 | #endif //__CIRCULAR_BUFFER_HPP__ |
---|