From 73badae2d0edbe8bacb4be1cd59803614430eec4 Mon Sep 17 00:00:00 2001 From: stephena Date: Tue, 4 Nov 2014 23:26:23 +0000 Subject: [PATCH] OK, this is the last commit about pointers for the CompuMate stuff. Again, still learning the best way to use C++11 here. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3042 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- src/emucore/CartCM.hxx | 4 ++-- src/emucore/CompuMate.cxx | 8 +++----- src/emucore/CompuMate.hxx | 6 +++--- src/emucore/Console.cxx | 8 ++++---- src/emucore/Console.hxx | 2 +- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/emucore/CartCM.hxx b/src/emucore/CartCM.hxx index da1bb37cb..a4609c4ca 100644 --- a/src/emucore/CartCM.hxx +++ b/src/emucore/CartCM.hxx @@ -229,7 +229,7 @@ class CartridgeCM : public Cartridge /** Inform the cartridge about the parent CompuMate controller */ - void setCompuMate(CompuMate* cmate) { myCompuMate = cmate; } + void setCompuMate(shared_ptr cmate) { myCompuMate = cmate; } /** Get the current keyboard column @@ -240,7 +240,7 @@ class CartridgeCM : public Cartridge private: // The CompuMate device which interacts with this cartridge - CompuMate* myCompuMate; + shared_ptr myCompuMate; // Indicates which bank is currently active uInt16 myCurrentBank; diff --git a/src/emucore/CompuMate.cxx b/src/emucore/CompuMate.cxx index bd851b611..4e1ba3bb5 100644 --- a/src/emucore/CompuMate.cxx +++ b/src/emucore/CompuMate.cxx @@ -25,14 +25,12 @@ CompuMate::CompuMate(const Console& console, const Event& event, const System& system) : myConsole(console), - myEvent(event), - myLeftController(nullptr), - myRightController(nullptr) + myEvent(event) { // These controller pointers will be retrieved by the Console, which will // also take ownership of them - myLeftController = new CMControl(*this, Controller::Left, event, system); - myRightController = new CMControl(*this, Controller::Right, event, system); + myLeftController = make_ptr(*this, Controller::Left, event, system); + myRightController = make_ptr(*this, Controller::Right, event, system); myLeftController->myAnalogPinValue[Controller::Nine] = Controller::maximumResistance; myLeftController->myAnalogPinValue[Controller::Five] = Controller::minimumResistance; diff --git a/src/emucore/CompuMate.hxx b/src/emucore/CompuMate.hxx index a5f2b897a..48bcf1c74 100644 --- a/src/emucore/CompuMate.hxx +++ b/src/emucore/CompuMate.hxx @@ -65,8 +65,8 @@ class CompuMate /** Return the left and right CompuMate controllers */ - Controller* leftController() const { return myLeftController; } - Controller* rightController() const { return myRightController; } + unique_ptr& leftController() { return myLeftController; } + unique_ptr& rightController() { return myRightController; } /** In normal key-handling mode, the update handler receives key events @@ -140,7 +140,7 @@ class CompuMate const Event& myEvent; // Left and right controllers - CMControl *myLeftController, *myRightController; + unique_ptr myLeftController, myRightController; // Column currently active uInt8 myColumn; diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index d2e384e37..e359b50db 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -587,17 +587,17 @@ void Console::setControllers(const string& rommd5) // creates them for us, and also that they must be used in both ports if(left == "COMPUMATE" || right == "COMPUMATE") { - myCMHandler = make_ptr(*this, myEvent, *mySystem); + myCMHandler = make_shared(*this, myEvent, *mySystem); // A somewhat ugly bit of code that casts to CartridgeCM to // add the CompuMate, and then back again for the actual // Cartridge unique_ptr cartcm(static_cast(myCart.release())); - cartcm->setCompuMate(myCMHandler.get()); + cartcm->setCompuMate(myCMHandler); myCart = std::move(cartcm); - myLeftControl = unique_ptr(myCMHandler->leftController()); - myRightControl = unique_ptr(myCMHandler->rightController()); + myLeftControl = std::move(myCMHandler->leftController()); + myRightControl = std::move(myCMHandler->rightController()); return; } diff --git a/src/emucore/Console.hxx b/src/emucore/Console.hxx index 3719a53c0..0528987d8 100644 --- a/src/emucore/Console.hxx +++ b/src/emucore/Console.hxx @@ -349,7 +349,7 @@ class Console : public Serializable unique_ptr myLeftControl, myRightControl; // Pointer to CompuMate handler (only used in CompuMate ROMs) - unique_ptr myCMHandler; + shared_ptr myCMHandler; // The currently defined display format (NTSC/PAL/SECAM) string myDisplayFormat;