AaronCameron.net
I care not for your petty politics.
Not a Member? - Login or Create an Account
Tuesday the 22nd of May 2012 @ 01:12am
Front Page Journal Projects Your Profile About
[]

LibN2L-4 Library Code Reference

Classes
Compounds
Files
Members
Method Index
Full Reference

cJoystickManager.cpp

Go to the documentation of this file.
00001 #include "cJoystickManager.h"
00002 #include "cJoystick.h"
00003 
00004 /******************************************************************************/
00005 namespace n2l {
00006 
00007     /**************************************************************************/
00008     cJoystickManager::~cJoystickManager()
00009     {
00010         for (tJoystickList::iterator i = mJoysticks.begin();
00011             i!=mJoysticks.end(); ++i)
00012         {
00013             *i = 0;
00014         }
00015 
00016         releaseSDLSubSystem(SDLSubSystemInitFlag_Joystick);
00017     }
00018 
00019     /**************************************************************************/
00020     const tUint cJoystickManager::numJoysticks() const
00021     {
00022         return mNumJoysticks;
00023     }
00024 
00025     /**************************************************************************/
00026     const tString cJoystickManager::joystickName( const tUint iID )
00027     {
00028         if (iID>=mNumJoysticks)
00029             throw cOutOfBoundsException("cJoystickManager::joystickName",
00030                 "No such joystick with ID", asString(iID) );
00031         return SDL_JoystickName( iID );
00032     }
00033 
00034     /**************************************************************************/
00035     const cAutoPtr<cJoystick> &cJoystickManager::openJoystick(
00036         const tUint iID )
00037     {
00038         if (iID>=mNumJoysticks)
00039             throw cOutOfBoundsException("cJoystickManager::openJoystick",
00040                 "No such joystick with ID", asString(iID) );
00041         // Make sure this joystick isn't still floating around with
00042         // open references.
00043         if (!mJoysticks[iID].isSet() && SDL_JoystickOpened(iID))
00044             throw cException( "cJoystickManager::openJoystick",
00045                 "Requested joystick is still open: "+joystickName(iID) );
00046 
00047         if (!mJoysticks[iID].isSet())
00048             mJoysticks[iID] = new cJoystick( iID );
00049 
00050         return mJoysticks[iID];
00051     }
00052 
00053     /**************************************************************************/
00054     const tBool cJoystickManager::joystickOpened( const tUint iID )
00055     {
00056         if (iID>=mNumJoysticks)
00057             throw cOutOfBoundsException("cJoystickManager::joystickOpened",
00058                 "No such joystick with ID", asString(iID) );
00059 
00060         return SDL_JoystickOpened(iID);
00061     }
00062 
00063     /**************************************************************************/
00064     void cJoystickManager::closeJoystick( const tUint iID )
00065     {
00066         if (iID>=mNumJoysticks)
00067             throw cOutOfBoundsException("cJoystickManager::closeJoystick",
00068                 "No such joystick with ID", asString(iID) );
00069 
00070         if (!mJoysticks[iID].isSet() || !SDL_JoystickOpened(iID))
00071             throw cOutOfBoundsException( "cJoystickManager::closeJoystick",
00072                 "Tried to close an invalid joystick with ID", asString(iID) );
00073         
00074         mJoysticks[iID] = 0;
00075     }
00076 
00077     /**************************************************************************/
00078     cJoystickManager::cJoystickManager()
00079     {
00080         requireSDLSubSystem(SDLSubSystemInitFlag_Joystick);
00081         mNumJoysticks = SDL_NumJoysticks();
00082         for (tUint i=0; i<mNumJoysticks; ++i)
00083             mJoysticks.push_back(0);
00084     }
00085 
00086 }
©2012 Aaron Cameron