aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2015-08-01 17:41:55 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2015-08-01 17:41:55 +0200
commit07f5c0fbfb43b099fa09b273a1074093c7579903 (patch)
tree48a2b759b46aaa483ab238d679cc172a97bdff82 /src
parentdd22ff8c7ab0ec2fae413431b7d546d2bf9367ea (diff)
downloaddabmod-07f5c0fbfb43b099fa09b273a1074093c7579903.tar.gz
dabmod-07f5c0fbfb43b099fa09b273a1074093c7579903.tar.bz2
dabmod-07f5c0fbfb43b099fa09b273a1074093c7579903.zip
Replace some loops with iterators to foreach loops
Diffstat (limited to 'src')
-rw-r--r--src/DabModulator.cpp47
-rw-r--r--src/EtiReader.cpp17
-rw-r--r--src/EtiReader.h7
-rw-r--r--src/Flowgraph.cpp16
-rw-r--r--src/Log.cpp6
-rw-r--r--src/RemoteControl.cpp32
-rw-r--r--src/RemoteControl.h35
7 files changed, 61 insertions, 99 deletions
diff --git a/src/DabModulator.cpp b/src/DabModulator.cpp
index 92f0acb..f55d918 100644
--- a/src/DabModulator.cpp
+++ b/src/DabModulator.cpp
@@ -261,13 +261,11 @@ int DabModulator::process(Buffer* const dataIn, Buffer* dataOut)
// Configuring puncturing encoder
shared_ptr<PuncturingEncoder> ficPunc(new PuncturingEncoder());
- std::vector<PuncturingRule*> rules = fic->get_rules();
- std::vector<PuncturingRule*>::const_iterator rule;
- for (rule = rules.begin(); rule != rules.end(); ++rule) {
+ for (const auto *rule : fic->get_rules()) {
PDEBUG(" Adding rule:\n");
- PDEBUG(" Length: %zu\n", (*rule)->length());
- PDEBUG(" Pattern: 0x%x\n", (*rule)->pattern());
- ficPunc->append_rule(*(*rule));
+ PDEBUG(" Length: %zu\n", rule->length());
+ PDEBUG(" Pattern: 0x%x\n", rule->pattern());
+ ficPunc->append_rule(*rule);
}
PDEBUG(" Adding tail\n");
ficPunc->append_tail_rule(PuncturingRule(3, 0xcccccc));
@@ -282,16 +280,13 @@ int DabModulator::process(Buffer* const dataIn, Buffer* dataOut)
////////////////////////////////////////////////////////////////
std::vector<shared_ptr<SubchannelSource> > subchannels =
myEtiReader.getSubchannels();
- std::vector<shared_ptr<SubchannelSource> >::const_iterator subchannel;
- for (subchannel = subchannels.begin();
- subchannel != subchannels.end();
- ++subchannel) {
+ for (const auto& subchannel : subchannels) {
////////////////////////////////////////////////////////////
// Data initialisation
////////////////////////////////////////////////////////////
- size_t subchSizeIn = (*subchannel)->framesize();
- size_t subchSizeOut = (*subchannel)->framesizeCu() * 8;
+ size_t subchSizeIn = subchannel->framesize();
+ size_t subchSizeOut = subchannel->framesizeCu() * 8;
////////////////////////////////////////////////////////////
// Modules configuration
@@ -300,20 +295,20 @@ int DabModulator::process(Buffer* const dataIn, Buffer* dataOut)
// Configuring subchannel
PDEBUG("Subchannel:\n");
PDEBUG(" Start address: %zu\n",
- (*subchannel)->startAddress());
+ subchannel->startAddress());
PDEBUG(" Framesize: %zu\n",
- (*subchannel)->framesize());
- PDEBUG(" Bitrate: %zu\n", (*subchannel)->bitrate());
+ subchannel->framesize());
+ PDEBUG(" Bitrate: %zu\n", subchannel->bitrate());
PDEBUG(" Framesize CU: %zu\n",
- (*subchannel)->framesizeCu());
+ subchannel->framesizeCu());
PDEBUG(" Protection: %zu\n",
- (*subchannel)->protection());
+ subchannel->protection());
PDEBUG(" Form: %zu\n",
- (*subchannel)->protectionForm());
+ subchannel->protectionForm());
PDEBUG(" Level: %zu\n",
- (*subchannel)->protectionLevel());
+ subchannel->protectionLevel());
PDEBUG(" Option: %zu\n",
- (*subchannel)->protectionOption());
+ subchannel->protectionOption());
// Configuring prbs genrerator
shared_ptr<PrbsGenerator> subchPrbs(
@@ -327,13 +322,11 @@ int DabModulator::process(Buffer* const dataIn, Buffer* dataOut)
shared_ptr<PuncturingEncoder> subchPunc(
new PuncturingEncoder());
- std::vector<PuncturingRule*> rules = (*subchannel)->get_rules();
- std::vector<PuncturingRule*>::const_iterator rule;
- for (rule = rules.begin(); rule != rules.end(); ++rule) {
+ for (const auto& rule : subchannel->get_rules()) {
PDEBUG(" Adding rule:\n");
- PDEBUG(" Length: %zu\n", (*rule)->length());
- PDEBUG(" Pattern: 0x%x\n", (*rule)->pattern());
- subchPunc->append_rule(*(*rule));
+ PDEBUG(" Length: %zu\n", rule->length());
+ PDEBUG(" Pattern: 0x%x\n", rule->pattern());
+ subchPunc->append_rule(*rule);
}
PDEBUG(" Adding tail\n");
subchPunc->append_tail_rule(PuncturingRule(3, 0xcccccc));
@@ -342,7 +335,7 @@ int DabModulator::process(Buffer* const dataIn, Buffer* dataOut)
shared_ptr<TimeInterleaver> subchInterleaver(
new TimeInterleaver(subchSizeOut));
- myFlowgraph->connect(*subchannel, subchPrbs);
+ myFlowgraph->connect(subchannel, subchPrbs);
myFlowgraph->connect(subchPrbs, subchConv);
myFlowgraph->connect(subchConv, subchPunc);
myFlowgraph->connect(subchPunc, subchInterleaver);
diff --git a/src/EtiReader.cpp b/src/EtiReader.cpp
index 500101b..76f8dbb 100644
--- a/src/EtiReader.cpp
+++ b/src/EtiReader.cpp
@@ -57,7 +57,6 @@ EtiReader::EtiReader(
unsigned tist_delay_stages,
RemoteControllers* rcs) :
state(EtiReaderStateSync),
- myFicSource(NULL),
myTimestampDecoder(tist_offset_s, tist_delay_stages)
{
PDEBUG("EtiReader::EtiReader()\n");
@@ -68,17 +67,7 @@ EtiReader::EtiReader(
eti_fc_valid = false;
}
-EtiReader::~EtiReader()
-{
- PDEBUG("EtiReader::~EtiReader()\n");
-
-// if (myFicSource != NULL) {
-// delete myFicSource;
-// }
-}
-
-
-FicSource* EtiReader::getFic()
+std::shared_ptr<FicSource>& EtiReader::getFic()
{
return myFicSource;
}
@@ -169,8 +158,8 @@ int EtiReader::process(const Buffer* dataIn)
if (!eti_fc.FICF) {
throw std::runtime_error("FIC must be present to modulate!");
}
- if (myFicSource == NULL) {
- myFicSource = new FicSource(eti_fc);
+ if (not myFicSource) {
+ myFicSource = make_shared<FicSource>(eti_fc);
}
break;
case EtiReaderStateNst:
diff --git a/src/EtiReader.h b/src/EtiReader.h
index a8fc8f0..c5dfb70 100644
--- a/src/EtiReader.h
+++ b/src/EtiReader.h
@@ -51,11 +51,8 @@ public:
double tist_offset_s,
unsigned tist_delay_stages,
RemoteControllers* rcs);
- virtual ~EtiReader();
- EtiReader(const EtiReader&);
- EtiReader& operator=(const EtiReader&);
- FicSource* getFic();
+ std::shared_ptr<FicSource>& getFic();
unsigned getMode();
unsigned getFp();
const std::vector<std::shared_ptr<SubchannelSource> >& getSubchannels();
@@ -83,7 +80,7 @@ protected:
eti_EOH eti_eoh;
eti_EOF eti_eof;
eti_TIST eti_tist;
- FicSource* myFicSource;
+ std::shared_ptr<FicSource> myFicSource;
std::vector<std::shared_ptr<SubchannelSource> > mySources;
TimestampDecoder myTimestampDecoder;
diff --git a/src/Flowgraph.cpp b/src/Flowgraph.cpp
index e36c1f4..e4c6a30 100644
--- a/src/Flowgraph.cpp
+++ b/src/Flowgraph.cpp
@@ -151,12 +151,11 @@ Flowgraph::~Flowgraph()
if (myProcessTime) {
fprintf(stderr, "Process time:\n");
- std::vector<shared_ptr<Node> >::const_iterator node;
- for (node = nodes.begin(); node != nodes.end(); ++node) {
+ for (const auto &node : nodes) {
fprintf(stderr, " %30s: %10u us (%2.2f %%)\n",
- (*node)->plugin()->name(),
- (unsigned)(*node)->processTime(),
- (*node)->processTime() * 100.0 / myProcessTime);
+ node->plugin()->name(),
+ (unsigned)node->processTime(),
+ node->processTime() * 100.0 / myProcessTime);
}
fprintf(stderr, " %30s: %10u us (100.00 %%)\n", "total",
@@ -215,19 +214,18 @@ bool Flowgraph::run()
{
PDEBUG("Flowgraph::run()\n");
- std::vector<shared_ptr<Node> >::const_iterator node;
timeval start, stop;
time_t diff;
gettimeofday(&start, NULL);
- for (node = nodes.begin(); node != nodes.end(); ++node) {
- int ret = (*node)->process();
+ for (const auto &node : nodes) {
+ int ret = node->process();
PDEBUG(" ret: %i\n", ret);
gettimeofday(&stop, NULL);
diff = (stop.tv_sec - start.tv_sec) * 1000000 +
stop.tv_usec - start.tv_usec;
myProcessTime += diff;
- (*node)->addProcessTime(diff);
+ node->addProcessTime(diff);
start = stop;
if (!ret) {
return false;
diff --git a/src/Log.cpp b/src/Log.cpp
index 9b7a2c3..7db1d44 100644
--- a/src/Log.cpp
+++ b/src/Log.cpp
@@ -68,10 +68,8 @@ void Logger::logstr(log_level_t level, std::string message)
message.resize(message.length()-1);
}
- for (std::list<LogBackend*>::iterator it = backends.begin();
- it != backends.end();
- ++it) {
- (*it)->log(level, message);
+ for (auto &backend : backends) {
+ backend->log(level, message);
}
std::cerr << levels_as_str[level] << " " << message << std::endl;
diff --git a/src/RemoteControl.cpp b/src/RemoteControl.cpp
index d4783fd..fa797ef 100644
--- a/src/RemoteControl.cpp
+++ b/src/RemoteControl.cpp
@@ -149,16 +149,12 @@ void RemoteControllerTelnet::dispatch_command(tcp::socket& socket, string comman
stringstream ss;
if (cmd.size() == 1) {
- for (list<RemoteControllable*>::iterator it = m_cohort.begin();
- it != m_cohort.end(); ++it) {
- ss << (*it)->get_rc_name() << endl;
-
- list< vector<string> >::iterator param;
- list< vector<string> > params = (*it)->get_parameter_descriptions();
- for (param = params.begin();
- param != params.end();
- ++param) {
- ss << "\t" << (*param)[0] << " : " << (*param)[1] << endl;
+ for (auto &controllable : m_cohort) {
+ ss << controllable->get_rc_name() << endl;
+
+ list< vector<string> > params = controllable->get_parameter_descriptions();
+ for (auto &param : params) {
+ ss << "\t" << param[0] << " : " << param[1] << endl;
}
}
}
@@ -173,9 +169,8 @@ void RemoteControllerTelnet::dispatch_command(tcp::socket& socket, string comman
try {
stringstream ss;
list< vector<string> > r = get_param_list_values_(cmd[1]);
- for (list< vector<string> >::iterator it = r.begin();
- it != r.end(); ++it) {
- ss << (*it)[0] << ": " << (*it)[1] << endl;
+ for (auto &param_val : r) {
+ ss << param_val[0] << ": " << param_val[1] << endl;
}
reply(socket, ss.str());
@@ -332,10 +327,9 @@ void RemoteControllerZmq::process()
}
else if (msg.size() == 1 && command == "list") {
size_t cohort_size = m_cohort.size();
- for (list<RemoteControllable*>::iterator it = m_cohort.begin();
- it != m_cohort.end(); ++it) {
+ for (auto &controllable : m_cohort) {
std::stringstream ss;
- ss << (*it)->get_rc_name();
+ ss << controllable->get_rc_name();
std::string msg_s = ss.str();
@@ -351,11 +345,9 @@ void RemoteControllerZmq::process()
try {
list< vector<string> > r = get_param_list_values_(module);
size_t r_size = r.size();
- for (list< vector<string> >::iterator it = r.begin();
- it != r.end(); ++it) {
-
+ for (auto &param_val : r) {
std::stringstream ss;
- ss << (*it)[0] << ": " << (*it)[1] << endl;
+ ss << param_val[0] << ": " << param_val[1] << endl;
zmq::message_t msg(ss.str().size());
memcpy(msg.data(), ss.str().data(), ss.str().size());
diff --git a/src/RemoteControl.h b/src/RemoteControl.h
index b94ed6c..8c3362c 100644
--- a/src/RemoteControl.h
+++ b/src/RemoteControl.h
@@ -102,20 +102,18 @@ class RemoteControllers {
}
void add_controllable(RemoteControllable *rc) {
- for (std::list<BaseRemoteController*>::iterator it = m_controllers.begin();
- it != m_controllers.end(); ++it) {
- (*it)->enrol(rc);
+ for (auto &controller : m_controllers) {
+ controller->enrol(rc);
}
}
void check_faults() {
- for (std::list<BaseRemoteController*>::iterator it = m_controllers.begin();
- it != m_controllers.end(); ++it) {
- if ((*it)->fault_detected())
+ for (auto &controller : m_controllers) {
+ if (controller->fault_detected())
{
etiLog.level(warn) <<
"Detected Remote Control fault, restarting it";
- (*it)->restart();
+ controller->restart();
}
}
}
@@ -147,9 +145,8 @@ class RemoteControllable {
/* Return a list of possible parameters that can be set */
virtual std::list<std::string> get_supported_parameters() const {
std::list<std::string> parameterlist;
- for (std::list< std::vector<std::string> >::const_iterator it = m_parameters.begin();
- it != m_parameters.end(); ++it) {
- parameterlist.push_back((*it)[0]);
+ for (const auto& param : m_parameters) {
+ parameterlist.push_back(param[0]);
}
return parameterlist;
}
@@ -255,12 +252,10 @@ class RemoteControllerTelnet : public BaseRemoteController {
RemoteControllable* controllable = get_controllable_(name);
std::list< std::vector<std::string> > allparams;
- std::list<std::string> params = controllable->get_supported_parameters();
- for (std::list<std::string>::iterator it = params.begin();
- it != params.end(); ++it) {
+ for (auto &param : controllable->get_supported_parameters()) {
std::vector<std::string> item;
- item.push_back(*it);
- item.push_back(controllable->get_parameter(*it));
+ item.push_back(param);
+ item.push_back(controllable->get_parameter(param));
allparams.push_back(item);
}
@@ -363,15 +358,15 @@ class RemoteControllerZmq : public BaseRemoteController {
RemoteControllable* controllable = get_controllable_(name);
std::list< std::vector<std::string> > allparams;
- std::list<std::string> params = controllable->get_supported_parameters();
- for (std::list<std::string>::iterator it = params.begin();
- it != params.end(); ++it) {
+
+ for (auto &param : controllable->get_supported_parameters()) {
std::vector<std::string> item;
- item.push_back(*it);
- item.push_back(controllable->get_parameter(*it));
+ item.push_back(param);
+ item.push_back(controllable->get_parameter(param));
allparams.push_back(item);
}
+
return allparams;
}