parent
b2c000c476
commit
3eff0610c4
@ -0,0 +1,74 @@ |
||||
#include "device.hpp" |
||||
#include "api.hpp" |
||||
#include "utils.hpp" |
||||
|
||||
using namespace std ; |
||||
|
||||
// --- CONSTRUCTORS ----------------------------------------------------
|
||||
|
||||
Device::Device( const ApiDevice* pDevice ) |
||||
{ |
||||
// initialize the Device
|
||||
mDeviceId = pDevice->mDeviceId ; |
||||
mHID = toUtf8( pDevice->mpHID ) ; |
||||
mDeviceNumber = pDevice->mDeviceNumber ; |
||||
mDisplayName = toUtf8( pDevice->mpDisplayName ) ; |
||||
mIsEnabled = pDevice->mIsEnabled ; |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
Device::Device() |
||||
: mDeviceId(-1) |
||||
, mHID() , mDeviceNumber(-1) |
||||
, mDisplayName() , mIsEnabled(false) |
||||
{ |
||||
} |
||||
|
||||
// --- COPY/ASSIGNMENT -------------------------------------------------
|
||||
|
||||
Device& Device::operator=( const Device& rhs ) |
||||
{ |
||||
// copy the Device
|
||||
mDeviceId = rhs.deviceId() ; |
||||
mHID = rhs.hid() ; |
||||
mDeviceNumber = rhs.deviceNumber() ; |
||||
mDisplayName = rhs.displayName() ; |
||||
mIsEnabled = rhs.isEnabled() ; |
||||
return *this ; |
||||
} |
||||
|
||||
Device::Device( const Device& rhs ) { operator=(rhs) ; } |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void |
||||
Device::dumpDevice( ostream& os , const char* pPrefix ) const |
||||
{ |
||||
// dump the device
|
||||
if ( pPrefix == NULL ) |
||||
pPrefix = "" ; |
||||
os << pPrefix << "Device (id=" << deviceId() << "):" << endl ; |
||||
os << pPrefix << "- hid = \"" << hid() << "\"" << endl ; |
||||
os << pPrefix << "- deviceNumber = " << deviceNumber() << endl ; |
||||
os << pPrefix << "- displayName = \"" << displayName() << "\"" << endl ; |
||||
os << pPrefix << "- isEnabled = " << isEnabled() << endl ; |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
ostream& |
||||
operator<<( ostream& os , const Device& device ) |
||||
{ |
||||
// insert the Device
|
||||
os << "[" << device.deviceId() << ":" << device.hid() << "/" << device.deviceNumber() << "]" ; |
||||
return os ; |
||||
} |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
int Device::deviceId() const { return mDeviceId ; } |
||||
const string& Device::hid() const { return mHID ; } |
||||
int Device::deviceNumber() const { return mDeviceNumber ; } |
||||
const string& Device::displayName() const { return mDisplayName ; } |
||||
bool Device::isEnabled() const { return mIsEnabled ; } |
@ -0,0 +1,49 @@ |
||||
#ifndef DEVICE_HPP |
||||
#define DEVICE_HPP |
||||
|
||||
#include <string> |
||||
#include <ostream> |
||||
|
||||
struct ApiDevice ; |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
class Device |
||||
{ |
||||
|
||||
// constructors/destructor:
|
||||
public: |
||||
Device( const ApiDevice* pDevice ) ; |
||||
Device() ; |
||||
// copy/assignment:
|
||||
public: |
||||
Device( const Device& rhs ) ; |
||||
Device& operator=( const Device& rhs ) ; |
||||
|
||||
// access methods:
|
||||
public: |
||||
int deviceId() const ; |
||||
const std::string& hid() const ; |
||||
int deviceNumber() const ; |
||||
const std::string& displayName() const ; |
||||
bool isEnabled() const ; |
||||
|
||||
// miscellaneous methods:
|
||||
public: |
||||
void dumpDevice( std::ostream& os , const char* pPrefix="" ) const ; |
||||
|
||||
// data members:
|
||||
private: |
||||
int mDeviceId ; |
||||
std::string mHID ; |
||||
int mDeviceNumber ; |
||||
std::string mDisplayName ; |
||||
bool mIsEnabled ; |
||||
|
||||
} ; |
||||
|
||||
std::ostream& operator<<( std::ostream& , const Device& ) ; |
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#endif // DEVICE_HPP
|
Loading…
Reference in new issue