Skip to content

Commit

Permalink
* Update code to C++ 17
Browse files Browse the repository at this point in the history
  • Loading branch information
j-tag committed May 12, 2019
1 parent b4fc983 commit ed26085
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 37 deletions.
12 changes: 6 additions & 6 deletions CumulativeStatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@
**************************************************************************/
#include "CumulativeStatistics.hpp"

int CumulativeStatistics::busyTimeLoaders = 0;
int CumulativeStatistics::busyTimeScale = 0;
unsigned int CumulativeStatistics::busyTimeLoaders = 0;
unsigned int CumulativeStatistics::busyTimeScale = 0;


CumulativeStatistics::CumulativeStatistics()
{

}

void CumulativeStatistics::appendLoadersBusyTime(int time)
void CumulativeStatistics::appendLoadersBusyTime(unsigned int time)
{
CumulativeStatistics::busyTimeLoaders += time;
}

void CumulativeStatistics::appendScaleBusyTime(int time)
void CumulativeStatistics::appendScaleBusyTime(unsigned int time)
{
CumulativeStatistics::busyTimeScale += time;
}

int CumulativeStatistics::getLoadersBusyTime()
unsigned int CumulativeStatistics::getLoadersBusyTime()
{
return CumulativeStatistics::busyTimeLoaders;
}

int CumulativeStatistics::getScaleBusyTime()
unsigned int CumulativeStatistics::getScaleBusyTime()
{
return CumulativeStatistics::busyTimeScale;
}
Expand Down
12 changes: 6 additions & 6 deletions CumulativeStatistics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class CumulativeStatistics
{
public:
CumulativeStatistics();
static void appendLoadersBusyTime(int time);
static void appendScaleBusyTime(int time);
static int getLoadersBusyTime();
static int getScaleBusyTime();
static void appendLoadersBusyTime(unsigned int time);
static void appendScaleBusyTime(unsigned int time);
static unsigned int getLoadersBusyTime();
static unsigned int getScaleBusyTime();
static void clear();

private:
static int busyTimeLoaders;
static int busyTimeScale;
static unsigned int busyTimeLoaders;
static unsigned int busyTimeScale;
};

#endif // CUMULATIVESTATISTICS_HPP
2 changes: 1 addition & 1 deletion DialogCharts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void DialogCharts::initBusyChart()
this->chartBusy->setAnimationOptions(QChart::AllAnimations);

this->chartBusy->createDefaultAxes();
int max = qMax(CumulativeStatistics::getLoadersBusyTime(), CumulativeStatistics::getScaleBusyTime());
unsigned int max = qMax(CumulativeStatistics::getLoadersBusyTime(), CumulativeStatistics::getScaleBusyTime());
this->chartBusy->axes(Qt::Horizontal).back()->setRange(0, DataProvider::getCurrentClock());
this->chartBusy->axes(Qt::Horizontal).back()->setTitleText("Clock");
this->chartBusy->axes(Qt::Vertical).back()->setRange(0, max);
Expand Down
8 changes: 4 additions & 4 deletions DialogSimulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void DialogSimulation::initializeSimulationTable()
strLstHeaders << "Clock t" << "LQ(t)" << "L(t)" << "WQ(t)" << "W(t)" << "Loader Queue" << "Weigh Queue" << "Future Event List" << "B L" << "B S";
ui->tableWidgetSimulation->setHorizontalHeaderLabels(strLstHeaders);
QSettings settings;
ui->tableWidgetSimulation->setRowCount(settings.value("simulation/count").toUInt());
ui->tableWidgetSimulation->setRowCount(settings.value("simulation/count").toInt());


// Load past state
Expand Down Expand Up @@ -102,7 +102,7 @@ void DialogSimulation::executeSimulation()
LoadingQueue loadingQueue;
auto loadingQueueCount = settings.value("simulation/itemsInitialize/loadingQueue").toUInt();
for (unsigned int i = 0; i < loadingQueueCount; ++i) {
loadingQueue.addTruck(trucks.at(i));
loadingQueue.addTruck(trucks.at(int(i)));
}

// Loaders
Expand All @@ -111,7 +111,7 @@ void DialogSimulation::executeSimulation()
auto loaderCount = settings.value("simulation/itemsInitialize/loader").toUInt();
loaderCount += loadingQueueCount;
for (unsigned int i = loadingQueueCount; i < loaderCount; ++i) {
loaders.addTruck(trucks.at(i));
loaders.addTruck(trucks.at(int(i)));
}

// Weigh queue
Expand All @@ -120,7 +120,7 @@ void DialogSimulation::executeSimulation()
auto weighQueueCount = settings.value("simulation/itemsInitialize/weighQueue").toUInt();
weighQueueCount += loaderCount;
for (unsigned int i = loaderCount; i < weighQueueCount; ++i) {
weighQueue.addTruck(trucks.at(i));
weighQueue.addTruck(trucks.at(int(i)));
}

// Scale
Expand Down
2 changes: 1 addition & 1 deletion DialogSimulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DialogSimulation : public QDialog
enum Columns {
Clock, LQt, Lt, WQt, Wt, LoaderQueue, WeighQueue, FutureEventList, Bl, Bs
};
explicit DialogSimulation(QWidget *parent = 0);
explicit DialogSimulation(QWidget *parent = nullptr);
~DialogSimulation();

public slots:
Expand Down
4 changes: 2 additions & 2 deletions DumpTruck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
**************************************************************************/
#include "DumpTruck.hpp"

DumpTruck::DumpTruck(int index, QObject *parent) : QObject(parent), index(index)
DumpTruck::DumpTruck(unsigned int index, QObject *parent) : QObject(parent), index(index)
{

}
Expand All @@ -23,7 +23,7 @@ QString DumpTruck::getName() const
return "DT" + QString::number(this->index);
}

int DumpTruck::getIndex() const
unsigned int DumpTruck::getIndex() const
{
return this->index;
}
Expand Down
6 changes: 3 additions & 3 deletions DumpTruck.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ class DumpTruck : public QObject
enum State {
None, InLoaderQueue, Loading, InWeighQueue, Weighing, Traveling
};
explicit DumpTruck(int index, QObject *parent = nullptr);
explicit DumpTruck(unsigned int index, QObject *parent = nullptr);

void setState(State state);
QString getName() const;
int getIndex() const;
unsigned int getIndex() const;
State getState() const;

signals:

public slots:
private:
int index = -1;
unsigned int index = 0;
State state = None;
};

Expand Down
4 changes: 2 additions & 2 deletions FutureEventList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ Event *FutureEventList::getNextEvent()
return this->lstEvents.at(index);
}

Event *FutureEventList::atTruck(int truckIndex) const
Event *FutureEventList::atTruck(unsigned int truckIndex) const
{
if(this->lstEvents.isEmpty()) {
return nullptr;
}

for (int i = 0; i < this->lstEvents.size(); ++i) {
int index = this->lstEvents.at(i)->getTruck()->getIndex();
unsigned int index = this->lstEvents.at(i)->getTruck()->getIndex();

if(index == truckIndex) {
return this->lstEvents.at(i);
Expand Down
2 changes: 1 addition & 1 deletion FutureEventList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FutureEventList
void clear();
QString getString() const;
Event* getNextEvent();
Event* atTruck(int truckIndex) const;
Event* atTruck(unsigned int truckIndex) const;

signals:

Expand Down
4 changes: 3 additions & 1 deletion Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ bool Loader::addTruck(DumpTruck *truck)

truck->setState(DumpTruck::Loading);

short time = DataProvider::getRandomLoadingTime() + DataProvider::getCurrentClock();
unsigned int randomLoadingTime = uint(DataProvider::getRandomLoadingTime());

unsigned int time = randomLoadingTime + DataProvider::getCurrentClock();
Event *event = new Event(Event::EL, time, truck);
FutureEventList::getInstance()->addEvent(event);

Expand Down
14 changes: 7 additions & 7 deletions MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,18 @@ void MainWindow::saveData()
void MainWindow::loadData()
{
QSettings settings;
ui->spinBoxSimulationCount->setValue(settings.value("simulation/count").toUInt());
ui->spinBoxNumberOfTrucks->setValue(settings.value("simulation/itemsInitialize/trucks").toUInt());
ui->spinBoxNumberOfTrucksInLoadingQueue->setValue(settings.value("simulation/itemsInitialize/loadingQueue").toUInt());
ui->spinBoxNumberOfTrucksInLoaders->setValue(settings.value("simulation/itemsInitialize/loader").toUInt());
ui->spinBoxNumberOftrucksInWeighQueue->setValue(settings.value("simulation/itemsInitialize/weighQueue").toUInt());
ui->spinBoxSimulationCount->setValue(settings.value("simulation/count").toInt());
ui->spinBoxNumberOfTrucks->setValue(settings.value("simulation/itemsInitialize/trucks").toInt());
ui->spinBoxNumberOfTrucksInLoadingQueue->setValue(settings.value("simulation/itemsInitialize/loadingQueue").toInt());
ui->spinBoxNumberOfTrucksInLoaders->setValue(settings.value("simulation/itemsInitialize/loader").toInt());
ui->spinBoxNumberOftrucksInWeighQueue->setValue(settings.value("simulation/itemsInitialize/weighQueue").toInt());
ui->checkBoxTruckInScale->setChecked(settings.value("simulation/itemsInitialize/scale").toBool());
}

void MainWindow::on_pushButtonSimulation_clicked()
{
unsigned int numberOfTrucks = ui->spinBoxNumberOfTrucks->value();
unsigned int totalOtherTrucksCount = ui->spinBoxNumberOfTrucksInLoadingQueue->value();
int numberOfTrucks = ui->spinBoxNumberOfTrucks->value();
int totalOtherTrucksCount = ui->spinBoxNumberOfTrucksInLoadingQueue->value();
totalOtherTrucksCount += ui->spinBoxNumberOfTrucksInLoaders->value();
totalOtherTrucksCount += ui->spinBoxNumberOftrucksInWeighQueue->value();
totalOtherTrucksCount += ui->checkBoxTruckInScale->isChecked() ? 1 : 0;
Expand Down
2 changes: 1 addition & 1 deletion MainWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MainWindow : public QMainWindow
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();

private slots:
Expand Down
4 changes: 2 additions & 2 deletions Scale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ bool Scale::addTruck(DumpTruck *truck)
return false;
}
truck->setState(DumpTruck::Weighing);
int time = DataProvider::getRandomWeighingTime() + DataProvider::getCurrentClock();
unsigned int time = uint(DataProvider::getRandomWeighingTime()) + DataProvider::getCurrentClock();
Event *event = new Event(Event::EW, time, truck);
FutureEventList::getInstance()->addEvent(event);
return true;
Expand Down Expand Up @@ -68,7 +68,7 @@ void Scale::processEvents(WeighQueue &weighQueue)
if(event->getEventType() == Event::EW && event->getTime() == DataProvider::getCurrentClock()) {
CumulativeStatistics::appendScaleBusyTime(timePenalty);
// At this time, weighing is finished and we must add new event for ALQ and also clear scale
short time = DataProvider::getRandomTravelTime() + DataProvider::getCurrentClock();
auto time = uint(DataProvider::getRandomTravelTime()) + DataProvider::getCurrentClock();
Event *alqEvent = new Event(Event::ALQ, time, event->getTruck());
futureList->removeEvent(event);
futureList->addEvent(alqEvent);
Expand Down

0 comments on commit ed26085

Please sign in to comment.