Commit 002269fe authored by Kučera Petr RNDr. Ph.D.'s avatar Kučera Petr RNDr. Ph.D.
Browse files

Renamed *ConstPtr -> *CPtr

parent 687207b2
......@@ -30,7 +30,7 @@ namespace Loco
public:
struct Position
{
EdgeConstPtr edge = nullptr;
EdgeCPtr edge = nullptr;
int offset = 0;
length_type Offset() const;
......@@ -69,7 +69,7 @@ namespace Loco
}
};
using PointConstPtr = std::shared_ptr<const Point>;
using PointCPtr = std::shared_ptr<const Point>;
class Section : public DataElement
{
......@@ -87,7 +87,7 @@ namespace Loco
private:
Data mData;
std::vector<PointConstPtr> mPoints;
std::vector<PointCPtr> mPoints;
virtual std::ostream &
PrintData(std::ostream &os, const std::string &prefix,
......@@ -95,37 +95,37 @@ namespace Loco
public:
Section(GlobalIdent ident, std::string name, const Data &data,
const std::vector<PointConstPtr> &points)
const std::vector<PointCPtr> &points)
: DataElement(std::move(ident), std::move(name)),
mData(std::move(data)), mPoints(points)
{
}
Section(GlobalIdent ident, std::string name, Data &&data,
std::vector<PointConstPtr> &&points)
std::vector<PointCPtr> &&points)
: DataElement(std::move(ident), std::move(name)),
mData(std::move(data)), mPoints(std::move(points))
{
}
const std::vector<PointConstPtr> &
const std::vector<PointCPtr> &
Points() const
{
return mPoints;
}
};
using SectionConstPtr = std::shared_ptr<const Section>;
using SectionCPtr = std::shared_ptr<const Section>;
class Indicator : public DataElement
{
SectionConstPtr mSection;
SectionCPtr mSection;
virtual std::ostream &
PrintData(std::ostream &os, const std::string &prefix,
const std::string &region_hint) const override;
public:
Indicator(GlobalIdent ident, std::string name, SectionConstPtr section)
Indicator(GlobalIdent ident, std::string name, SectionCPtr section)
: DataElement(std::move(ident), std::move(name)),
mSection(std::move(section))
{
......@@ -133,7 +133,7 @@ namespace Loco
};
class EntryPoint : public DataElement
{
SectionConstPtr mSection;
SectionCPtr mSection;
std::vector<Indicator> mIndicators;
virtual std::ostream &
......@@ -144,7 +144,7 @@ namespace Loco
virtual unsigned Level() const override;
public:
EntryPoint(GlobalIdent ident, std::string name, SectionConstPtr section,
EntryPoint(GlobalIdent ident, std::string name, SectionCPtr section,
std::vector<Indicator> indicators)
: DataElement(std::move(ident), std::move(name)),
mSection(std::move(section)), mIndicators(std::move(indicators))
......
......@@ -55,7 +55,7 @@ Loco::LogicalGraph::SortEdgePoints(EdgePoints edge_points) -> EdgePoints
for (auto &[edge, point_list] : edge_points)
{
std::sort(point_list.begin(), point_list.end(),
[](const PointConstPtr &a, const PointConstPtr &b) {
[](const PointCPtr &a, const PointCPtr &b) {
return a->GetPosition().offset < b->GetPosition().offset;
});
}
......@@ -63,15 +63,15 @@ Loco::LogicalGraph::SortEdgePoints(EdgePoints edge_points) -> EdgePoints
}
void
Loco::LogicalGraph::AddNeighbour(unsigned a, unsigned b,
const EdgeConstPtr &edge, length_type dist)
Loco::LogicalGraph::AddNeighbour(unsigned a, unsigned b, const EdgeCPtr &edge,
length_type dist)
{
mNeighbours[a].emplace_back(edge, b, true, dist);
mNeighbours[b].emplace_back(edge, a, false, dist);
}
void
Loco::LogicalGraph::AddEdge(const EdgeConstPtr &edge)
Loco::LogicalGraph::AddEdge(const EdgeCPtr &edge)
{
AddNeighbour(mNodeId.at(edge->From()), mNodeId.at(edge->To()), edge,
edge->Length());
......@@ -79,8 +79,7 @@ Loco::LogicalGraph::AddEdge(const EdgeConstPtr &edge)
}
void
Loco::LogicalGraph::AddPathOfEdge(const EdgeConstPtr &edge,
const PointList &points)
Loco::LogicalGraph::AddPathOfEdge(const EdgeCPtr &edge, const PointList &points)
{
AddNeighbour(mNodeId.at(edge->From()), mPointId.at(points.front()), edge,
points.front()->Offset());
......@@ -176,19 +175,19 @@ Loco::LogicalGraph::InitPointIds(const InputData &data)
}
auto
Loco::LogicalGraph::NodeWithId(unsigned id) const -> const NodeConstPtr &
Loco::LogicalGraph::NodeWithId(unsigned id) const -> const NodeCPtr &
{
return mNodes[id];
}
auto
Loco::LogicalGraph::PointWithId(unsigned id) const -> const PointConstPtr &
Loco::LogicalGraph::PointWithId(unsigned id) const -> const PointCPtr &
{
return mPoints[id - mNodes.size()];
}
auto
Loco::LogicalGraph::FindSectionVertices(const SectionConstPtr &sect) const
Loco::LogicalGraph::FindSectionVertices(const SectionCPtr &sect) const
-> std::pair<std::vector<Vertex>, length_type>
{
auto [vertex_id, len] = FindInnerVertices(VerticesOfPoints(sect->Points()));
......@@ -201,8 +200,7 @@ Loco::LogicalGraph::FindSectionVertices(const SectionConstPtr &sect) const
}
std::vector<unsigned>
Loco::LogicalGraph::VerticesOfPoints(
const std::vector<PointConstPtr> &points) const
Loco::LogicalGraph::VerticesOfPoints(const std::vector<PointCPtr> &points) const
{
std::vector<unsigned> vertices;
vertices.reserve(points.size());
......@@ -284,7 +282,7 @@ Loco::LogicalGraph::FindInnerVertices(
auto
Loco::LogicalGraph::VertexWithId(unsigned id) const
-> std::variant<NodeConstPtr, PointConstPtr>
-> std::variant<NodeCPtr, PointCPtr>
{
if (id < mNodes.size())
{
......@@ -296,9 +294,9 @@ Loco::LogicalGraph::VertexWithId(unsigned id) const
auto
Loco::LogicalGraph::VertexIdent(const Vertex &v) -> const GlobalIdent &
{
if (std::holds_alternative<PointConstPtr>(v))
if (std::holds_alternative<PointCPtr>(v))
{
return std::get<PointConstPtr>(v)->Ident();
return std::get<PointCPtr>(v)->Ident();
}
return std::get<NodeConstPtr>(v)->Ident();
return std::get<NodeCPtr>(v)->Ident();
}
......@@ -34,39 +34,38 @@ namespace Loco
public:
struct Neighbour
{
EdgeConstPtr mEdge{};
EdgeCPtr mEdge{};
unsigned mVertexId{};
bool mForward{};
length_type mDistance{};
Neighbour() = default;
Neighbour(EdgeConstPtr e, unsigned vertex_id, bool fw,
length_type dist)
Neighbour(EdgeCPtr e, unsigned vertex_id, bool fw, length_type dist)
: mEdge(std::move(e)), mVertexId(std::move(vertex_id)),
mForward(fw), mDistance(dist)
{
}
};
using PointList = std::vector<PointConstPtr>;
using EdgePoints = std::unordered_map<EdgeConstPtr, PointList>;
using Vertex = std::variant<NodeConstPtr, PointConstPtr>;
using PointList = std::vector<PointCPtr>;
using EdgePoints = std::unordered_map<EdgeCPtr, PointList>;
using Vertex = std::variant<NodeCPtr, PointCPtr>;
private:
std::vector<std::vector<Neighbour>> mNeighbours;
std::vector<NodeConstPtr> mNodes;
std::vector<PointConstPtr> mPoints;
std::unordered_map<NodeConstPtr, unsigned> mNodeId;
std::unordered_map<PointConstPtr, unsigned> mPointId;
std::vector<NodeCPtr> mNodes;
std::vector<PointCPtr> mPoints;
std::unordered_map<NodeCPtr, unsigned> mNodeId;
std::unordered_map<PointCPtr, unsigned> mPointId;
static EdgePoints BuildEdgePoints(const InputData &data);
static EdgePoints SortEdgePoints(EdgePoints edge_points);
void InitNodeIds(const InputData &data);
void InitPointIds(const InputData &data);
const NodeConstPtr &NodeWithId(unsigned id) const;
const PointConstPtr &PointWithId(unsigned id) const;
const NodeCPtr &NodeWithId(unsigned id) const;
const PointCPtr &PointWithId(unsigned id) const;
Vertex VertexWithId(unsigned id) const;
unsigned
......@@ -75,9 +74,9 @@ namespace Loco
return mNodes.size() + mPoints.size();
}
void AddPathOfEdge(const EdgeConstPtr &edge, const PointList &points);
void AddEdge(const EdgeConstPtr &edge);
void AddNeighbour(unsigned a, unsigned b, const EdgeConstPtr &edge,
void AddPathOfEdge(const EdgeCPtr &edge, const PointList &points);
void AddEdge(const EdgeCPtr &edge);
void AddNeighbour(unsigned a, unsigned b, const EdgeCPtr &edge,
length_type dist);
void Build(const InputData &data);
......@@ -87,7 +86,7 @@ namespace Loco
const Neighbour &nb) const;
std::vector<unsigned>
VerticesOfPoints(const std::vector<PointConstPtr> &points) const;
VerticesOfPoints(const std::vector<PointCPtr> &points) const;
std::pair<std::vector<unsigned>, length_type>
FindInnerVertices(const std::vector<unsigned> &border_vertices) const;
......@@ -97,7 +96,7 @@ namespace Loco
std::ostream &PrintGraph(std::ostream &os) const;
std::pair<std::vector<Vertex>, length_type>
FindSectionVertices(const SectionConstPtr &sect) const;
FindSectionVertices(const SectionCPtr &sect) const;
static const GlobalIdent &VertexIdent(const Vertex &v);
};
......
......@@ -38,21 +38,21 @@ namespace Loco
using DataElement::DataElement;
};
using NodeConstPtr = std::shared_ptr<const Node>;
using NodeCPtr = std::shared_ptr<const Node>;
class Edge : public DataElement
{
public:
struct Data
{
NodeConstPtr from_node = nullptr;
NodeConstPtr to_node = nullptr;
NodeCPtr from_node = nullptr;
NodeCPtr to_node = nullptr;
length_type len = 0;
};
private:
NodeConstPtr mFrom;
NodeConstPtr mTo;
NodeCPtr mFrom;
NodeCPtr mTo;
length_type mLength;
virtual std::ostream &
......@@ -77,22 +77,22 @@ namespace Loco
{
return mLength;
}
NodeConstPtr From() const;
NodeConstPtr To() const;
NodeCPtr From() const;
NodeCPtr To() const;
};
using EdgeConstPtr = std::shared_ptr<const Edge>;
using EdgeCPtr = std::shared_ptr<const Edge>;
} // namespace Loco
inline auto
Loco::Edge::From() const -> NodeConstPtr
Loco::Edge::From() const -> NodeCPtr
{
return mFrom;
}
inline auto
Loco::Edge::To() const -> NodeConstPtr
Loco::Edge::To() const -> NodeCPtr
{
return mTo;
}
......
......@@ -10,8 +10,8 @@
#include "places.h"
Loco::SectionGroupPlace::SectionGroupPlace(
unsigned cg_id, std::vector<SectionConstPtr> sections)
Loco::SectionGroupPlace::SectionGroupPlace(unsigned cg_id,
std::vector<SectionCPtr> sections)
: mSectionGroupId(cg_id), mSections(std::move(sections))
{
}
......@@ -34,7 +34,7 @@ Loco::SectionGroupPlace::Print(std::ostream &os,
return os;
}
Loco::TrainPlace::TrainPlace(bool enter, unsigned train_id, TrainConstPtr train)
Loco::TrainPlace::TrainPlace(bool enter, unsigned train_id, TrainCPtr train)
: mEnter(enter), mTrainId(train_id), mTrain(std::move(train))
{
}
......
......@@ -27,16 +27,16 @@ namespace Loco
private:
unsigned mSectionGroupId;
std::vector<SectionConstPtr> mSections;
std::vector<SectionCPtr> mSections;
public:
SectionGroupPlace(unsigned sg_id, std::vector<SectionConstPtr> sections);
SectionGroupPlace(unsigned sg_id, std::vector<SectionCPtr> sections);
std::string Ident() const;
std::ostream &Print(std::ostream &os, const std::string &prefix) const;
const std::vector<SectionConstPtr> &Sections() const;
const SectionConstPtr &FrontSection() const;
const std::vector<SectionCPtr> &Sections() const;
const SectionCPtr &FrontSection() const;
bool SingleSection() const;
unsigned SectionGroupId() const;
};
......@@ -50,32 +50,31 @@ namespace Loco
private:
bool mEnter;
unsigned mTrainId;
TrainConstPtr mTrain;
TrainCPtr mTrain;
public:
TrainPlace(bool enter, unsigned train_id, TrainConstPtr train);
TrainPlace(bool enter, unsigned train_id, TrainCPtr train);
std::string Ident() const;
std::string Desc() const;
const TrainConstPtr &Train() const;
const TrainCPtr &Train() const;
unsigned TrainId() const;
};
using SGPlaceConstPtr = std::shared_ptr<const SectionGroupPlace>;
using TPlaceConstPtr = std::shared_ptr<const TrainPlace>;
using Place = std::variant<SGPlaceConstPtr, TPlaceConstPtr>;
using SGPlaceCPtr = std::shared_ptr<const SectionGroupPlace>;
using TPlaceCPtr = std::shared_ptr<const TrainPlace>;
using Place = std::variant<SGPlaceCPtr, TPlaceCPtr>;
} // namespace Loco
inline auto
Loco::SectionGroupPlace::Sections() const
-> const std::vector<SectionConstPtr> &
Loco::SectionGroupPlace::Sections() const -> const std::vector<SectionCPtr> &
{
return mSections;
}
inline auto
Loco::SectionGroupPlace::FrontSection() const -> const SectionConstPtr &
Loco::SectionGroupPlace::FrontSection() const -> const SectionCPtr &
{
return mSections.front();
}
......@@ -99,7 +98,7 @@ Loco::SectionGroupPlace::Ident() const
}
inline auto
Loco::TrainPlace::Train() const -> const TrainConstPtr &
Loco::TrainPlace::Train() const -> const TrainCPtr &
{
return mTrain;
}
......
......@@ -46,18 +46,18 @@ Loco::SectionGraph::InitSectionInfo(const InputData &data,
void
Loco::SectionGraph::AddInfoForSection(const LogicalGraph &logical_graph,
SectionConstPtr sect)
SectionCPtr sect)
{
auto [vertices, len] = logical_graph.FindSectionVertices(sect);
mSectionId[sect] = mSections.size();
for (const auto &v : vertices)
{
if (std::holds_alternative<PointConstPtr>(v))
if (std::holds_alternative<PointCPtr>(v))
{
mPointSections[std::get<PointConstPtr>(v)].push_back(mSections.size());
mPointSections[std::get<PointCPtr>(v)].push_back(mSections.size());
continue;
}
mNodeSections[std::get<NodeConstPtr>(v)].push_back(mSections.size());
mNodeSections[std::get<NodeCPtr>(v)].push_back(mSections.size());
}
mSections.emplace_back(std::move(sect), std::move(vertices), len);
}
......@@ -227,7 +227,7 @@ Loco::SectionGraph::BuildPlaces()
mPlaces.reserve(mConflictGroups.size());
for (unsigned cg_id = 0; cg_id < mConflictGroups.size(); ++cg_id)
{
std::vector<SectionConstPtr> sections;
std::vector<SectionCPtr> sections;
for (const auto &sect_id : mConflictGroups[cg_id])
{
sections.push_back(mSections[sect_id].mSection);
......@@ -238,7 +238,7 @@ Loco::SectionGraph::BuildPlaces()
}
auto
Loco::SectionGraph::PlaceOfSection(unsigned section_id) const -> SGPlaceConstPtr
Loco::SectionGraph::PlaceOfSection(unsigned section_id) const -> SGPlaceCPtr
{
return mPlaces[mSections[section_id].mConflictGroupId];
}
......@@ -293,22 +293,21 @@ Loco::SectionGraph::PrintConflictGroups(std::ostream &os) const
}
auto
Loco::SectionGraph::GetSubgraph(
const std::vector<SectionConstPtr> &sources,
const std::vector<SectionConstPtr> &targets) const -> Subgraph
Loco::SectionGraph::GetSubgraph(const std::vector<SectionCPtr> &sources,
const std::vector<SectionCPtr> &targets) const
-> Subgraph
{
return GetSubgraphWithIds(SectionIds(sources), SectionIds(targets));
}
std::vector<unsigned>
Loco::SectionGraph::SectionIds(
const std::vector<SectionConstPtr> &sections) const
Loco::SectionGraph::SectionIds(const std::vector<SectionCPtr> &sections) const
{
std::vector<unsigned> sect_id;
sect_id.reserve(sections.size());
std::transform(
sections.begin(), sections.end(), std::back_inserter(sect_id),
[this](const SectionConstPtr &sect) { return mSectionId.at(sect); });
[this](const SectionCPtr &sect) { return mSectionId.at(sect); });
return sect_id;
}
......
......@@ -27,7 +27,7 @@ namespace Loco
public:
struct SectionInfo
{
SectionConstPtr mSection{};
SectionCPtr mSection{};
std::vector<LogicalGraph::Vertex> mVertices{};
length_type mLength;
unsigned mConflictGroupId{};
......@@ -35,7 +35,7 @@ namespace Loco
std::vector<unsigned> mConflicts;
SectionInfo() = default;
SectionInfo(SectionConstPtr sect,
SectionInfo(SectionCPtr sect,
std::vector<LogicalGraph::Vertex> vertices,
length_type len)
: mSection(std::move(sect)), mVertices(std::move(vertices)),
......@@ -64,14 +64,14 @@ namespace Loco
private:
std::vector<SectionInfo> mSections;
std::unordered_map<SectionConstPtr, unsigned> mSectionId;
std::unordered_map<SectionCPtr, unsigned> mSectionId;
std::vector<std::vector<unsigned>> mConflictGroups;
std::unordered_map<NodeConstPtr, std::vector<unsigned>> mNodeSections;
std::unordered_map<PointConstPtr, std::vector<unsigned>> mPointSections;
std::vector<SGPlaceConstPtr> mPlaces;
std::unordered_map<NodeCPtr, std::vector<unsigned>> mNodeSections;
std::unordered_map<PointCPtr, std::vector<unsigned>> mPointSections;
std::vector<SGPlaceCPtr> mPlaces;
void AddInfoForSection(const LogicalGraph &logical_graph,
SectionConstPtr sect);
SectionCPtr sect);
void InitSectionInfo(const InputData &data,
const LogicalGraph &logical_graph);
......@@ -89,14 +89,14 @@ namespace Loco
void ChangeIdOfConflictGroup(unsigned old_id, unsigned new_id);
void CompressConflictGroups();
void BuildPlaces();
SGPlaceConstPtr PlaceOfSection(unsigned section_id) const;
SGPlaceCPtr PlaceOfSection(unsigned section_id) const;
std::vector<unsigned>
SectionIds(const std::vector<SectionConstPtr> &sect) const;
SectionIds(const std::vector<SectionCPtr> &sect) const;
std::ostream &PrintVertices(std::ostream &os) const;
Subgraph GetSubgraphWithIds(std::vector<unsigned> sources,
std::vector<unsigned> targets) const;
Subgraph GetSubgraph(const std::vector<SectionConstPtr> &sources,
const std::vector<SectionConstPtr> &targets) const;
Subgraph GetSubgraph(const std::vector<SectionCPtr> &sources,
const std::vector<SectionCPtr> &targets) const;
public:
SectionGraph(const InputData &data, const LogicalGraph &logical_graph)
......@@ -113,8 +113,8 @@ namespace Loco
std::ostream &PrintConflictGroups(std::ostream &os) const;
};
using SectionGraphConstPtr = std::shared_ptr<const SectionGraph>;
using SGSubgraphConstPtr = std::shared_ptr<const SectionGraph::Subgraph>;
using SectionGraphCPtr = std::shared_ptr<const SectionGraph>;
using SGSubgraphCPtr = std::shared_ptr<const SectionGraph::Subgraph>;
} // namespace Loco
......
......@@ -21,7 +21,7 @@ namespace Loco
{
class TrafficPoint : public DataElement
{
std::vector<SectionConstPtr> mSections{};
std::vector<SectionCPtr> mSections{};
virtual std::ostream &
PrintData(std::ostream &os, const std::string &prefix,
......@@ -34,14 +34,14 @@ namespace Loco
}
TrafficPoint(GlobalIdent ident, std::string name,
std::vector<SectionConstPtr> sections)
std::vector<SectionCPtr> sections)
: DataElement(std::move(ident), std::move(name)),
mSections(std::move(sections))
{
}
};
using TrafficPointConstPtr = std::shared_ptr<const TrafficPoint>;
using TrafficPointCPtr = std::shared_ptr<const TrafficPoint>;
enum class StopKind
{
......@@ -73,12 +73,12 @@ namespace Loco
{
// It has no identification, because it is identified with its traffic
// point
TrafficPointConstPtr mTrafficPoint;
TrafficPointCPtr mTrafficPoint;
std::string mName;
TrainStopSpec mSpec;
public:
TrainStop(TrafficPointConstPtr traffic_point, std::string name,
TrainStop(TrafficPointCPtr traffic_point, std::string name,
TrainStopSpec spec)
: mTrafficPoint(std::move(traffic_point)), mName(std::move(name)),
mSpec(std::move(spec))
......@@ -134,8 +134,8 @@ namespace Loco
}
};
using TrainConstPtr = std::shared_ptr<const Train>;
using SectionTrainList = std::vector<TrainConstPtr>;
using TrainCPtr = std::shared_ptr<const Train>;
using SectionTrainList = std::vector<TrainCPtr>;
using TrainList = std::map<unsigned, SectionTrainList>;
} // namespace Loco
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment