From 166e885cf6ea7ff4b56d860bc6449c02d03ef5de Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sun, 31 Jan 2016 21:45:00 +0100 Subject: Replace quite a few 'new' with make_shared --- src/DabMod.cpp | 4 +-- src/DabModulator.cpp | 82 +++++++++++++++++++++++----------------------------- src/EtiReader.cpp | 3 +- src/Flowgraph.cpp | 8 ++--- 4 files changed, 43 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/DabMod.cpp b/src/DabMod.cpp index 982a1ee..f250850 100644 --- a/src/DabMod.cpp +++ b/src/DabMod.cpp @@ -164,7 +164,7 @@ int launch_modulator(int argc, char* argv[]) unsigned tist_delay_stages = 0; double tist_offset_s = 0.0; - shared_ptr flowgraph(new Flowgraph()); + auto flowgraph = make_shared(); shared_ptr format_converter; shared_ptr output; @@ -174,7 +174,7 @@ int launch_modulator(int argc, char* argv[]) InputFileReader inputFileReader; #if defined(HAVE_ZEROMQ) - shared_ptr inputZeroMQReader(new InputZeroMQReader()); + auto inputZeroMQReader = make_shared(); #endif struct sigaction sa; diff --git a/src/DabModulator.cpp b/src/DabModulator.cpp index 5219ac4..61e5ce8 100644 --- a/src/DabModulator.cpp +++ b/src/DabModulator.cpp @@ -160,23 +160,20 @@ int DabModulator::process(Buffer* const dataIn, Buffer* dataOut) //////////////////////////////////////////////////////////////// // CIF data initialisation //////////////////////////////////////////////////////////////// - shared_ptr cifPrbs(new PrbsGenerator(864 * 8, 0x110)); - shared_ptr cifMux( - new FrameMultiplexer(myFicSizeOut + 864 * 8, - &myEtiReader.getSubchannels())); + auto cifPrbs = make_shared(864 * 8, 0x110); + auto cifMux = make_shared( + myFicSizeOut + 864 * 8, &myEtiReader.getSubchannels()); - shared_ptr cifPart( - new BlockPartitioner(mode, myEtiReader.getFp())); + auto cifPart = make_shared(mode, myEtiReader.getFp()); - shared_ptr cifMap(new QpskSymbolMapper(myNbCarriers)); - shared_ptr cifRef(new PhaseReference(mode)); - shared_ptr cifFreq(new FrequencyInterleaver(mode)); - shared_ptr cifDiff( - new DifferentialModulator(myNbCarriers)); + auto cifMap = make_shared(myNbCarriers); + auto cifRef = make_shared(mode); + auto cifFreq = make_shared(mode); + auto cifDiff = make_shared(myNbCarriers); - shared_ptr cifNull(new NullSymbol(myNbCarriers)); - shared_ptr cifSig(new SignalMultiplexer( - (1 + myNbSymbols) * myNbCarriers * sizeof(complexf))); + auto cifNull = make_shared(myNbCarriers); + auto cifSig = make_shared( + (1 + myNbSymbols) * myNbCarriers * sizeof(complexf)); // TODO this needs a review bool useCicEq = false; @@ -194,9 +191,9 @@ int DabModulator::process(Buffer* const dataIn, Buffer* dataOut) } } - shared_ptr cifCicEq(new CicEqualizer(myNbCarriers, - (float)mySpacing * (float)myOutputRate / 2048000.0f, - cic_ratio)); + auto cifCicEq = make_shared( + myNbCarriers, + (float)mySpacing * (float)myOutputRate / 2048000.0f, cic_ratio); shared_ptr tii; try { @@ -207,28 +204,27 @@ int DabModulator::process(Buffer* const dataIn, Buffer* dataOut) etiLog.level(error) << "Could not initialise TII: " << e.what(); } - shared_ptr cifOfdm( - new OfdmGenerator((1 + myNbSymbols), myNbCarriers, mySpacing)); + auto cifOfdm = make_shared( + (1 + myNbSymbols), myNbCarriers, mySpacing); - shared_ptr cifGain( - new GainControl(mySpacing, myGainMode, myDigGain, myNormalise)); + auto cifGain = make_shared( + mySpacing, myGainMode, myDigGain, myNormalise); cifGain->enrol_at(*myRCs); - shared_ptr cifGuard( - new GuardIntervalInserter(myNbSymbols, mySpacing, - myNullSize, mySymSize)); + auto cifGuard = make_shared( + myNbSymbols, mySpacing, myNullSize, mySymSize); shared_ptr cifFilter; if (myFilterTapsFilename != "") { cifFilter = make_shared(myFilterTapsFilename); cifFilter->enrol_at(*myRCs); } - shared_ptr myOutput(new OutputMemory(dataOut)); + auto myOutput = make_shared(dataOut); - Resampler* cifRes = NULL; + shared_ptr cifRes; if (myOutputRate != 2048000) { - cifRes = new Resampler(2048000, myOutputRate, mySpacing); + cifRes = make_shared(2048000, myOutputRate, mySpacing); } else { fprintf(stderr, "No resampler\n"); } @@ -254,13 +250,13 @@ int DabModulator::process(Buffer* const dataIn, Buffer* dataOut) PDEBUG(" Framesize: %zu\n", fic->getFramesize()); // Configuring prbs generator - shared_ptr ficPrbs(new PrbsGenerator(myFicSizeIn, 0x110)); + auto ficPrbs = make_shared(myFicSizeIn, 0x110); // Configuring convolutionnal encoder - shared_ptr ficConv(new ConvEncoder(myFicSizeIn)); + auto ficConv = make_shared(myFicSizeIn); // Configuring puncturing encoder - shared_ptr ficPunc(new PuncturingEncoder()); + auto ficPunc = make_shared(); for (const auto *rule : fic->get_rules()) { PDEBUG(" Adding rule:\n"); PDEBUG(" Length: %zu\n", rule->length()); @@ -311,16 +307,13 @@ int DabModulator::process(Buffer* const dataIn, Buffer* dataOut) subchannel->protectionOption()); // Configuring prbs genrerator - shared_ptr subchPrbs( - new PrbsGenerator(subchSizeIn, 0x110)); + auto subchPrbs = make_shared(subchSizeIn, 0x110); // Configuring convolutionnal encoder - shared_ptr subchConv( - new ConvEncoder(subchSizeIn)); + auto subchConv = make_shared(subchSizeIn); // Configuring puncturing encoder - shared_ptr subchPunc( - new PuncturingEncoder()); + auto subchPunc = make_shared(); for (const auto& rule : subchannel->get_rules()) { PDEBUG(" Adding rule:\n"); @@ -332,8 +325,7 @@ int DabModulator::process(Buffer* const dataIn, Buffer* dataOut) subchPunc->append_tail_rule(PuncturingRule(3, 0xcccccc)); // Configuring time interleaver - shared_ptr subchInterleaver( - new TimeInterleaver(subchSizeOut)); + auto subchInterleaver = make_shared(subchSizeOut); myFlowgraph->connect(subchannel, subchPrbs); myFlowgraph->connect(subchPrbs, subchConv); @@ -364,19 +356,17 @@ int DabModulator::process(Buffer* const dataIn, Buffer* dataOut) if (cifFilter) { myFlowgraph->connect(cifGuard, cifFilter); - if (cifRes != NULL) { - shared_ptr res(cifRes); - myFlowgraph->connect(cifFilter, res); - myFlowgraph->connect(res, myOutput); + if (cifRes) { + myFlowgraph->connect(cifFilter, cifRes); + myFlowgraph->connect(cifRes, myOutput); } else { myFlowgraph->connect(cifFilter, myOutput); } } else { //no filtering - if (cifRes != NULL) { - shared_ptr res(cifRes); - myFlowgraph->connect(cifGuard, res); - myFlowgraph->connect(res, myOutput); + if (cifRes) { + myFlowgraph->connect(cifGuard, cifRes); + myFlowgraph->connect(cifRes, myOutput); } else { myFlowgraph->connect(cifGuard, myOutput); } diff --git a/src/EtiReader.cpp b/src/EtiReader.cpp index 3171a91..16272e3 100644 --- a/src/EtiReader.cpp +++ b/src/EtiReader.cpp @@ -174,8 +174,7 @@ int EtiReader::process(const Buffer* dataIn) mySources.clear(); for (unsigned i = 0; i < eti_fc.NST; ++i) { - mySources.push_back(shared_ptr( - new SubchannelSource(eti_stc[i]))); + mySources.push_back(make_shared(eti_stc[i])); PDEBUG("Sstc %u:\n", i); PDEBUG(" Stc%i.scid: %i\n", i, eti_stc[i].SCID); PDEBUG(" Stc%i.sad: %u\n", i, eti_stc[i].getStartAddress()); diff --git a/src/Flowgraph.cpp b/src/Flowgraph.cpp index e4c6a30..8e76cae 100644 --- a/src/Flowgraph.cpp +++ b/src/Flowgraph.cpp @@ -77,7 +77,7 @@ Edge::Edge(shared_ptr& srcNode, shared_ptr& dstNode) : dstNode->plugin()->name(), dstNode.get(), this); - myBuffer = shared_ptr(new Buffer()); + myBuffer = make_shared(); srcNode->myOutputBuffers.push_back(myBuffer); dstNode->myInputBuffers.push_back(myBuffer); } @@ -177,7 +177,7 @@ void Flowgraph::connect(shared_ptr input, shared_ptr outpu } } if (inputNode == nodes.end()) { - inputNode = nodes.insert(nodes.end(), shared_ptr(new Node(input))); + inputNode = nodes.insert(nodes.end(), make_shared(input)); } for (outputNode = nodes.begin(); outputNode != nodes.end(); ++outputNode) { @@ -186,7 +186,7 @@ void Flowgraph::connect(shared_ptr input, shared_ptr outpu } } if (outputNode == nodes.end()) { - outputNode = nodes.insert(nodes.end(), shared_ptr(new Node(output))); + outputNode = nodes.insert(nodes.end(), make_shared(output)); for (inputNode = nodes.begin(); inputNode != nodes.end(); ++inputNode) { if ((*inputNode)->plugin() == input) { break; @@ -206,7 +206,7 @@ void Flowgraph::connect(shared_ptr input, shared_ptr outpu assert((*inputNode)->plugin() == input); assert((*outputNode)->plugin() == output); - edges.push_back(shared_ptr(new Edge(*inputNode, *outputNode))); + edges.push_back(make_shared(*inputNode, *outputNode)); } -- cgit v1.2.3