32 lines
872 B
C++
32 lines
872 B
C++
//
|
|
// Created by stani on 3/10/2025.
|
|
//
|
|
|
|
#include "CostPipeline.h"
|
|
|
|
|
|
void CostPipeline::addCostComponent(const std::shared_ptr<ICostComponent> &components) {
|
|
this->components.push_back(components);
|
|
}
|
|
|
|
void CostPipeline::calculateFinalCost() {
|
|
for (size_t i = 0; i < this->components.size() - 1; i++) {
|
|
iterateCommunity(this->components[i]);
|
|
}
|
|
// Ensure CalculateFinalSums is last
|
|
iterateCommunity(this->components.back());
|
|
}
|
|
|
|
|
|
void CostPipeline::iterateCommunity(std::shared_ptr<ICostComponent> &component) const {
|
|
for (auto &community: this->communities) {
|
|
iterateBuilding(community, component);
|
|
}
|
|
}
|
|
|
|
void CostPipeline::iterateBuilding(std::unique_ptr<Community> &community, std::shared_ptr<ICostComponent> &component) {
|
|
for (auto &building: community->buildings()) {
|
|
component->apply(building, community);
|
|
}
|
|
}
|