diff --git a/src/cheat/Cheat.hxx b/src/cheat/Cheat.hxx index 5ca1a0915..bc3bb817d 100644 --- a/src/cheat/Cheat.hxx +++ b/src/cheat/Cheat.hxx @@ -22,8 +22,6 @@ class OSystem; -#include - #include "bspf.hxx" class Cheat diff --git a/src/cheat/CheatCodeDialog.cxx b/src/cheat/CheatCodeDialog.cxx index 8b56d5333..23e1d6ae8 100644 --- a/src/cheat/CheatCodeDialog.cxx +++ b/src/cheat/CheatCodeDialog.cxx @@ -17,8 +17,6 @@ // $Id$ //============================================================================ -#include - #include "bspf.hxx" #include "Cheat.hxx" diff --git a/src/common/EventHandlerSDL2.cxx b/src/common/EventHandlerSDL2.cxx index c86ca2fc7..4a39a3c86 100644 --- a/src/common/EventHandlerSDL2.cxx +++ b/src/common/EventHandlerSDL2.cxx @@ -40,12 +40,6 @@ void EventHandlerSDL2::enableTextEvents(bool enable) SDL_StopTextInput(); } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -const char* EventHandlerSDL2::nameForKey(StellaKey key) const -{ - return SDL_GetScancodeName(SDL_Scancode(key)); -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EventHandlerSDL2::pollEvent() { diff --git a/src/common/EventHandlerSDL2.hxx b/src/common/EventHandlerSDL2.hxx index 3a89a92e2..c000e57ba 100644 --- a/src/common/EventHandlerSDL2.hxx +++ b/src/common/EventHandlerSDL2.hxx @@ -53,7 +53,9 @@ class EventHandlerSDL2 : public EventHandler /** Returns the human-readable name for a StellaKey. */ - const char* nameForKey(StellaKey key) const; + const char* nameForKey(StellaKey key) const { + return SDL_GetScancodeName(SDL_Scancode(key)); + } /** Collects and dispatches any pending SDL2 events. diff --git a/src/common/FrameBufferSDL2.cxx b/src/common/FrameBufferSDL2.cxx index 37f4a15f7..c9e539aae 100644 --- a/src/common/FrameBufferSDL2.cxx +++ b/src/common/FrameBufferSDL2.cxx @@ -107,8 +107,7 @@ Int32 FrameBufferSDL2::getCurrentDisplayIndex() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode, - bool /*fullscreen_toggle*/) +bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode) { // If not initialized by this point, then immediately fail if(SDL_WasInit(SDL_INIT_VIDEO) == 0) diff --git a/src/common/FrameBufferSDL2.hxx b/src/common/FrameBufferSDL2.hxx index b10402405..e57a27893 100644 --- a/src/common/FrameBufferSDL2.hxx +++ b/src/common/FrameBufferSDL2.hxx @@ -129,8 +129,7 @@ class FrameBufferSDL2 : public FrameBuffer @return False on any errors, else true */ - bool setVideoMode(const string& title, const VideoMode& mode, - bool fullscreen_toggle); + bool setVideoMode(const string& title, const VideoMode& mode); /** This method is called to invalidate the contents of the entire diff --git a/src/common/PNGLibrary.cxx b/src/common/PNGLibrary.cxx index dcbef1a4b..874bab478 100644 --- a/src/common/PNGLibrary.cxx +++ b/src/common/PNGLibrary.cxx @@ -34,13 +34,6 @@ PNGLibrary::PNGLibrary(const FrameBuffer& fb) { } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -PNGLibrary::~PNGLibrary() -{ - delete[] ReadInfo.buffer; - delete[] ReadInfo.row_pointers; -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PNGLibrary::loadImage(const string& filename, FBSurface& surface) { @@ -311,7 +304,7 @@ void PNGLibrary::writeComments(png_structp png_ptr, png_infop info_ptr, if(numComments == 0) return; - png_text* text_ptr = new png_text[numComments]; + png_text text_ptr[numComments]; for(uInt32 i = 0; i < numComments; ++i) { text_ptr[i].key = (char*) comments[i].first.c_str(); @@ -320,7 +313,6 @@ void PNGLibrary::writeComments(png_structp png_ptr, png_infop info_ptr, text_ptr[i].text_length = 0; } png_set_text(png_ptr, info_ptr, text_ptr, numComments); - delete[] text_ptr; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/PNGLibrary.hxx b/src/common/PNGLibrary.hxx index eb10dc371..0e04c5a89 100644 --- a/src/common/PNGLibrary.hxx +++ b/src/common/PNGLibrary.hxx @@ -41,7 +41,6 @@ class PNGLibrary { public: PNGLibrary(const FrameBuffer& fb); - ~PNGLibrary(); /** Read a PNG image from the specified file into a FBSurface structure, @@ -93,6 +92,8 @@ class PNGLibrary // The following data remains between invocations of allocateStorage, // and is only changed when absolutely necessary. struct ReadInfoType { + ~ReadInfoType() { delete[] buffer; delete[] row_pointers; } + uInt8* buffer; png_bytep* row_pointers; png_uint_32 width, height, pitch; diff --git a/src/common/SoundSDL2.cxx b/src/common/SoundSDL2.cxx index 44258f637..485d933b0 100644 --- a/src/common/SoundSDL2.cxx +++ b/src/common/SoundSDL2.cxx @@ -450,19 +450,13 @@ bool SoundSDL2::load(Serializer& in) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SoundSDL2::RegWriteQueue::RegWriteQueue(uInt32 capacity) - : myCapacity(capacity), - myBuffer(nullptr), + : myBuffer(nullptr), + myCapacity(capacity), mySize(0), myHead(0), myTail(0) { - myBuffer = new RegWrite[myCapacity]; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -SoundSDL2::RegWriteQueue::~RegWriteQueue() -{ - delete[] myBuffer; + myBuffer = make_ptr(myCapacity); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -521,16 +515,15 @@ uInt32 SoundSDL2::RegWriteQueue::size() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void SoundSDL2::RegWriteQueue::grow() { - RegWrite* buffer = new RegWrite[myCapacity * 2]; + unique_ptr buffer = make_ptr(myCapacity*2); for(uInt32 i = 0; i < mySize; ++i) - { buffer[i] = myBuffer[(myHead + i) % myCapacity]; - } + myHead = 0; myTail = mySize; - myCapacity = myCapacity * 2; - delete[] myBuffer; - myBuffer = buffer; + myCapacity *= 2; + + myBuffer = std::move(buffer); } #endif // SOUND_SUPPORT diff --git a/src/common/SoundSDL2.hxx b/src/common/SoundSDL2.hxx index ae4d68ad2..28742b9ab 100644 --- a/src/common/SoundSDL2.hxx +++ b/src/common/SoundSDL2.hxx @@ -193,11 +193,6 @@ class SoundSDL2 : public Sound */ RegWriteQueue(uInt32 capacity = 512); - /** - Destroy this queue instance. - */ - virtual ~RegWriteQueue(); - public: /** Clear any items stored in the queue. @@ -238,8 +233,8 @@ class SoundSDL2 : public Sound void grow(); private: + unique_ptr myBuffer; uInt32 myCapacity; - RegWrite* myBuffer; uInt32 mySize; uInt32 myHead; uInt32 myTail; diff --git a/src/common/StringParser.hxx b/src/common/StringParser.hxx index 016ba5825..bc300f169 100644 --- a/src/common/StringParser.hxx +++ b/src/common/StringParser.hxx @@ -38,7 +38,7 @@ class StringParser */ StringParser(const string& str) { - stringstream buf(str); + istringstream buf(str); string line; while(std::getline(buf, line, '\n')) @@ -54,7 +54,7 @@ class StringParser */ StringParser(const string& str, uInt16 maxlen) { - stringstream buf(str); + istringstream buf(str); string line; while(std::getline(buf, line, '\n')) diff --git a/src/common/UniquePtr.hxx b/src/common/UniquePtr.hxx new file mode 100644 index 000000000..5db7f7ab4 --- /dev/null +++ b/src/common/UniquePtr.hxx @@ -0,0 +1,67 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2015 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id$ +//============================================================================ + +#ifndef UNIQUE_PTR_HXX +#define UNIQUE_PTR_HXX + +#include +#include +#include +#include + +/** + The following templates implement 'make_unique' from C++14, which is + named 'make_ptr' here. Eventually, when compilers are updated, this code + can be removed. + + @author Stephen Anthony, based on a C++14 proposal by Stephan T. Lavavej. +*/ +namespace std { + + template struct _Unique_if { + typedef unique_ptr _Single_object; + }; + + template struct _Unique_if { + typedef unique_ptr _Unknown_bound; + }; + + template struct _Unique_if { + typedef void _Known_bound; + }; + + template + typename _Unique_if::_Single_object + make_ptr(Args&&... args) { + return unique_ptr(new T(std::forward(args)...)); + } + + template + typename _Unique_if::_Unknown_bound + make_ptr(size_t n) { + typedef typename remove_extent::type U; + return unique_ptr(new U[n]()); + } + + template + typename _Unique_if::_Known_bound + make_ptr(Args&&...) = delete; +} + +#endif diff --git a/src/common/bspf.hxx b/src/common/bspf.hxx index b6ca2cb53..acb4705f5 100644 --- a/src/common/bspf.hxx +++ b/src/common/bspf.hxx @@ -55,6 +55,7 @@ using uInt64 = uint64_t; #include #include #include +#include "UniquePtr.hxx" // only until C++14 compilers are more common using namespace std; // Common array types @@ -99,17 +100,6 @@ static const string EmptyString(""); ////////////////////////////////////////////////////////////////////// // Some convenience functions - -// Initialize C++11 unique_ptr, at least until std::make_unique() -// becomes part of the standard (C++14) -template -std::unique_ptr make_ptr(Arguments && ... arguments_for_constructor) -{ - return std::unique_ptr( - new Value(std::forward(arguments_for_constructor)...) - ); -} - template inline void BSPF_swap(T& a, T& b) { std::swap(a, b); } template inline T BSPF_abs (T x) { return (x>=0) ? x : -x; } template inline T BSPF_min (T a, T b) { return (a= 3 ? atoi(av[2]) : 8; int offset = ac >= 4 ? atoi(av[3]) : 0; - ifstream in; - in.open(av[1]); + ifstream in(av[1]); if(in.is_open()) { in.seekg(0, ios::end);