MCPcopy Create free account
hub / github.com/davisking/dlib / circular_buffer

Class circular_buffer

dlib/sliding_buffer/circular_buffer.h:20–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18 typename T
19 >
20 class circular_buffer
21 {
22 public:
23 typedef default_memory_manager mem_manager_type;
24 typedef T value_type;
25 typedef T type;
26
27 circular_buffer()
28 {
29 }
30
31 explicit circular_buffer(unsigned long s)
32 {
33 resize(s);
34 }
35
36 void clear (
37 )
38 {
39 offset = 0;
40 data.clear();
41 }
42
43 T& operator[] ( unsigned long i)
44 {
45 DLIB_ASSERT(i < size(),
46 "\t T& circular_buffer::operator[](i)"
47 << "\n\t You have supplied an invalid index"
48 << "\n\t this: " << this
49 << "\n\t i: " << i
50 << "\n\t size(): " << size()
51 );
52 auto index = i + offset;
53 if (index >= data.size())
54 index -= data.size();
55 return data[index];
56 }
57
58 const T& operator[] ( unsigned long i) const
59 {
60 DLIB_ASSERT(i < size(),
61 "\t const T& circular_buffer::operator[](i)"
62 << "\n\t You have supplied an invalid index"
63 << "\n\t this: " << this
64 << "\n\t i: " << i
65 << "\n\t size(): " << size()
66 );
67 auto index = i + offset;
68 if (index >= data.size())
69 index -= data.size();
70 return data[index];
71 }
72
73 void resize(unsigned long size)
74 {
75 offset = 0;
76 data.resize(size);
77 }

Callers

nothing calls this directly

Calls 2

sizeFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected