17 #ifndef CYBER_DATA_CACHE_BUFFER_H_ 18 #define CYBER_DATA_CACHE_BUFFER_H_ 38 buffer_.resize(capacity_);
42 std::lock_guard<std::mutex> lg(rhs.mutex_);
45 buffer_ = rhs.buffer_;
46 capacity_ = rhs.capacity_;
47 fusion_callback_ = rhs.fusion_callback_;
50 T&
operator[](
const uint64_t& pos) {
return buffer_[GetIndex(pos)]; }
51 const T&
at(
const uint64_t& pos)
const {
return buffer_[GetIndex(pos)]; }
53 uint64_t
Head()
const {
return head_ + 1; }
54 uint64_t
Tail()
const {
return tail_; }
55 uint64_t
Size()
const {
return tail_ - head_; }
57 const T&
Front()
const {
return buffer_[GetIndex(head_ + 1)]; }
58 const T&
Back()
const {
return buffer_[GetIndex(tail_)]; }
60 bool Empty()
const {
return tail_ == 0; }
61 bool Full()
const {
return capacity_ - 1 == tail_ - head_; }
62 uint64_t
Capacity()
const {
return capacity_; }
65 fusion_callback_ = callback;
69 if (fusion_callback_) {
70 fusion_callback_(value);
73 buffer_[GetIndex(head_)] =
value;
77 buffer_[GetIndex(tail_ + 1)] =
value;
83 std::mutex&
Mutex() {
return mutex_; }
87 uint64_t GetIndex(
const uint64_t& pos)
const {
return pos % capacity_; }
91 uint64_t capacity_ = 0;
92 std::vector<T> buffer_;
93 mutable std::mutex mutex_;
101 #endif // CYBER_DATA_CACHE_BUFFER_H_ CacheBuffer(uint64_t size)
Definition: cache_buffer.h:36
const T & Back() const
Definition: cache_buffer.h:58
std::size_t size_type
Definition: cache_buffer.h:33
const T & Front() const
Definition: cache_buffer.h:57
uint64_t Size() const
Definition: cache_buffer.h:55
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
void SetFusionCallback(const FusionCallback &callback)
Definition: cache_buffer.h:64
uint64_t Capacity() const
Definition: cache_buffer.h:62
std::mutex & Mutex()
Definition: cache_buffer.h:83
T & operator[](const uint64_t &pos)
Definition: cache_buffer.h:50
std::function< void(const T &)> FusionCallback
Definition: cache_buffer.h:34
const T & at(const uint64_t &pos) const
Definition: cache_buffer.h:51
CacheBuffer(const CacheBuffer &rhs)
Definition: cache_buffer.h:41
void Fill(const T &value)
Definition: cache_buffer.h:68
T value_type
Definition: cache_buffer.h:32
Definition: cache_buffer.h:30
bool Full() const
Definition: cache_buffer.h:61
bool Empty() const
Definition: cache_buffer.h:60
apollo::cyber::base::std value
uint64_t Tail() const
Definition: cache_buffer.h:54
uint64_t Head() const
Definition: cache_buffer.h:53