diff options
| author | Patrick Venture <venture@google.com> | 2018-10-23 09:02:55 -0700 |
|---|---|---|
| committer | Patrick Venture <venture@google.com> | 2018-10-23 09:21:43 -0700 |
| commit | 4a2dc4d89a8efc42da57db7d3c3fb9e850e8fb1b (patch) | |
| tree | 8f3124e4c3c0fed65a69d7146df892ee2a5e7bdc /pid | |
| parent | d8a9a19e5a1c1a343cd6f10a58b0eee937bebeca (diff) | |
| download | phosphor-pid-control-4a2dc4d89a8efc42da57db7d3c3fb9e850e8fb1b.tar.gz phosphor-pid-control-4a2dc4d89a8efc42da57db7d3c3fb9e850e8fb1b.zip | |
cleanup: apply constness to read-only iterators
Apply const to read-only iterators to indicate intent more clearly.
Change-Id: Ic14304c69361da203d3d3a900180bd54346acc87
Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'pid')
| -rw-r--r-- | pid/builder.cpp | 16 | ||||
| -rw-r--r-- | pid/fancontroller.cpp | 4 | ||||
| -rw-r--r-- | pid/fancontroller.hpp | 5 | ||||
| -rw-r--r-- | pid/thermalcontroller.cpp | 2 | ||||
| -rw-r--r-- | pid/thermalcontroller.hpp | 5 | ||||
| -rw-r--r-- | pid/zone.cpp | 16 |
6 files changed, 25 insertions, 23 deletions
diff --git a/pid/builder.cpp b/pid/builder.cpp index e98ba22..1e7a737 100644 --- a/pid/builder.cpp +++ b/pid/builder.cpp @@ -42,7 +42,7 @@ std::unordered_map<int64_t, std::unique_ptr<PIDZone>> { std::unordered_map<int64_t, std::unique_ptr<PIDZone>> zones; - for (auto& zi : zonePids) + for (const auto& zi : zonePids) { auto zoneId = static_cast<int64_t>(zi.first); /* The above shouldn't be necessary but is, and I am having trouble @@ -60,7 +60,7 @@ std::unordered_map<int64_t, std::unique_ptr<PIDZone>> throw std::runtime_error(err); } - PIDConf& PIDConfig = zi.second; + const PIDConf& PIDConfig = zi.second; auto zone = std::make_unique<PIDZone>( zoneId, zoneConf->second.minthermalrpm, @@ -70,11 +70,11 @@ std::unordered_map<int64_t, std::unique_ptr<PIDZone>> std::cerr << "Zone Id: " << zone->getZoneId() << "\n"; // For each PID create a Controller and a Sensor. - for (auto& pit : PIDConfig) + for (const auto& pit : PIDConfig) { std::vector<std::string> inputs; std::string name = pit.first; - struct controller_info* info = &pit.second; + const struct controller_info* info = &pit.second; std::cerr << "PID name: " << name << "\n"; @@ -84,7 +84,7 @@ std::unordered_map<int64_t, std::unique_ptr<PIDZone>> */ if (info->type == "fan") { - for (auto i : info->inputs) + for (const auto& i : info->inputs) { inputs.push_back(i); zone->addFanInput(i); @@ -96,7 +96,7 @@ std::unordered_map<int64_t, std::unique_ptr<PIDZone>> } else if (info->type == "temp" || info->type == "margin") { - for (auto i : info->inputs) + for (const auto& i : info->inputs) { inputs.push_back(i); zone->addThermalInput(i); @@ -109,7 +109,7 @@ std::unordered_map<int64_t, std::unique_ptr<PIDZone>> } else if (info->type == "stepwise") { - for (auto& i : info->inputs) + for (const auto& i : info->inputs) { inputs.push_back(i); zone->addThermalInput(i); @@ -120,7 +120,7 @@ std::unordered_map<int64_t, std::unique_ptr<PIDZone>> } std::cerr << "inputs: "; - for (auto& i : inputs) + for (const auto& i : inputs) { std::cerr << i << ", "; } diff --git a/pid/fancontroller.cpp b/pid/fancontroller.cpp index b1c923f..f085927 100644 --- a/pid/fancontroller.cpp +++ b/pid/fancontroller.cpp @@ -24,7 +24,7 @@ std::unique_ptr<PIDController> FanController::CreateFanPid(ZoneInterface* owner, const std::string& id, - std::vector<std::string>& inputs, + const std::vector<std::string>& inputs, ec::pidinfo initial) { if (inputs.size() == 0) @@ -130,7 +130,7 @@ void FanController::output_proc(float value) percent /= 100; // PidSensorMap for writing. - for (auto& it : _inputs) + for (const auto& it : _inputs) { auto sensor = _owner->getSensor(it); sensor->write(static_cast<double>(percent)); diff --git a/pid/fancontroller.hpp b/pid/fancontroller.hpp index 521d638..c081ce1 100644 --- a/pid/fancontroller.hpp +++ b/pid/fancontroller.hpp @@ -18,9 +18,10 @@ class FanController : public PIDController public: static std::unique_ptr<PIDController> CreateFanPid(ZoneInterface* owner, const std::string& id, - std::vector<std::string>& inputs, ec::pidinfo initial); + const std::vector<std::string>& inputs, + ec::pidinfo initial); - FanController(const std::string& id, std::vector<std::string>& inputs, + FanController(const std::string& id, const std::vector<std::string>& inputs, ZoneInterface* owner) : PIDController(id, owner), _inputs(inputs), _direction(FanSpeedDirection::NEUTRAL) diff --git a/pid/thermalcontroller.cpp b/pid/thermalcontroller.cpp index 1422bef..d7ea5ae 100644 --- a/pid/thermalcontroller.cpp +++ b/pid/thermalcontroller.cpp @@ -21,7 +21,7 @@ std::unique_ptr<PIDController> ThermalController::CreateThermalPid( ZoneInterface* owner, const std::string& id, - std::vector<std::string>& inputs, float setpoint, ec::pidinfo initial) + const std::vector<std::string>& inputs, float setpoint, ec::pidinfo initial) { // ThermalController currently only supports precisely one input. if (inputs.size() != 1) diff --git a/pid/thermalcontroller.hpp b/pid/thermalcontroller.hpp index 85c3a2b..e38938f 100644 --- a/pid/thermalcontroller.hpp +++ b/pid/thermalcontroller.hpp @@ -16,10 +16,11 @@ class ThermalController : public PIDController public: static std::unique_ptr<PIDController> CreateThermalPid(ZoneInterface* owner, const std::string& id, - std::vector<std::string>& inputs, float setpoint, + const std::vector<std::string>& inputs, float setpoint, ec::pidinfo initial); - ThermalController(const std::string& id, std::vector<std::string>& inputs, + ThermalController(const std::string& id, + const std::vector<std::string>& inputs, ZoneInterface* owner) : PIDController(id, owner), _inputs(inputs) diff --git a/pid/zone.cpp b/pid/zone.cpp index 35abb13..ab5cc8c 100644 --- a/pid/zone.cpp +++ b/pid/zone.cpp @@ -163,11 +163,11 @@ void PIDZone::initializeLog(void) _log << "epoch_ms,setpt"; - for (auto& f : _fanInputs) + for (const auto& f : _fanInputs) { _log << "," << f; } - for (auto& t : _thermalInputs) + for (const auto& t : _thermalInputs) { _log << "," << t; } @@ -210,7 +210,7 @@ void PIDZone::updateFanTelemetry(void) _log << "," << _maximumRPMSetPt; #endif - for (auto& f : _fanInputs) + for (const auto& f : _fanInputs) { auto sensor = _mgr.getSensor(f); ReadReturn r = sensor->read(); @@ -227,7 +227,7 @@ void PIDZone::updateFanTelemetry(void) } #ifdef __TUNING_LOGGING__ - for (auto& t : _thermalInputs) + for (const auto& t : _thermalInputs) { _log << "," << _cachedValuesByName[t]; } @@ -242,7 +242,7 @@ void PIDZone::updateSensors(void) /* margin and temp are stored as temp */ tstamp now = high_resolution_clock::now(); - for (auto& t : _thermalInputs) + for (const auto& t : _thermalInputs) { auto sensor = _mgr.getSensor(t); ReadReturn r = sensor->read(); @@ -285,12 +285,12 @@ void PIDZone::updateSensors(void) void PIDZone::initializeCache(void) { - for (auto& f : _fanInputs) + for (const auto& f : _fanInputs) { _cachedValuesByName[f] = 0; } - for (auto& t : _thermalInputs) + for (const auto& t : _thermalInputs) { _cachedValuesByName[t] = 0; @@ -302,7 +302,7 @@ void PIDZone::initializeCache(void) void PIDZone::dumpCache(void) { std::cerr << "Cache values now: \n"; - for (auto& k : _cachedValuesByName) + for (const auto& k : _cachedValuesByName) { std::cerr << k.first << ": " << k.second << "\n"; } |

