parent
3eff0610c4
commit
d692463d20
@ -0,0 +1,114 @@ |
||||
#include "actions.hpp" |
||||
#include "api.hpp" |
||||
#include "utils.hpp" |
||||
|
||||
using namespace std ; |
||||
|
||||
// --- Action ---------------------------------------------------------
|
||||
|
||||
Action::Action( const ApiAction* pAction ) |
||||
{ |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
Action* |
||||
Action::allocAction( const ApiAction* pAction ) |
||||
{ |
||||
switch( pAction->mActionType ) |
||||
{ |
||||
case Action::atMouseLeft: return new MouseLeftAction(pAction) ; |
||||
case Action::atMouseRight: return new MouseRightAction(pAction) ; |
||||
case Action::atMouseUp: return new MouseUpAction(pAction) ; |
||||
case Action::atMouseDown: return new MouseDownAction(pAction) ; |
||||
default: |
||||
assert( false ) ; |
||||
return NULL ; |
||||
} |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
ostream& |
||||
operator<<( ostream& os , const Action& action ) |
||||
{ |
||||
// insert the Action
|
||||
os << action.asString() ; |
||||
return os ; |
||||
} |
||||
|
||||
// --- MouseLeftAction ------------------------------------------------
|
||||
|
||||
MouseLeftAction::MouseLeftAction( const ApiAction* pAction ) |
||||
: Action( pAction ) |
||||
{ |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
void |
||||
MouseLeftAction::doAction() const |
||||
{ |
||||
assert(0);//FIXME
|
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
string MouseLeftAction::asString() const { return "<MouseLeftAction>" ; } |
||||
|
||||
// --- MouseRightAction -----------------------------------------------
|
||||
|
||||
MouseRightAction::MouseRightAction( const ApiAction* pAction ) |
||||
: Action( pAction ) |
||||
{ |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
void |
||||
MouseRightAction::doAction() const |
||||
{ |
||||
assert(0);//FIXME
|
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
string MouseRightAction::asString() const { return "<MouseRightAction>" ; } |
||||
|
||||
// --- MouseUpAction --------------------------------------------------
|
||||
|
||||
MouseUpAction::MouseUpAction( const ApiAction* pAction ) |
||||
: Action( pAction ) |
||||
{ |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
void |
||||
MouseUpAction::doAction() const |
||||
{ |
||||
assert(0);//FIXME
|
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
string MouseUpAction::asString() const { return "<MouseUpAction>" ; } |
||||
|
||||
// --- MouseDownAction ------------------------------------------------
|
||||
|
||||
MouseDownAction::MouseDownAction( const ApiAction* pAction ) |
||||
: Action( pAction ) |
||||
{ |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
void |
||||
MouseDownAction::doAction() const |
||||
{ |
||||
assert(0);//FIXME
|
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
string MouseDownAction::asString() const { return "<MouseDownAction>" ; } |
@ -0,0 +1,77 @@ |
||||
#ifndef ACTIONS_HPP |
||||
#define ACTIONS_HPP |
||||
|
||||
#include "utils.hpp" |
||||
|
||||
struct ApiAction ; |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
class Action |
||||
{ |
||||
|
||||
// data types:
|
||||
public: |
||||
enum eActionType { atMouseLeft=1 , atMouseRight=2 , atMouseUp=3 , atMouseDown=4 } ; |
||||
|
||||
// constructors/destructor:
|
||||
public: |
||||
static Action* allocAction( const ApiAction* pAction ) ; |
||||
protected: |
||||
Action( const ApiAction* pAction ) ; |
||||
DISABLE_COPY_ASSIGNMENT( Action ) ; |
||||
|
||||
// action methods:
|
||||
virtual void doAction() const = 0 ; |
||||
|
||||
// access methods:
|
||||
public: |
||||
virtual std::string asString() const = 0 ; |
||||
|
||||
} ; |
||||
|
||||
typedef PtrVector<Action> ActionPtrVector ; |
||||
|
||||
// inserter
|
||||
std::ostream& operator<<( std::ostream& , const Action& ) ; |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
#define DEFINE_ACTION_CLASS( ClassName ) \ |
||||
public: \
|
||||
ClassName( const ApiAction* pAction ) ; \
|
||||
public: \
|
||||
virtual std::string asString() const ; \
|
||||
virtual void doAction() const ; |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
class MouseLeftAction : public Action |
||||
{ |
||||
DEFINE_ACTION_CLASS( MouseLeftAction ) ; |
||||
} ; |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
class MouseRightAction : public Action |
||||
{ |
||||
DEFINE_ACTION_CLASS( MouseRightAction ) ; |
||||
} ; |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
class MouseUpAction : public Action |
||||
{ |
||||
DEFINE_ACTION_CLASS( MouseUpAction ) ; |
||||
} ; |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
class MouseDownAction : public Action |
||||
{ |
||||
DEFINE_ACTION_CLASS( MouseDownAction ) ; |
||||
} ; |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#endif // ACTIONS_HPP
|
@ -0,0 +1,76 @@ |
||||
#include "appProfile.hpp" |
||||
#include "api.hpp" |
||||
|
||||
using namespace std ; |
||||
|
||||
// --- CONSTRUCTORS ----------------------------------------------------
|
||||
|
||||
AppProfile::AppProfile( |
||||
const ApiAppProfile* pAppProfile , |
||||
const ApiEvent* pEvents , int nEvents , |
||||
const ApiAction* pActions , int nActions |
||||
) |
||||
{ |
||||
// initialize the Device
|
||||
mApp = toUtf8( pAppProfile->mpApp ) ; |
||||
|
||||
// initialize the Device
|
||||
for ( int i=0 ; i < nEvents ; ++i ) |
||||
{ |
||||
const ApiEvent* pEvent = pEvents + i ; |
||||
// validate the Action index/count
|
||||
if ( pEvent->mActionStartIndex < 0 || pEvent->mActionStartIndex >= nActions ) |
||||
{ |
||||
throw runtime_error( |
||||
MAKE_STRING( |
||||
"Invalid Action start index: " << pEvent->mActionStartIndex |
||||
<< " (#=" << nActions << ")" |
||||
) |
||||
) ; |
||||
} |
||||
if ( pEvent->mActionCount < 0 || pEvent->mActionStartIndex + pEvent->mActionCount > nActions ) |
||||
{ |
||||
throw runtime_error( |
||||
MAKE_STRING( |
||||
"Invalid Action count: " << pEvent->mActionCount |
||||
<< " (s=" << pEvent->mActionStartIndex << ", #=" << nActions << ")" |
||||
) |
||||
) ; |
||||
} |
||||
// add the next Event
|
||||
mEvents.push_back( |
||||
new Event( |
||||
pEvent , |
||||
pActions+pEvent->mActionStartIndex , pEvent->mActionCount |
||||
) |
||||
) ; |
||||
} |
||||
} |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void |
||||
AppProfile::dumpAppProfile( ostream& os , const char* pPrefix ) const |
||||
{ |
||||
// dump the AppProfile
|
||||
if ( pPrefix == NULL ) |
||||
pPrefix = "" ; |
||||
os << pPrefix << "AppProfile: \"" << app() << "\"" << endl ; |
||||
for ( EventPtrVector::const_iterator it=events().begin() ; it != events().end() ; ++it ) |
||||
(*it)->dumpEvent( os , MAKE_CSTRING(pPrefix << " ") ) ; |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
ostream& |
||||
operator<<( ostream& os , const AppProfile& appProfile ) |
||||
{ |
||||
// insert the AppProfile
|
||||
os << "[AppProfile:" << appProfile.app() << "]" ; |
||||
return os ; |
||||
} |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
const string& AppProfile::app() const { return mApp ; } |
||||
const EventPtrVector& AppProfile::events() const { return mEvents ; } |
@ -0,0 +1,45 @@ |
||||
#ifndef APPPROFILE_HPP |
||||
#define APPPROFILE_HPP |
||||
|
||||
#include "event.hpp" |
||||
#include "utils.hpp" |
||||
|
||||
struct ApiAppProfile ; |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
class AppProfile |
||||
{ |
||||
|
||||
// constructors/destructor:
|
||||
public: |
||||
AppProfile( |
||||
const ApiAppProfile* pAppProfile , |
||||
const ApiEvent* pEvents , int nEvents , |
||||
const ApiAction* pActions , int nActions |
||||
) ; |
||||
DISABLE_COPY_ASSIGNMENT( AppProfile ) ; |
||||
|
||||
// access methods:
|
||||
public: |
||||
const std::string& app() const ; |
||||
const EventPtrVector& events() const ; |
||||
|
||||
// miscellaneous methods:
|
||||
public: |
||||
void dumpAppProfile( std::ostream& os , const char* pPrefix="" ) const ; |
||||
|
||||
// data members:
|
||||
private: |
||||
std::string mApp ; |
||||
EventPtrVector mEvents ; |
||||
} ; |
||||
|
||||
typedef PtrVector<AppProfile> AppProfilePtrVector ; |
||||
|
||||
// inserter
|
||||
std::ostream& operator<<( std::ostream& , const AppProfile& ) ; |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#endif // APPPROFILE_HPP
|
@ -0,0 +1,77 @@ |
||||
#include "deviceConfig.hpp" |
||||
#include "api.hpp" |
||||
|
||||
using namespace std ; |
||||
|
||||
// --- CONSTRUCTORS ----------------------------------------------------
|
||||
|
||||
DeviceConfig::DeviceConfig( |
||||
const ApiDeviceConfig* pDeviceConfig , |
||||
const ApiAppProfile* pAppProfiles , int nAppProfiles , |
||||
const ApiEvent* pEvents , int nEvents , |
||||
const ApiAction* pActions , int nActions |
||||
) |
||||
{ |
||||
// initialize the DeviceConfig
|
||||
mDeviceId = pDeviceConfig->mDeviceId ; |
||||
for ( int i=0 ; i < nAppProfiles ; ++i ) |
||||
{ |
||||
const ApiAppProfile* pAppProfile = pAppProfiles + i ; |
||||
// validate the Event index/count
|
||||
if ( pAppProfile->mEventStartIndex < 0 || pAppProfile->mEventStartIndex >= nEvents ) |
||||
{ |
||||
throw runtime_error( |
||||
MAKE_STRING( |
||||
"Invalid Event start index: " << pAppProfile->mEventStartIndex |
||||
<< " (#=" << nEvents << ")" |
||||
) |
||||
) ; |
||||
} |
||||
if ( pAppProfile->mEventCount < 0 || pAppProfile->mEventStartIndex + pAppProfile->mEventCount > nEvents ) |
||||
{ |
||||
throw runtime_error( |
||||
MAKE_STRING( |
||||
"Invalid Event count: " << pAppProfile->mEventCount |
||||
<< " (s=" << pAppProfile->mEventStartIndex << ", #=" << nEvents << ")" |
||||
) |
||||
) ; |
||||
} |
||||
// add the next Event
|
||||
mAppProfiles.push_back( |
||||
new AppProfile( |
||||
pAppProfile , |
||||
pEvents+pAppProfile->mEventStartIndex , pAppProfile->mEventCount , |
||||
pActions , nActions |
||||
) |
||||
) ; |
||||
} |
||||
} |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void |
||||
DeviceConfig::dumpDeviceConfig( ostream& os , const char* pPrefix ) const |
||||
{ |
||||
// dump the DeviceConfig
|
||||
if ( pPrefix == NULL ) |
||||
pPrefix = "" ; |
||||
os << pPrefix << *this << ":" << endl ; |
||||
os << pPrefix << " deviceId = " << deviceId() << endl ; |
||||
for ( AppProfilePtrVector::const_iterator it=appProfiles().begin() ; it != appProfiles().end() ; ++it ) |
||||
(*it)->dumpAppProfile( os , MAKE_CSTRING(pPrefix << " ") ) ; |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
ostream& |
||||
operator<<( ostream& os , const DeviceConfig& deviceConfig ) |
||||
{ |
||||
// insert the DeviceConfig
|
||||
os << "[DeviceConfig:" << deviceConfig.deviceId() << "]" ; |
||||
return os ; |
||||
} |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
int DeviceConfig::deviceId() const { return mDeviceId ; } |
||||
const AppProfilePtrVector& DeviceConfig::appProfiles() const { return mAppProfiles ; } |
@ -0,0 +1,45 @@ |
||||
#ifndef DEVICECONFIG_HPP |
||||
#define DEVICECONFIG_HPP |
||||
|
||||
#include "appProfile.hpp" |
||||
#include "utils.hpp" |
||||
|
||||
struct ApiDeviceConfig ; |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
class DeviceConfig |
||||
{ |
||||
|
||||
// constructors/destructor:
|
||||
public: |
||||
DeviceConfig( |
||||
const ApiDeviceConfig* pDeviceConfig , |
||||
const ApiAppProfile* pAppProfiles , int nAppProfiles , |
||||
const ApiEvent* pEvents , int nEvents , |
||||
const ApiAction* pActions , int nActions |
||||
) ; |
||||
DISABLE_COPY_ASSIGNMENT( DeviceConfig ) ; |
||||
|
||||
// access methods:
|
||||
public: |
||||
int deviceId() const ; |
||||
const AppProfilePtrVector& appProfiles() const ; |
||||
|
||||
// miscellaneous methods:
|
||||
public: |
||||
void dumpDeviceConfig( std::ostream& os , const char* pPrefix="" ) const ; |
||||
|
||||
// data members:
|
||||
private: |
||||
int mDeviceId ; |
||||
AppProfilePtrVector mAppProfiles ; |
||||
|
||||
} ; |
||||
|
||||
// inserter
|
||||
std::ostream& operator<<( std::ostream& , const DeviceConfig& ) ; |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#endif // DEVICECONFIG_HPP
|
@ -0,0 +1,67 @@ |
||||
#include "event.hpp" |
||||
#include "api.hpp" |
||||
#include "utils.hpp" |
||||
|
||||
using namespace std ; |
||||
|
||||
// --- LOCAL DATA ------------------------------------------------------
|
||||
|
||||
static EnumStringInfo gEventTypeStringTable[] = |
||||
{ |
||||
{ Event::etMouseLeft , "mouseLeft" } , |
||||
{ Event::etMouseRight , "mouseRight" } , |
||||
{ Event::etMouseUp , "mouseUp" } , |
||||
{ Event::etMouseDown , "mouseDown" } , |
||||
{ -1 , NULL } |
||||
} ; |
||||
|
||||
static BitFlagsInfo gKeyModifiersStringTable[] = |
||||
{ |
||||
{ Event::kmCtrl , "Ctrl" } , |
||||
{ Event::kmAlt , "Alt" } , |
||||
{ Event::kmShift , "Shift" } , |
||||
{ -1 , NULL } , |
||||
} ; |
||||
|
||||
// --- CONSTRUCTORS ----------------------------------------------------
|
||||
|
||||
Event::Event( const ApiEvent* pEvent , const ApiAction* pActions , int nActions ) |
||||
{ |
||||
// initialize the Event
|
||||
mEventType = pEvent->mEventType ; |
||||
mKeyModifiers = pEvent->mKeyModifiers ; |
||||
|
||||
// initialize the Event
|
||||
for ( int i=0 ; i < nActions ; ++i ) |
||||
mActions.push_back( Action::allocAction( pActions+i ) ) ; |
||||
} |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void |
||||
Event::dumpEvent( ostream& os , const char* pPrefix ) const |
||||
{ |
||||
// dump the Event
|
||||
os << pPrefix << *this << ":" << endl ; |
||||
for ( ActionPtrVector::const_iterator it=actions().begin() ; it != actions().end() ; ++it ) |
||||
os << pPrefix << " " << *(*it) << endl ; |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
ostream& |
||||
operator<<( ostream& os , const Event& evt ) |
||||
{ |
||||
// insert the Event
|
||||
os << "{Event:" << enumString(gEventTypeStringTable,evt.eventType()) ; |
||||
if ( evt.keyModifiers() != 0 ) |
||||
os << ":" << bitFlagsString(gKeyModifiersStringTable,evt.keyModifiers(),'+') ; |
||||
os << "}" ; |
||||
return os ; |
||||
} |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
int Event::eventType() const { return mEventType ; } |
||||
int Event::keyModifiers() const { return mKeyModifiers ; } |
||||
const ActionPtrVector& Event::actions() const { return mActions ; } |
@ -0,0 +1,47 @@ |
||||
#ifndef EVENT_HPP |
||||
#define EVENT_HPP |
||||
|
||||
#include "actions.hpp" |
||||
#include "utils.hpp" |
||||
|
||||
struct ApiEvent ; |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
class Event |
||||
{ |
||||
|
||||
// data types:
|
||||
public: |
||||
enum eEventType { etMouseLeft=1 , etMouseRight=2 , etMouseUp=3 , etMouseDown=4 } ; |
||||
enum eKeyModifiers { kmCtrl=0x0001 , kmAlt=0x0002 , kmShift=0x0004 } ; |
||||
|
||||
// constructors/destructor:
|
||||
public: |
||||
Event( const ApiEvent* pEvent , const ApiAction* pActions , int nActions ) ; |
||||
DISABLE_COPY_ASSIGNMENT( Event ) ; |
||||
|
||||
// access methods:
|
||||
public: |
||||
int eventType() const ; |
||||
int keyModifiers() const ; |
||||
const ActionPtrVector& actions() const ; |
||||
public: |
||||
void dumpEvent( std::ostream& os , const char* pPrefix="" ) const ; |
||||
|
||||
// data members:
|
||||
private: |
||||
int mEventType ; |
||||
int mKeyModifiers ; |
||||
ActionPtrVector mActions ; |
||||
|
||||
} ; |
||||
|
||||
typedef PtrVector<Event> EventPtrVector ; |
||||
|
||||
// inserter
|
||||
std::ostream& operator<<( std::ostream& , const Event& ) ; |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#endif // EVENT_HPP
|
Loading…
Reference in new issue