Skip to content

Commit e87cec6

Browse files
committed
symbol cache: use iterator
1 parent c68bdd1 commit e87cec6

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

include/mapnik/symbol_cache.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ class symbol_cache : util::noncopyable
4646
box_type box;
4747
};
4848

49+
using container_type = std::map<std::string, symbol>;
50+
using iterator = container_type::const_iterator;
51+
4952
void insert(std::string const & key, box_type const & value);
50-
symbol const& get(std::string const & key) const;
51-
bool contains(std::string const & key) const;
53+
iterator end() const;
54+
iterator get(std::string const & key) const;
5255

5356
private:
54-
std::map<std::string, symbol> items;
57+
container_type items;
5558
};
5659

5760
}

src/symbol_cache.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ void symbol_cache::insert(std::string const & key, box_type const & box)
3131
items.emplace(key, box);
3232
}
3333

34-
symbol_cache::symbol const& symbol_cache::get(std::string const & key) const
34+
symbol_cache::iterator symbol_cache::end() const
3535
{
36-
return items.at(key);
36+
return items.end();
3737
}
3838

39-
bool symbol_cache::contains(std::string const & key) const
39+
symbol_cache::iterator symbol_cache::get(std::string const & key) const
4040
{
41-
return items.find(key) != items.end();
41+
return items.find(key);
4242
}
4343

4444
}

src/text/placements/angle.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,15 @@ text_placement_info_ptr text_placements_angle::get_placement_info(double scale_f
9898
{
9999
std::string anchor_key = util::apply_visitor(extract_value<std::string>(feature, vars),
100100
static_cast<symbolizer_base::value_type>(*anchor_key_));
101-
102-
if (sc.contains(anchor_key))
101+
symbol_cache::iterator sym = sc.get(anchor_key);
102+
if (sym == sc.end())
103103
{
104-
symbol_cache::symbol const& sym = sc.get(anchor_key);
105-
return std::make_shared<text_placement_info_angle>(this,
106-
feature, vars, scale_factor, angle, tolerance, step, sym.box, list_placement_info);
104+
return std::make_shared<text_placement_info_dummy>(this, scale_factor, 1);
107105
}
108106
else
109107
{
110-
return std::make_shared<text_placement_info_dummy>(this, scale_factor, 1);
108+
return std::make_shared<text_placement_info_angle>(this,
109+
feature, vars, scale_factor, angle, tolerance, step, sym->second.box, list_placement_info);
111110
}
112111
}
113112

src/text/placements/simple.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,16 @@ text_placement_info_ptr text_placements_simple::get_placement_info(double scale_
169169
if (anchor_key_)
170170
{
171171
std::string evaluated_anchor_key = util::apply_visitor(extract_value<std::string>(feature, vars), static_cast<symbolizer_base::value_type>(*anchor_key_));
172-
173-
if (sc.contains(evaluated_anchor_key))
172+
symbol_cache::iterator sym = sc.get(evaluated_anchor_key);
173+
if (sym == sc.end())
174174
{
175-
symbol_cache::symbol const& sym = sc.get(evaluated_anchor_key);
176-
// Add 0.5 to ensure boxes won't intersect.
177-
dx += sym.box.width() / 2.0 + .5;
178-
dy += sym.box.height() / 2.0 + .5;
175+
return std::make_shared<text_placement_info_dummy>(this, scale_factor, 1);
179176
}
180177
else
181178
{
182-
return std::make_shared<text_placement_info_dummy>(this, scale_factor, 1);
179+
// Add 0.5 to ensure boxes won't intersect.
180+
dx += sym->second.box.width() / 2.0 + .5;
181+
dy += sym->second.box.height() / 2.0 + .5;
183182
}
184183
}
185184

0 commit comments

Comments
 (0)