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

Places representation

parent c3bd15a6
......@@ -37,6 +37,8 @@ namespace Loco
const std::string &region_hint) const;
std::ostream &Print(std::ostream &os, bool global) const;
std::ostream &PrettyPrint(std::ostream &os, const std::string &sep) const;
std::string IdentString() const;
std::string IdentStringWithHint(const std::string &region_hint) const;
};
std::ostream &operator<<(std::ostream &os, const GlobalIdent &gi);
......
/*
* Train deadlock detection
* Project Masinky
*
* Petr Kucera, 2021
*/
/**@file places.cpp
* Representation of places for the model data
*/
#include "places.h"
Loco::SectionGroupPlace::SectionGroupPlace(
unsigned cg_id, std::vector<SectionConstPtr> sections)
: mSectionGroupId(cg_id), mSections(std::move(sections))
{
}
std::string
Loco::SectionGroupPlace::Desc() const
{
auto desc = kPrefix + "{";
if (!mSections.empty())
{
desc += mSections.front()->Ident().IdentString();
std::for_each(mSections.begin() + 1, mSections.end(),
[&desc](const auto &sect) {
desc += kArraySep + sect->Ident().IdentString();
});
}
desc += "}";
return desc;
}
Loco::TrainPlace::TrainPlace(bool enter, unsigned train_id, TrainConstPtr train)
: mEnter(enter), mTrainId(train_id), mTrain(std::move(train))
{
}
std::string
Loco::TrainPlace::Desc() const
{
return (mEnter ? kPrefixEnter : kPrefixLeave) + ":" + mTrain->Ident();
}
/*
* Train deadlock detection
* Project Masinky
*
* Petr Kucera, 2021
*/
/**@file places.h
* Representation of places for the model data
*/
#ifndef __PLACES_H
#define __PLACES_H
#include <string>
#include <variant>
#include "logical_desc.h"
#include "trains_desc.h"
namespace Loco
{
class SectionGroupPlace
{
public:
inline static const std::string kPrefix{"SG"};
private:
unsigned mSectionGroupId;
std::vector<SectionConstPtr> mSections;
public:
SectionGroupPlace(unsigned sg_id, std::vector<SectionConstPtr> sections);
std::string Ident() const;
std::string Desc() const;
const std::vector<SectionConstPtr> &Sections() const;
const SectionConstPtr &FrontSection() const;
bool SingleSection() const;
unsigned SectionGroupId() const;
};
class TrainPlace
{
public:
inline static const std::string kPrefixEnter{"TE"};
inline static const std::string kPrefixLeave{"TL"};
private:
bool mEnter;
unsigned mTrainId;
TrainConstPtr mTrain;
public:
TrainPlace(bool enter, unsigned train_id, TrainConstPtr train);
std::string Ident() const;
std::string Desc() const;
const TrainConstPtr &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>;
} // namespace Loco
inline auto
Loco::SectionGroupPlace::Sections() const
-> const std::vector<SectionConstPtr> &
{
return mSections;
}
inline auto
Loco::SectionGroupPlace::FrontSection() const -> const SectionConstPtr &
{
return mSections.front();
}
inline bool
Loco::SectionGroupPlace::SingleSection() const
{
return mSections.size() == 1;
}
inline unsigned
Loco::SectionGroupPlace::SectionGroupId() const
{
return mSectionGroupId;
}
inline std::string
Loco::SectionGroupPlace::Ident() const
{
return kPrefix + std::to_string(mSectionGroupId);
}
inline auto
Loco::TrainPlace::Train() const -> const TrainConstPtr &
{
return mTrain;
}
inline unsigned
Loco::TrainPlace::TrainId() const
{
return mTrainId;
}
inline std::string
Loco::TrainPlace::Ident() const
{
return (mEnter ? kPrefixEnter : kPrefixLeave) + std::to_string(mTrainId);
}
#endif
......@@ -21,7 +21,7 @@ namespace Loco
{
class TrafficPoint : public DataElement
{
std::vector<std::shared_ptr<const Section>> mSections{};
std::vector<SectionConstPtr> mSections{};
virtual std::ostream &
PrintData(std::ostream &os, const std::string &prefix,
......@@ -34,13 +34,15 @@ namespace Loco
}
TrafficPoint(GlobalIdent ident, std::string name,
std::vector<std::shared_ptr<const Section>> sections)
std::vector<SectionConstPtr> sections)
: DataElement(std::move(ident), std::move(name)),
mSections(std::move(sections))
{
}
};
using TrafficPointConstPtr = std::shared_ptr<const TrafficPoint>;
enum class StopKind
{
UNKNOWN,
......@@ -71,13 +73,13 @@ namespace Loco
{
// It has no identification, because it is identified with its traffic
// point
std::shared_ptr<const TrafficPoint> mTrafficPoint;
TrafficPointConstPtr mTrafficPoint;
std::string mName;
TrainStopSpec mSpec;
public:
TrainStop(std::shared_ptr<const TrafficPoint> traffic_point,
std::string name, TrainStopSpec spec)
TrainStop(TrafficPointConstPtr traffic_point, std::string name,
TrainStopSpec spec)
: mTrafficPoint(std::move(traffic_point)), mName(std::move(name)),
mSpec(std::move(spec))
{
......@@ -132,7 +134,8 @@ namespace Loco
}
};
using SectionTrainList = std::vector<std::shared_ptr<const Train>>;
using TrainConstPtr = std::shared_ptr<const Train>;
using SectionTrainList = std::vector<TrainConstPtr>;
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