SDL++
C++wrapperfortheSDLlibrary.
|
00001 00021 #ifndef SDL_DEVICES_CDROM_H 00022 #define SDL_DEVICES_CDROM_H 00023 00024 #include <stdexcept> 00025 #include <string> 00026 00027 #include <SDL.h> 00028 00029 #include "sdlpp/subsystem/Subsystem.h" 00030 00031 namespace sdl { 00032 namespace devices { 00037 struct CdRom { 00043 CdRom (int drive) : cd_ (open (drive)) {}; 00044 00048 ~CdRom () { SDL_CDClose (cd_); }; 00049 00055 string name () { return SDL_CDName (cd_->id); }; 00056 00062 CDstatus status () { return SDL_CDStatus (cd_); }; 00063 00069 bool cdInDrive () { return CD_INDRIVE (status ()); }; 00070 00079 bool play (int start, int length) { return cdInDrive () ? SDL_CDPlay (cd_, start, length) == 0 : false; }; 00080 00091 bool playTracks (int startTrack, int startFrame, int numTracks, int numFrames) { return cdInDrive () ? SDL_CDPlayTracks (cd_, startTrack, startFrame, numTracks, numFrames) == 0 : false; }; 00092 00098 bool pause () { return SDL_CDPause (cd_) == 0; }; 00099 00105 bool resume () { return SDL_CDResume (cd_) == 0; }; 00106 00112 bool stop () { return SDL_CDStop (cd_) == 0; }; 00113 00119 bool eject () { return SDL_CDEject (cd_) == 0; }; 00120 00126 SDL_CD* get () const { return cd_; }; 00127 00133 SDL_CD* get () { return cd_; }; 00134 00135 private: 00145 SDL_CD* open (int drive) { 00146 if (drive > subsystem::CdRom::instance ().numDrives () - 1) 00147 throw runtime_error ("Invalid drive id."); 00148 00149 SDL_CD* cd = SDL_CDOpen (drive); 00150 if (cd == NULL) 00151 throw runtime_error ("Failed to open cd drive."); 00152 return cd; 00153 }; 00154 00158 SDL_CD* cd_; 00159 }; //CdRom 00160 }; //devices 00161 }; //sdl 00162 00163 #endif //SDL_DEVICES_CDROM_H 00164