src
tile_cache_delay.h
Go to the documentation of this file.
1
/* Copyright 2018-2019 TomTom N.V.
2
3
Licensed under the Apache License, Version 2.0 (the "License");
4
you may not use this file except in compliance with the License.
5
You may obtain a copy of the License at
6
7
http://www.apache.org/licenses/LICENSE-2.0
8
9
Unless required by applicable law or agreed to in writing, software
10
distributed under the License is distributed on an "AS IS" BASIS,
11
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
See the License for the specific language governing permissions and
13
limitations under the License. */
14
15
#pragma once
16
17
#include <vector>
18
19
#include <QTimer>
20
21
#include "
tile_cache.h
"
22
23
template
<
typename
Tile>
24
class
TileCacheDelay
;
25
26
namespace
detail
27
{
33
struct
ExpiringArea
34
{
35
QTimer
timer
;
36
Area
area
;
37
38
ExpiringArea
(
Area
area
) :
area
(
std
::move(
area
))
39
{
40
timer
.setSingleShot(
true
);
41
int
constexpr timeout = 2000;
// in ms
42
timer
.start(timeout);
43
}
44
45
ExpiringArea
(
ExpiringArea
&&) =
default
;
46
ExpiringArea
(
ExpiringArea
const
& p) :
area
(p.
area
)
47
{
48
*
this
= p;
49
}
50
56
template
<
typename
Tile>
57
bool
ready
(
TileCacheDelay<Tile>
const
& cache)
const
58
{
59
if
(!
timer
.isActive())
60
{
61
return
true
;
62
}
63
64
return
cache.isAreaReady(
area
);
65
}
66
67
ExpiringArea
&
operator=
(
ExpiringArea
&&) =
default
;
68
69
ExpiringArea
&
operator=
(
ExpiringArea
const
& p)
70
{
71
area
= p.
area
;
72
73
// QTimer has no copy operator
74
if
(p.
timer
.isActive())
75
{
76
timer
.start(p.
timer
.remainingTime());
77
}
78
return
*
this
;
79
}
80
};
81
85
class
AreaHistory
86
{
88
std::vector<ExpiringArea>
history_
;
89
90
public
:
94
void
fit
(
Area
const
& area)
95
{
96
history_
.erase(std::remove_if(
history_
.begin(),
history_
.end(),
97
[&area](
ExpiringArea
const
& p) { return !areaContainsTile(p.area, area.center); }),
98
history_
.end());
99
}
100
106
void
add
(
Area
const
& area)
107
{
108
auto
const
it =
109
std::find_if(
history_
.begin(),
history_
.end(), [&area](
ExpiringArea
const
& p) { return p.area == area; });
110
if
(it ==
history_
.end())
111
{
112
history_
.emplace_back(area);
113
}
114
};
115
119
template
<
typename
Tile>
120
bool
ready
(
TileCacheDelay<Tile>
const
& cache,
TileId
const
& to_find)
const
121
{
122
return
std::any_of(
history_
.begin(),
history_
.end(), [&to_find, &cache](
ExpiringArea
const
& ea) {
123
return areaContainsTile(ea.area, to_find) && ea.ready(cache);
124
});
125
}
126
};
127
}
// namespace detail
128
148
template
<
typename
Tile>
149
class
TileCacheDelay
:
public
TileCache
<Tile>
150
{
151
detail::AreaHistory
history_
;
152
friend
detail::ExpiringArea
;
153
154
public
:
155
void
request
(
Area
const
& area)
156
{
157
TileCache<Tile>::request
(area);
158
159
history_
.
fit
(area);
160
history_
.
add
(area);
161
}
162
166
Tile
const
*
ready
(
TileId
const
& to_find)
const
167
{
168
Tile
const
* tile =
TileCache<Tile>::ready
(to_find);
169
if
(tile &&
history_
.
ready
(*
this
, to_find))
170
{
171
return
tile;
172
}
173
174
return
nullptr
;
175
}
176
};
tile_cache.h
detail::ExpiringArea::ready
bool ready(TileCacheDelay< Tile > const &cache) const
Definition:
tile_cache_delay.h:57
detail::AreaHistory::fit
void fit(Area const &area)
Definition:
tile_cache_delay.h:94
TileCache
A cache for tiles.
Definition:
tile_cache.h:61
detail
Definition:
error_rate_manager.h:19
detail::AreaHistory::history_
std::vector< ExpiringArea > history_
History of areas that will be or were drawn in Rviz.
Definition:
tile_cache_delay.h:88
TileCacheDelay::request
void request(Area const &area)
Definition:
tile_cache_delay.h:155
Area
Definition:
area.h:31
detail::AreaHistory
Definition:
tile_cache_delay.h:85
TileCacheDelay
Definition:
tile_cache_delay.h:24
TileCacheDelay::history_
detail::AreaHistory history_
Definition:
tile_cache_delay.h:151
detail::AreaHistory::add
void add(Area const &area)
Definition:
tile_cache_delay.h:106
TileCache::request
void request(Area const &area)
Definition:
tile_cache.h:90
detail::ExpiringArea::operator=
ExpiringArea & operator=(ExpiringArea const &p)
Definition:
tile_cache_delay.h:69
detail::ExpiringArea::timer
QTimer timer
Definition:
tile_cache_delay.h:35
TileCache::ready
Tile const * ready(TileId const &to_find) const
Definition:
tile_cache.h:112
TileId
Definition:
tile_id.h:31
std
TileCacheDelay::ready
Tile const * ready(TileId const &to_find) const
Definition:
tile_cache_delay.h:166
detail::AreaHistory::ready
bool ready(TileCacheDelay< Tile > const &cache, TileId const &to_find) const
Definition:
tile_cache_delay.h:120
detail::ExpiringArea::operator=
ExpiringArea & operator=(ExpiringArea &&)=default
detail::ExpiringArea::ExpiringArea
ExpiringArea(ExpiringArea const &p)
Definition:
tile_cache_delay.h:46
detail::ExpiringArea::ExpiringArea
ExpiringArea(Area area)
Definition:
tile_cache_delay.h:38
detail::ExpiringArea
Definition:
tile_cache_delay.h:33
detail::ExpiringArea::area
Area area
Definition:
tile_cache_delay.h:36
rviz_satellite
Author(s): Gareth Cross
, Andre Schröder
autogenerated on Thu May 4 2023 02:47:22