Skip to content

Commit bcf6644

Browse files
committed
Rename all private class members
1 parent d9e8f6b commit bcf6644

16 files changed

+134
-132
lines changed

rest/controller/MeterReadingController.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ auto renderReadingAsJson(const ElectricityReading &r) {
3838
class MeterReadingController {
3939
public:
4040
MeterReadingController(ElectricityReadingService &electricityReadingService, MeterReadingService &meterReadingService)
41-
: electricityReadingService(electricityReadingService), meterReadingService(meterReadingService) {}
41+
: electricityReadingService_(electricityReadingService), meterReadingService_(meterReadingService) {}
4242

4343
http::response<http::string_body> Read(const http::request<http::string_body> &req, const std::vector<std::string> &queries) {
4444
const auto &meterId = queries[0];
45-
auto readings = electricityReadingService.GetReading(meterId);
45+
auto readings = electricityReadingService_.GetReading(meterId);
4646

4747
if (!readings) {
4848
return {http::status::not_found, req.version()};
@@ -70,13 +70,13 @@ class MeterReadingController {
7070
for (auto &electricityReading : body["electricityReadings"]) {
7171
electricityReadings.emplace_back(detail::fromRfc3339(electricityReading["time"]), electricityReading["reading"]);
7272
}
73-
meterReadingService.storeReadings(smartMeterId, electricityReadings);
73+
meterReadingService_.storeReadings(smartMeterId, electricityReadings);
7474
return {};
7575
}
7676

7777
private:
78-
ElectricityReadingService &electricityReadingService;
79-
MeterReadingService &meterReadingService;
78+
ElectricityReadingService &electricityReadingService_;
79+
MeterReadingService &meterReadingService_;
8080
bool IsMeterReadingsValid(const nlohmann::basic_json<> &smartMeterId,
8181
const nlohmann::basic_json<> &electricityReadings) {
8282
if (smartMeterId.type() == nlohmann::json::value_t::null || electricityReadings.empty()) {

rest/controller/PricePlanComparatorController.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ namespace http = boost::beast::http;
1616

1717
class PricePlanComparatorController {
1818
public:
19-
PricePlanComparatorController(PricePlanService &pricePlanService) : pricePlanService(pricePlanService) {}
19+
PricePlanComparatorController(PricePlanService &pricePlanService) : pricePlanService_(pricePlanService) {}
2020

2121
http::response<http::string_body> Compare(const http::request<http::string_body> &req,
2222
const std::vector<std::string> &queries) {
2323
const auto &meterId = queries[0];
24-
auto costs = pricePlanService.getConsumptionCostOfElectricityReadingsForEachPricePlan(meterId);
24+
auto costs = pricePlanService_.getConsumptionCostOfElectricityReadingsForEachPricePlan(meterId);
2525

2626
if (!costs) {
2727
return {http::status::not_found, req.version()};
@@ -48,7 +48,7 @@ class PricePlanComparatorController {
4848
if (queries.size() > 2){
4949
maybeLimit = std::stoi(queries[2]);
5050
}
51-
auto costs = pricePlanService.getConsumptionCostOfElectricityReadingsForEachPricePlan(meterId);
51+
auto costs = pricePlanService_.getConsumptionCostOfElectricityReadingsForEachPricePlan(meterId);
5252

5353
if (!costs) {
5454
return {http::status::not_found, req.version()};
@@ -76,7 +76,7 @@ class PricePlanComparatorController {
7676
}
7777

7878
private:
79-
PricePlanService &pricePlanService;
79+
PricePlanService &pricePlanService_;
8080
};
8181

8282
#endif // DEVELOPER_JOYOFENERGY_CPP_BEAST_PRICEPLANCOMPARATORCONTROLLER_H

rest/domain/ElectricityReading.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ class ElectricityReading {
88
public:
99
using time_point_type = std::chrono::time_point<std::chrono::system_clock>;
1010

11-
ElectricityReading(time_point_type time, size_t reading) : time(time), reading(reading) {}
11+
ElectricityReading(time_point_type time, size_t reading) : time_(time), reading_(reading) {}
1212

13-
time_point_type getTime() const { return time; }
13+
time_point_type getTime() const { return time_; }
1414

15-
size_t getReading() const { return reading; }
15+
size_t getReading() const { return reading_; }
1616

17-
bool operator==(const ElectricityReading& rhs) const { return time == rhs.time && reading == rhs.reading; }
17+
bool operator==(const ElectricityReading& rhs) const { return time_ == rhs.time_ && reading_ == rhs.reading_; }
1818
bool operator!=(const ElectricityReading& rhs) const { return !(rhs == *this); }
1919

2020
private:
21-
time_point_type time;
22-
size_t reading; // scale out in 0.1w for precision
21+
time_point_type time_;
22+
size_t reading_; // scale out in 0.1w for precision
2323
};
2424

2525
#endif // DEVELOPER_JOYOFENERGY_CPP_BEAST_ELECTRICITYREADING_H

rest/domain/MeterReadings.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ class MeterReadings {
1111
MeterReadings() {}
1212

1313
MeterReadings(std::string smartMeterId, std::list<ElectricityReading> electricityReadings)
14-
: smartMeterId(smartMeterId), electricityReadings(electricityReadings){};
14+
: smartMeterId_(smartMeterId), electricityReadings_(electricityReadings){};
1515

16-
std::list<ElectricityReading> getElectricityReadings() { return electricityReadings; }
16+
std::list<ElectricityReading> getElectricityReadings() { return electricityReadings_; }
1717

18-
std::string getSmartMeterId() { return smartMeterId; }
18+
std::string getSmartMeterId() { return smartMeterId_; }
1919

2020
private:
21-
std::list<ElectricityReading> electricityReadings;
22-
std::string smartMeterId;
21+
std::list<ElectricityReading> electricityReadings_;
22+
std::string smartMeterId_;
2323
};
2424

2525
#endif // DEVELOPER_JOYOFENERGY_CPP_BEAST_METERREADINGS_H

rest/domain/PricePlan.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,33 @@ class PricePlan {
2929
};
3030

3131
PricePlan(std::string planName, std::string energySupplier, int unitRate, std::vector<PeakTimeMultiplier> peakTimeMultipliers)
32-
: planName(std::move(planName)), energySupplier(std::move(energySupplier)), unitRate(unitRate), peakTimeMultipliers(std::move(peakTimeMultipliers)) {}
32+
: planName_(std::move(planName)),
33+
energySupplier_(std::move(energySupplier)),
34+
unitRate_(unitRate),
35+
peakTimeMultipliers_(std::move(peakTimeMultipliers)) {}
3336

34-
std::string getEnergySupplier() const { return energySupplier; }
37+
std::string getEnergySupplier() const { return energySupplier_; }
3538

36-
std::string getPlanName() const { return planName; }
39+
std::string getPlanName() const { return planName_; }
3740

38-
int getUnitRate() const { return unitRate; }
41+
int getUnitRate() const { return unitRate_; }
3942

4043
int getPrice(time_point_type dateTime) const {
4144
auto time_t_dateTime = std::chrono::system_clock::to_time_t(dateTime);
4245
auto t = std::localtime(&time_t_dateTime);
43-
auto it = std::find_if(peakTimeMultipliers.begin(), peakTimeMultipliers.end(), [=](auto &p) {
44-
return p.dayOfWeek == t->tm_wday;
45-
});
46-
if (it == peakTimeMultipliers.end()) {
47-
return unitRate;
46+
auto it = std::find_if(peakTimeMultipliers_.begin(), peakTimeMultipliers_.end(),
47+
[=](auto &p) { return p.dayOfWeek == t->tm_wday; });
48+
if (it == peakTimeMultipliers_.end()) {
49+
return unitRate_;
4850
}
49-
return unitRate * it->multiplier;
51+
return unitRate_ * it->multiplier;
5052
}
5153

5254
private:
53-
const std::string energySupplier;
54-
const std::string planName;
55-
const int unitRate; // unit price per kWh
56-
const std::vector<PeakTimeMultiplier> peakTimeMultipliers;
55+
const std::string energySupplier_;
56+
const std::string planName_;
57+
const int unitRate_; // unit price per kWh
58+
const std::vector<PeakTimeMultiplier> peakTimeMultipliers_;
5759
};
5860

5961
#endif // DEVELOPER_JOYOFENERGY_CPP_BEAST_PRICEPLAN_H

rest/listener.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class listener : public std::enable_shared_from_this<listener> {
1313
public:
1414
listener(io_context &ioc, tcp::endpoint endpoint,
1515
std::function<http::response<http::string_body>(const http::request<http::string_body> &)> &handler)
16-
: ioc_(ioc), acceptor_(boost::asio::make_strand(ioc)), handler(handler) {
16+
: ioc_(ioc), acceptor_(boost::asio::make_strand(ioc)), handler_(handler) {
1717
error_code ec;
1818

1919
acceptor_.open(endpoint.protocol(), ec);
@@ -53,14 +53,14 @@ class listener : public std::enable_shared_from_this<listener> {
5353
if (ec) {
5454
fail(ec, "accept");
5555
} else {
56-
std::make_shared<session>(std::move(socket), handler)->run();
56+
std::make_shared<session>(std::move(socket), handler_)->run();
5757
}
5858
do_accept();
5959
}
6060

6161
io_context &ioc_;
6262
tcp::acceptor acceptor_;
63-
std::function<http::response<http::string_body>(const http::request<http::string_body> &)> &handler;
63+
std::function<http::response<http::string_body>(const http::request<http::string_body> &)> &handler_;
6464
};
6565

6666
#endif // DEVELOPER_JOYOFENERGY_CPP_BEAST_LISTENER_H

rest/server.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,53 @@
1010
namespace server_detail {
1111
class impl {
1212
public:
13-
explicit impl(int concurrency) : ioc(concurrency) {
13+
explicit impl(int concurrency) : ioc_(concurrency) {
1414
using reading = MeterReadingController;
1515
using price_plan = PricePlanComparatorController;
16-
router.to<reading, &reading::Read>(R"(/readings/read/([a-zA-Z0-9_-]+))", electricityReadingService, meterReadingService);
17-
router.to<reading, &reading::Store>(R"(/readings/store)", electricityReadingService, meterReadingService);
18-
router.to<price_plan, &price_plan::Compare>(R"(/price-plans/compare-all/([a-zA-Z0-9_-]+))", pricePlanService);
19-
router.to<price_plan, &price_plan::Recommend>(R"(/price-plans/recommend/([a-zA-Z0-9_-]+)\?(limit)=([0-9]+))",
20-
pricePlanService);
16+
router_.to<reading, &reading::Read>(R"(/readings/read/([a-zA-Z0-9_-]+))", electricityReadingService_, meterReadingService);
17+
router_.to<reading, &reading::Store>(R"(/readings/store)", electricityReadingService_, meterReadingService);
18+
router_.to<price_plan, &price_plan::Compare>(R"(/price-plans/compare-all/([a-zA-Z0-9_-]+))", pricePlanService_);
19+
router_.to<price_plan, &price_plan::Recommend>(R"(/price-plans/recommend/([a-zA-Z0-9_-]+)\?(limit)=([0-9]+))",
20+
pricePlanService_);
2121
}
2222

2323
void launch(const char *address, unsigned short port) {
2424
using tcp = boost::asio::ip::tcp;
2525
auto endpoint = tcp::endpoint{boost::asio::ip::make_address(address), port};
26-
std::make_shared<listener>(ioc, endpoint, handler)->run();
26+
std::make_shared<listener>(ioc_, endpoint, handler)->run();
2727
}
2828

29-
void run() { ioc.run(); }
29+
void run() { ioc_.run(); }
3030

31-
void stop() { ioc.stop(); }
31+
void stop() { ioc_.stop(); }
3232

3333
private:
34-
boost::asio::io_context ioc;
35-
std::unordered_map<std::string, std::vector<ElectricityReading>> meterAssociatedReadings{readings()};
36-
ElectricityReadingService electricityReadingService{meterAssociatedReadings};
37-
MeterReadingService meterReadingService{meterAssociatedReadings};
38-
std::vector<PricePlan> price_plans{pricePlans()};
39-
PricePlanService pricePlanService{price_plans, meterReadingService};
40-
router router;
41-
std::function<http::response<http::string_body>(const http::request<http::string_body> &)> handler = router.handler();
34+
boost::asio::io_context ioc_;
35+
std::unordered_map<std::string, std::vector<ElectricityReading>> meterAssociatedReadings_{readings()};
36+
ElectricityReadingService electricityReadingService_{meterAssociatedReadings_};
37+
MeterReadingService meterReadingService{meterAssociatedReadings_};
38+
std::vector<PricePlan> price_plans_{pricePlans()};
39+
PricePlanService pricePlanService_{price_plans_, meterReadingService};
40+
router router_;
41+
std::function<http::response<http::string_body>(const http::request<http::string_body> &)> handler = router_.handler();
4242
};
4343
} // namespace server_detail
4444

45-
server::server(int concurrency) : impl(std::make_unique<server_detail::impl>(concurrency)), concurrency(concurrency) {}
45+
server::server(int concurrency) : impl_(std::make_unique<server_detail::impl>(concurrency)), concurrency_(concurrency) {}
4646

4747
server::~server() {
48-
impl->stop();
49-
for (auto &worker : threads) {
48+
impl_->stop();
49+
for (auto &worker : threads_) {
5050
if (worker.joinable()) {
5151
worker.join();
5252
}
5353
}
5454
}
5555

5656
void server::run(const char *address, unsigned short port) {
57-
impl->launch(address, port);
58-
threads.reserve(concurrency);
59-
for (auto i = concurrency; i > 0; --i) {
60-
threads.emplace_back([this] { impl->run(); });
57+
impl_->launch(address, port);
58+
threads_.reserve(concurrency_);
59+
for (auto i = concurrency_; i > 0; --i) {
60+
threads_.emplace_back([this] { impl_->run(); });
6161
}
6262
}

rest/server.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class server {
1818
void run(const char *address, unsigned short port);
1919

2020
private:
21-
std::unique_ptr<server_detail::impl> impl;
22-
int concurrency;
23-
std::vector<std::thread> threads;
21+
std::unique_ptr<server_detail::impl> impl_;
22+
int concurrency_;
23+
std::vector<std::thread> threads_;
2424
};
2525

2626
#endif // DEVELOPER_JOYOFENERGY_CPP_BEAST_SERVER_H

rest/service/ElectricityReadingService.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
class ElectricityReadingService {
1212
public:
1313
ElectricityReadingService(std::unordered_map<std::string, std::vector<ElectricityReading>> &meterAssociatedReadings)
14-
: meterAssociatedReadings(meterAssociatedReadings) {}
14+
: meterAssociatedReadings_(meterAssociatedReadings) {}
1515

1616
std::optional<std::vector<ElectricityReading>> GetReading(const std::string &meterId) {
17-
auto found = meterAssociatedReadings.find(meterId);
18-
if (found != meterAssociatedReadings.end()) {
17+
auto found = meterAssociatedReadings_.find(meterId);
18+
if (found != meterAssociatedReadings_.end()) {
1919
return found->second;
2020
}
2121
return {};
2222
}
2323

2424
private:
25-
std::unordered_map<std::string, std::vector<ElectricityReading>> &meterAssociatedReadings;
25+
std::unordered_map<std::string, std::vector<ElectricityReading>> &meterAssociatedReadings_;
2626
};
2727

2828
#endif // DEVELOPER_JOYOFENERGY_CPP_ELECTRICITYREADINGSERVICE_H

rest/service/MeterReadingService.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,28 @@
1919
class MeterReadingService {
2020
public:
2121
std::optional<std::vector<ElectricityReading>> getReadings(const std::string &smartMeterId) {
22-
std::shared_lock<std::shared_mutex> lock(mtx);
23-
if (meterAssociatedReadings.find(smartMeterId) == meterAssociatedReadings.end()) {
22+
std::shared_lock<std::shared_mutex> lock(mtx_);
23+
if (meterAssociatedReadings_.find(smartMeterId) == meterAssociatedReadings_.end()) {
2424
return {};
2525
}
26-
return meterAssociatedReadings[smartMeterId];
26+
return meterAssociatedReadings_[smartMeterId];
2727
}
2828

2929
void storeReadings(const std::string &smartMeterId, std::vector<ElectricityReading> &electricityReadings) {
30-
std::unique_lock<std::shared_mutex> lock(mtx);
31-
if (meterAssociatedReadings.find(smartMeterId) == meterAssociatedReadings.end()) {
32-
meterAssociatedReadings[smartMeterId] = {};
30+
std::unique_lock<std::shared_mutex> lock(mtx_);
31+
if (meterAssociatedReadings_.find(smartMeterId) == meterAssociatedReadings_.end()) {
32+
meterAssociatedReadings_[smartMeterId] = {};
3333
}
34-
meterAssociatedReadings[smartMeterId].insert(meterAssociatedReadings[smartMeterId].end(), electricityReadings.begin(),
35-
electricityReadings.end());
34+
meterAssociatedReadings_[smartMeterId].insert(meterAssociatedReadings_[smartMeterId].end(), electricityReadings.begin(),
35+
electricityReadings.end());
3636
}
3737

3838
explicit MeterReadingService(std::unordered_map<std::string, std::vector<ElectricityReading>> &meterAssociatedReadings)
39-
: meterAssociatedReadings(meterAssociatedReadings) {}
39+
: meterAssociatedReadings_(meterAssociatedReadings) {}
4040

4141
private:
42-
std::unordered_map<std::string, std::vector<ElectricityReading>> &meterAssociatedReadings;
43-
mutable std::shared_mutex mtx;
42+
mutable std::shared_mutex mtx_;
43+
std::unordered_map<std::string, std::vector<ElectricityReading>> &meterAssociatedReadings_;
4444
};
4545

4646
#endif // DEVELOPER_JOYOFENERGY_CPP_BEAST_METERREADINGSERVICE_H

0 commit comments

Comments
 (0)