Use make_unique/make_shared to eliminate raw pointers.

This commit is contained in:
Stephen Anthony 2019-12-13 19:24:36 -03:30
parent c4d1473f81
commit d129ffc12a
7 changed files with 16 additions and 12 deletions

View File

@ -45,7 +45,7 @@ StaggeredLogger::StaggeredLogger(const string& message, Logger::Level level)
myMaxIntervalFactor(9),
myCurrentIntervalFactor(1),
myCooldownTime(1000),
myTimer(new TimerManager()),
myTimer(make_unique<TimerManager>()),
myTimerId(0),
myTimerCallbackId(0)
{
@ -57,7 +57,7 @@ StaggeredLogger::~StaggeredLogger()
myTimer->clear(myTimerId);
// make sure that the worker thread joins before continuing with the destruction
delete myTimer;
myTimer.reset();
// the worker thread has joined and there will be no more reentrant calls ->
// continue with destruction

View File

@ -76,7 +76,7 @@ class StaggeredLogger
// We need control over the destruction porcess and over the exact point where
// the worker thread joins -> allocate on the heap end delete explicitly in
// our destructor.
TimerManager *myTimer;
unique_ptr<TimerManager> myTimer;
TimerManager::TimerId myTimerId;
// It is possible that the timer callback is running even after TimerManager::clear

View File

@ -29,14 +29,16 @@ unique_ptr<Blitter> BlitterFactory::createBlitter(FrameBufferSDL2& fb, ScalingAl
switch (scaling) {
case ScalingAlgorithm::nearestNeighbour:
return unique_ptr<Blitter>(new BilinearBlitter(fb, false));
return make_unique<BilinearBlitter>(fb, false);
case ScalingAlgorithm::bilinear:
return unique_ptr<Blitter>(new BilinearBlitter(fb, true));
return make_unique<BilinearBlitter>(fb, true);
case ScalingAlgorithm::quasiInteger:
return HqBlitter::isSupported(fb) ?
unique_ptr<Blitter>(new HqBlitter(fb)) : unique_ptr<Blitter>(new BilinearBlitter(fb, true));
if (HqBlitter::isSupported(fb))
return make_unique<HqBlitter>(fb);
else
return make_unique<BilinearBlitter>(fb, true);
default:
throw runtime_error("unreachable");

View File

@ -2106,8 +2106,7 @@ void DebuggerParser::executeTraps(bool read, bool write, const string& command,
YaccParser::getResult(), hasCond ? argStrings[0] : "");
commandResult << "added trap " << Base::toString(ret);
// @sa666666: please check this:
myTraps.emplace_back(new Trap{ read, write, begin, end, condition });
myTraps.emplace_back(make_unique<Trap>(read, write, begin, end, condition));
}
for(uInt32 addr = begin; addr <= end; ++addr)

View File

@ -106,6 +106,9 @@ class DebuggerParser
uInt32 begin;
uInt32 end;
string condition;
Trap(bool r, bool w, uInt32 b, uInt32 e, const string& c)
: read(r), write(w), begin(b), end(e), condition(c) {}
};
// Reference to our debugger object

View File

@ -1147,8 +1147,8 @@ void TIA::setJitterRecoveryFactor(Int32 factor)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
shared_ptr<DelayQueueIterator> TIA::delayQueueIterator() const
{
return shared_ptr<DelayQueueIterator>(
new DelayQueueIteratorImpl<delayQueueLength, delayQueueSize>(myDelayQueue)
return make_shared<DelayQueueIteratorImpl<delayQueueLength, delayQueueSize>>(
myDelayQueue
);
}

View File

@ -113,7 +113,7 @@ void FrameLayoutDetector::setState(State state)
break;
default:
throw new runtime_error("cannot happen");
throw runtime_error("cannot happen");
}
}