Apollo
10.0
自动驾驶开放平台
bridge_buffer.cc
浏览该文件的文档.
1
/******************************************************************************
2
* Copyright 2019 The Apollo Authors. All Rights Reserved.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*****************************************************************************/
16
17
#include "
modules/bridge/common/bridge_buffer.h
"
18
19
#include <memory.h>
20
21
namespace
apollo
{
22
namespace
bridge {
23
24
#define BRIDGE_IMPL(type) template class BridgeBuffer<type>
25
26
template
<
typename
T>
27
BridgeBuffer<T>::BridgeBuffer
() {}
28
29
template
<
typename
T>
30
BridgeBuffer<T>::BridgeBuffer
(
size_t
size) {
31
reset(size);
32
}
33
34
template
<
typename
T>
35
BridgeBuffer<T>::~BridgeBuffer
() {
36
std::lock_guard<std::mutex> lg(mutex_);
37
if
(buf_) {
38
delete
[] buf_;
39
}
40
buf_ =
nullptr
;
41
size_ = 0;
42
capacity_ = 0;
43
}
44
45
template
<
typename
T>
46
BridgeBuffer<T>::operator
T *() {
47
return
buf_;
48
}
49
50
template
<
typename
T>
51
void
BridgeBuffer<T>::reset
(
size_t
size) {
52
std::lock_guard<std::mutex> lg(mutex_);
53
if
(capacity_ < size) {
54
if
(buf_) {
55
delete
[] buf_;
56
}
57
capacity_ = size;
58
buf_ =
new
T[capacity_];
59
}
60
size_ = size;
61
memset(buf_, 0,
sizeof
(T) * capacity_);
62
}
63
64
template
<
typename
T>
65
void
BridgeBuffer<T>::write
(
size_t
index,
const
T *data,
size_t
size) {
66
std::lock_guard<std::mutex> lg(mutex_);
67
reset(size + index);
68
T *p = buf_ + index;
69
memcpy(p, data, size);
70
}
71
72
BRIDGE_IMPL
(
char
);
73
BRIDGE_IMPL
(
int
);
74
BRIDGE_IMPL
(
double
);
75
76
}
// namespace bridge
77
}
// namespace apollo
BRIDGE_IMPL
#define BRIDGE_IMPL(type)
Definition
bridge_buffer.cc:24
bridge_buffer.h
apollo::bridge::BridgeBuffer
Definition
bridge_buffer.h:25
apollo::bridge::BridgeBuffer::BridgeBuffer
BridgeBuffer()
Definition
bridge_buffer.cc:27
apollo::bridge::BridgeBuffer::reset
void reset(size_t size)
Definition
bridge_buffer.cc:51
apollo::bridge::BridgeBuffer::write
void write(size_t index, const T *data, size_t size)
Definition
bridge_buffer.cc:65
apollo::bridge::BridgeBuffer::~BridgeBuffer
virtual ~BridgeBuffer()
Definition
bridge_buffer.cc:35
apollo
class register implement
Definition
arena_queue.h:37
modules
bridge
common
bridge_buffer.cc