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 | |
| 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>
| -rw-r--r-- | dbus/dbusconfiguration.cpp | 10 | ||||
| -rw-r--r-- | experiments/drive.cpp | 2 | ||||
| -rw-r--r-- | main.cpp | 2 | ||||
| -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 | ||||
| -rw-r--r-- | sensors/builder.cpp | 2 |
10 files changed, 33 insertions, 31 deletions
diff --git a/dbus/dbusconfiguration.cpp b/dbus/dbusconfiguration.cpp index be372af..93f9c1f 100644 --- a/dbus/dbusconfiguration.cpp +++ b/dbus/dbusconfiguration.cpp @@ -75,7 +75,7 @@ void debugPrint(void) // print sensor config std::cout << "sensor config:\n"; std::cout << "{\n"; - for (auto& pair : SensorConfig) + for (const auto& pair : SensorConfig) { std::cout << "\t{" << pair.first << ",\n\t\t{"; @@ -89,7 +89,7 @@ void debugPrint(void) std::cout << "}\n\n"; std::cout << "ZoneDetailsConfig\n"; std::cout << "{\n"; - for (auto& zone : ZoneDetailsConfig) + for (const auto& zone : ZoneDetailsConfig) { std::cout << "\t{" << zone.first << ",\n"; std::cout << "\t\t{" << zone.second.minthermalrpm << ", "; @@ -98,15 +98,15 @@ void debugPrint(void) std::cout << "}\n\n"; std::cout << "ZoneConfig\n"; std::cout << "{\n"; - for (auto& zone : ZoneConfig) + for (const auto& zone : ZoneConfig) { std::cout << "\t{" << zone.first << "\n"; - for (auto& pidconf : zone.second) + for (const auto& pidconf : zone.second) { std::cout << "\t\t{" << pidconf.first << ",\n"; std::cout << "\t\t\t{" << pidconf.second.type << ",\n"; std::cout << "\t\t\t{"; - for (auto& input : pidconf.second.inputs) + for (const auto& input : pidconf.second.inputs) { std::cout << "\n\t\t\t" << input << ",\n"; } diff --git a/experiments/drive.cpp b/experiments/drive.cpp index d73148a..3eed0a0 100644 --- a/experiments/drive.cpp +++ b/experiments/drive.cpp @@ -243,7 +243,7 @@ int driveMain(void) tstamp tp = t1; /* Output the values and the timepoints as a time series for review. */ - for (auto& t : series) + for (const auto& t : series) { tstamp ts = std::get<0>(t); int64_t n0 = std::get<1>(t); @@ -158,7 +158,7 @@ int main(int argc, char* argv[]) * however, a system isn't likely going to have more than a couple zones. * If it only has a couple zones, then this is fine. */ - for (auto& i : zones) + for (const auto& i : zones) { std::cerr << "pushing zone" << std::endl; zoneThreads.push_back(std::thread(PIDControlThread, i.second.get())); 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"; } diff --git a/sensors/builder.cpp b/sensors/builder.cpp index 881a9c2..7927dd0 100644 --- a/sensors/builder.cpp +++ b/sensors/builder.cpp @@ -42,7 +42,7 @@ SensorManager BuildSensors(const std::map<std::string, struct sensor>& config) auto& HostSensorBus = mgmr.getHostBus(); auto& PassiveListeningBus = mgmr.getPassiveBus(); - for (auto& it : config) + for (const auto& it : config) { std::unique_ptr<ReadInterface> ri; std::unique_ptr<WriteInterface> wi; |

