Change constants methods to static constexpr

This commit is contained in:
Stefan Müller 2025-01-21 14:03:40 +01:00
parent 0b72b7efdc
commit 0f60b23b33
6 changed files with 26 additions and 16 deletions

View File

@ -26,11 +26,11 @@ class GuardGallivant
virtual void processDataLine(const std::string& line) override;
virtual void finish() override;
private:
static constexpr size_t getStartDirectionIndex();
static constexpr char getStartChar();
static constexpr char getVisitedChar();
static constexpr char getObstructionChar();
Point2 start_{};
const size_t getStartDirectionIndex() const;
const char getStartChar() const;
const char getVisitedChar() const;
const char getObstructionChar() const;
void visitPosition(const Point2& current);
size_t turnDirection(const size_t current) const;
};

View File

@ -28,7 +28,7 @@ class HoofIt
virtual const std::string getInputFileName() const override;
virtual void finish() override;
private:
const char getTrailheadChar() const;
const char getTrailTopChar() const;
static constexpr char getTrailheadChar();
static constexpr char getTrailTopChar();
void addUnique(const std::vector<Point2>& source, std::vector<Point2>& destination);
};

View File

@ -30,8 +30,8 @@ class PrintQueue
virtual void processDataLine(const std::string& line) override;
virtual void finish() override;
private:
static const int nPages_{ 49 };
static const int maxPageNo_{ 99 };
static constexpr int getNPages();
static constexpr int getMaxPageNo();
bool isProcessingOrderingRules_;
int pageNoMapIndex_;
std::vector<int> pageNoMap_;

View File

@ -56,22 +56,22 @@ void GuardGallivant::finish()
}
}
const size_t GuardGallivant::getStartDirectionIndex() const
constexpr size_t GuardGallivant::getStartDirectionIndex()
{
return 2;
}
const char GuardGallivant::getStartChar() const
constexpr char GuardGallivant::getStartChar()
{
return '^';
}
const char GuardGallivant::getVisitedChar() const
constexpr char GuardGallivant::getVisitedChar()
{
return 'X';
}
const char GuardGallivant::getObstructionChar() const
constexpr char GuardGallivant::getObstructionChar()
{
return '#';
}

View File

@ -81,12 +81,12 @@ void HoofIt::finish()
}
}
const char HoofIt::getTrailheadChar() const
constexpr char HoofIt::getTrailheadChar()
{
return '0';
}
const char HoofIt::getTrailTopChar() const
constexpr char HoofIt::getTrailTopChar()
{
return '9';
}

View File

@ -20,8 +20,8 @@
#include <vector>
PrintQueue::PrintQueue()
: Solver{}, isProcessingOrderingRules_{ true }, pageNoMapIndex_{ 0 }, pageNoMap_(maxPageNo_ + 1, -1),
orderingRules_(nPages_, nPages_)
: Solver{}, isProcessingOrderingRules_{ true }, pageNoMapIndex_{ 0 }, pageNoMap_(getMaxPageNo() + 1, -1),
orderingRules_(getNPages(), getNPages())
{
orderingRules_.fill(false);
}
@ -59,6 +59,16 @@ void PrintQueue::finish()
{
}
constexpr int PrintQueue::getNPages()
{
return 49;
}
constexpr int PrintQueue::getMaxPageNo()
{
return 99;
}
size_t PrintQueue::getMapped(const int pageNo)
{
if (pageNoMap_[pageNo] < 0)