cpp-sdl2
C++ header-only SDL2 wrapper
sdl::Haptic Class Reference

#include <haptic.hpp>

Classes

union  Effect
 Effect defintion. More...
 
class  InstalledEffect
 Installed effect handle. More...
 

Public Member Functions

SDL_Haptic * ptr () const
 The the C pointer. More...
 
 Haptic ()
 Uninitialized dummy haptic device. More...
 
 Haptic (int haptic_index)
 Open haptic device from index. More...
 
 Haptic (SDL_Joystick *joystick)
 Open haptic device from joystick pointer. More...
 
 ~Haptic ()
 close the haptic device automatically More...
 
 Haptic (Haptic const &)=delete
 
Hapticoperator= (Haptic const &)=delete
 
 Haptic (Haptic &&other) noexcept
 move ctor More...
 
Hapticoperator= (Haptic &&other) noexcept
 move assign opeartor More...
 
bool valid () const
 Return true if the device is correctly opened. More...
 
unsigned int get_capabilities () const
 Get a bitflag that describe the device capabilities. More...
 
bool is_capable_of (int haptic_flag) const
 Check the SDL_HAPTIC_ flag agianst the device capabilities. More...
 
InstalledEffect new_effect (Effect const &e)
 Install the effect. More...
 
effect_list::size_type registered_effect_count () const
 Get the number of effects installed. More...
 
effect_sdlid get_effect_sdlid (InstalledEffect const &h) const
 Get the SDL assigned ID (an integer) to the effect. More...
 
void remove_effect (effect_sdlid e)
 Deactiave the effect. This only set the registered id in question to -1. More...
 
void run_effect (InstalledEffect const &h, uint32_t iterations=1) const
 Run an effect, if said effect is valid. More...
 
bool is_effect_compatible (Effect const &e) const
 Check if you can safely attemp to install the effect ont he haptic device. More...
 

Private Types

using effect_sdlid = int
 Type of an installed "effect" for SDL. More...
 
using effect_list = std::vector< effect_sdlid >
 Installed effect storage type. More...
 

Private Attributes

SDL_Haptic * haptic_ = nullptr
 Pointer to C sdl haptic device. More...
 
effect_list my_effects {}
 Installed effect storage. More...
 

Detailed Description

Definition at line 8 of file haptic.hpp.

Member Typedef Documentation

◆ effect_list

using sdl::Haptic::effect_list = std::vector<effect_sdlid>
private

Installed effect storage type.

Definition at line 17 of file haptic.hpp.

◆ effect_sdlid

using sdl::Haptic::effect_sdlid = int
private

Type of an installed "effect" for SDL.

Definition at line 14 of file haptic.hpp.

Constructor & Destructor Documentation

◆ Haptic() [1/5]

sdl::Haptic::Haptic ( )
inline

Uninitialized dummy haptic device.

Definition at line 128 of file haptic.hpp.

◆ Haptic() [2/5]

sdl::Haptic::Haptic ( int  haptic_index)
inline

Open haptic device from index.

Definition at line 131 of file haptic.hpp.

◆ Haptic() [3/5]

sdl::Haptic::Haptic ( SDL_Joystick *  joystick)
inline

Open haptic device from joystick pointer.

Definition at line 140 of file haptic.hpp.

◆ ~Haptic()

sdl::Haptic::~Haptic ( )
inline

close the haptic device automatically

Definition at line 149 of file haptic.hpp.

References sdl::Haptic::InstalledEffect::Haptic, and sdl::Haptic::InstalledEffect::operator=().

◆ Haptic() [4/5]

sdl::Haptic::Haptic ( Haptic const &  )
delete

◆ Haptic() [5/5]

sdl::Haptic::Haptic ( Haptic &&  other)
inlinenoexcept

move ctor

Definition at line 162 of file haptic.hpp.

Member Function Documentation

◆ get_capabilities()

unsigned int sdl::Haptic::get_capabilities ( ) const
inline

Get a bitflag that describe the device capabilities.

Definition at line 180 of file haptic.hpp.

References valid().

Referenced by is_capable_of().

◆ get_effect_sdlid()

effect_sdlid sdl::Haptic::get_effect_sdlid ( InstalledEffect const &  h) const
inline

Get the SDL assigned ID (an integer) to the effect.

Definition at line 224 of file haptic.hpp.

References sdl::Haptic::InstalledEffect::index_, and my_effects.

Referenced by run_effect(), and sdl::Haptic::InstalledEffect::~InstalledEffect().

◆ is_capable_of()

bool sdl::Haptic::is_capable_of ( int  haptic_flag) const
inline

Check the SDL_HAPTIC_ flag agianst the device capabilities.

Definition at line 198 of file haptic.hpp.

References get_capabilities().

Referenced by is_effect_compatible(), and new_effect().

◆ is_effect_compatible()

bool sdl::Haptic::is_effect_compatible ( Effect const &  e) const
inline

Check if you can safely attemp to install the effect ont he haptic device.

Definition at line 249 of file haptic.hpp.

References is_capable_of(), and sdl::Haptic::Effect::type.

◆ new_effect()

InstalledEffect sdl::Haptic::new_effect ( Effect const &  e)
inline

Install the effect.

Definition at line 205 of file haptic.hpp.

References is_capable_of(), my_effects, and sdl::Haptic::Effect::type.

◆ operator=() [1/2]

Haptic& sdl::Haptic::operator= ( Haptic const &  )
delete

◆ operator=() [2/2]

Haptic& sdl::Haptic::operator= ( Haptic &&  other)
inlinenoexcept

move assign opeartor

Definition at line 165 of file haptic.hpp.

References haptic_, and my_effects.

◆ ptr()

SDL_Haptic* sdl::Haptic::ptr ( ) const
inline

The the C pointer.

Definition at line 24 of file haptic.hpp.

References haptic_.

Referenced by sdl::Haptic::InstalledEffect::~InstalledEffect().

◆ registered_effect_count()

effect_list::size_type sdl::Haptic::registered_effect_count ( ) const
inline

Get the number of effects installed.

Definition at line 221 of file haptic.hpp.

References my_effects.

◆ remove_effect()

void sdl::Haptic::remove_effect ( effect_sdlid  e)
inline

Deactiave the effect. This only set the registered id in question to -1.

Definition at line 230 of file haptic.hpp.

References my_effects.

Referenced by sdl::Haptic::InstalledEffect::~InstalledEffect().

◆ run_effect()

void sdl::Haptic::run_effect ( InstalledEffect const &  h,
uint32_t  iterations = 1 
) const
inline

Run an effect, if said effect is valid.

Definition at line 239 of file haptic.hpp.

References get_effect_sdlid().

Referenced by sdl::Haptic::InstalledEffect::run().

◆ valid()

bool sdl::Haptic::valid ( ) const
inline

Return true if the device is correctly opened.

Definition at line 177 of file haptic.hpp.

Referenced by get_capabilities().

Member Data Documentation

◆ haptic_

SDL_Haptic* sdl::Haptic::haptic_ = nullptr
private

Pointer to C sdl haptic device.

Definition at line 11 of file haptic.hpp.

Referenced by operator=(), and ptr().

◆ my_effects

effect_list sdl::Haptic::my_effects {}
private

Installed effect storage.

Definition at line 20 of file haptic.hpp.

Referenced by get_effect_sdlid(), new_effect(), operator=(), registered_effect_count(), and remove_effect().


The documentation for this class was generated from the following file: