Privatized Map constructor, only MapBuilder can create an instance of it
This commit is contained in:
parent
3a09b56ac4
commit
8735f750df
|
@ -10,12 +10,12 @@ namespace carla {
|
|||
namespace road {
|
||||
|
||||
bool Map::ExistId(id_type id) const {
|
||||
return _sections.count(id);
|
||||
return _elements.count(id);
|
||||
}
|
||||
|
||||
const RoadElement *Map::GetRoad(id_type id) {
|
||||
if (ExistId(id)) {
|
||||
return _sections.find(id)->second.get();
|
||||
return _elements.find(id)->second.get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -30,13 +30,15 @@ namespace road {
|
|||
T &MakeElement(id_type id, Args && ... args) {
|
||||
auto inst = std::make_unique<T>(std::forward<Args>(args) ...);
|
||||
T &r = *inst;
|
||||
_sections.emplace(id, std::move(inst));
|
||||
_elements.emplace(id, std::move(inst));
|
||||
return r;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::map<id_type, std::unique_ptr<RoadElement>> _sections;
|
||||
friend class MapBuilder;
|
||||
Map() {}
|
||||
std::map<id_type, std::unique_ptr<RoadElement>> _elements;
|
||||
};
|
||||
|
||||
} // namespace road
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace road {
|
|||
const Map &MapBuilder::Build() {
|
||||
|
||||
for (auto &&seg : _temp_sections) {
|
||||
map.MakeElement<RoadSegment>(seg.first, seg.second);
|
||||
map.MakeElement<RoadSegment>(seg.first, std::move(seg.second));
|
||||
}
|
||||
|
||||
return map;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
namespace carla {
|
||||
namespace road {
|
||||
|
||||
using temp_section_type = std::multimap<id_type, RoadSegmentDefinition &>;
|
||||
using temp_section_type = std::map<id_type, RoadSegmentDefinition &>;
|
||||
|
||||
class MapBuilder {
|
||||
public:
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "RoadElement.h"
|
||||
#include "carla/geom/Location.h"
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
|
@ -21,8 +21,13 @@ namespace element {
|
|||
class RoadSegment : public RoadElement {
|
||||
public:
|
||||
|
||||
RoadSegment() : _id(-1) {}
|
||||
RoadSegment(const RoadSegmentDefinition &def) : _id(def.GetId()) {}
|
||||
RoadSegment(RoadSegmentDefinition &&def)
|
||||
: _id(def.GetId()),
|
||||
_geom(std::move(def._geom)) {
|
||||
for (auto &&a : def._info) {
|
||||
_info.insert(std::move(a));
|
||||
}
|
||||
}
|
||||
|
||||
id_type GetId() const {
|
||||
return _id;
|
||||
|
@ -41,11 +46,20 @@ namespace element {
|
|||
|
||||
private:
|
||||
|
||||
struct LessComp {
|
||||
using is_transparent = void;
|
||||
bool operator()(
|
||||
const std::unique_ptr<RoadInfo> &a,
|
||||
const std::unique_ptr<RoadInfo> &b) const {
|
||||
return a->d < b->d;
|
||||
}
|
||||
};
|
||||
|
||||
id_type _id;
|
||||
std::vector<RoadSegment *> _next_list;
|
||||
std::vector<RoadSegment *> _prev_list;
|
||||
std::vector<std::unique_ptr<Geometry>> geom;
|
||||
std::multimap<double, std::unique_ptr<RoadInfo>> _info_list;
|
||||
std::vector<RoadSegment *> _predecessors;
|
||||
std::vector<RoadSegment *> _successors;
|
||||
std::vector<std::unique_ptr<Geometry>> _geom;
|
||||
std::multiset<std::unique_ptr<RoadInfo>, LessComp> _info;
|
||||
};
|
||||
|
||||
} // namespace element
|
||||
|
|
|
@ -35,15 +35,15 @@ namespace element {
|
|||
_geom(std::move(rsd._geom)),
|
||||
_info(std::move(rsd._info)) {}
|
||||
|
||||
const id_type &GetId() const {
|
||||
return _id;
|
||||
}
|
||||
|
||||
RoadSegmentDefinition(id_type id) {
|
||||
assert(id > 0);
|
||||
_id = id;
|
||||
}
|
||||
|
||||
const id_type &GetId() const {
|
||||
return _id;
|
||||
}
|
||||
|
||||
void AddPredecessorID(const id_type &id) {
|
||||
_predecessor_id.emplace_back(id);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ namespace element {
|
|||
}
|
||||
|
||||
private:
|
||||
|
||||
friend class RoadSegment;
|
||||
id_type _id;
|
||||
std::vector<id_type> _predecessor_id;
|
||||
std::vector<id_type> _successor_id;
|
||||
|
|
Loading…
Reference in New Issue