From 000796dc3d909f179fb6586fae7e9ce986440576 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 28 Jan 2017 16:14:08 +0100 Subject: Avoid uninitialised fields, modernise DabService::nbComponent --- src/MuxElements.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/MuxElements.cpp') diff --git a/src/MuxElements.cpp b/src/MuxElements.cpp index 9dbe5fc..f8a3eb4 100644 --- a/src/MuxElements.cpp +++ b/src/MuxElements.cpp @@ -412,7 +412,7 @@ const string DabComponent::get_parameter(const string& parameter) const } -subchannel_type_t DabService::getType(std::shared_ptr ensemble) const +subchannel_type_t DabService::getType(const std::shared_ptr ensemble) const { vector::iterator subchannel; auto component = @@ -429,7 +429,7 @@ subchannel_type_t DabService::getType(std::shared_ptr ensemble) con return (*subchannel)->type; } -bool DabService::isProgramme(std::shared_ptr ensemble) const +bool DabService::isProgramme(const std::shared_ptr& ensemble) const { bool ret = false; switch (getType(ensemble)) { @@ -452,18 +452,14 @@ bool DabService::isProgramme(std::shared_ptr ensemble) const } -unsigned char DabService::nbComponent(vector& components) const +unsigned char DabService::nbComponent(const vector& components) const { - int nb = 0; - vector::iterator current; - - for (current = components.begin(); current != components.end(); - ++current) { - if ((*current)->serviceId == id) { - ++nb; - } + size_t count = std::count_if(components.begin(), components.end(), + [&](const DabComponent* c) { return c->serviceId == id;} ); + if (count > 0xFF) { + throw std::logic_error("Invalid number of components in service"); } - return nb; + return count; } void DabService::set_parameter(const string& parameter, -- cgit v1.2.3