aboutsummaryrefslogtreecommitdiffstats
path: root/src/MuxElements.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2017-01-28 16:14:08 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2017-01-28 16:14:08 +0100
commit000796dc3d909f179fb6586fae7e9ce986440576 (patch)
treea6b08f5866af7d5943052d18b7162ba3ed897d37 /src/MuxElements.cpp
parentaf782e67db704d1d58c265fb4e1ff12aa1526596 (diff)
downloaddabmux-000796dc3d909f179fb6586fae7e9ce986440576.tar.gz
dabmux-000796dc3d909f179fb6586fae7e9ce986440576.tar.bz2
dabmux-000796dc3d909f179fb6586fae7e9ce986440576.zip
Avoid uninitialised fields, modernise DabService::nbComponent
Diffstat (limited to 'src/MuxElements.cpp')
-rw-r--r--src/MuxElements.cpp20
1 files changed, 8 insertions, 12 deletions
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<dabEnsemble> ensemble) const
+subchannel_type_t DabService::getType(const std::shared_ptr<dabEnsemble> ensemble) const
{
vector<DabSubchannel*>::iterator subchannel;
auto component =
@@ -429,7 +429,7 @@ subchannel_type_t DabService::getType(std::shared_ptr<dabEnsemble> ensemble) con
return (*subchannel)->type;
}
-bool DabService::isProgramme(std::shared_ptr<dabEnsemble> ensemble) const
+bool DabService::isProgramme(const std::shared_ptr<dabEnsemble>& ensemble) const
{
bool ret = false;
switch (getType(ensemble)) {
@@ -452,18 +452,14 @@ bool DabService::isProgramme(std::shared_ptr<dabEnsemble> ensemble) const
}
-unsigned char DabService::nbComponent(vector<DabComponent*>& components) const
+unsigned char DabService::nbComponent(const vector<DabComponent*>& components) const
{
- int nb = 0;
- vector<DabComponent*>::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,