/********************************************************************************************************************* * Copyright 2013-2014 Tobii Technology AB. All rights reserved. * InteractionObject.inl *********************************************************************************************************************/ #if !defined(__TOBII_TX_CLIENT_CPPBINDINGS_INTERACTIONOBJECT__INL__) #define __TOBII_TX_CLIENT_CPPBINDINGS_INTERACTIONOBJECT__INL__ /*********************************************************************************************************************/ TX_NAMESPACE_BEGIN /*********************************************************************************************************************/ template inline InteractionObjectBase::InteractionObjectBase(const std::shared_ptr& spContext, THandle hObject) : HandleWrapper(spContext, hObject) { } /*********************************************************************************************************************/ template inline TX_INTERACTIONOBJECTTYPE InteractionObjectBase::GetObjectType() const { TX_INTERACTIONOBJECTTYPE objectType; TX_VALIDATE(txGetObjectType(_hObject, &objectType)); return objectType; } /*********************************************************************************************************************/ template inline bool InteractionObjectBase::TryGetProperty(std::shared_ptr* pspProperty, const std::string& propertyName) const { TX_PROPERTYHANDLE hProperty; auto result = txGetProperty(_hObject, &hProperty, propertyName.c_str()); if(result == TX_RESULT_NOTFOUND) return false; *pspProperty = _spContext->CreateProperty(hProperty); return true; } /*********************************************************************************************************************/ template inline std::shared_ptr InteractionObjectBase::GetProperty(const std::string& propertyName) const { std::shared_ptr spProperty; if(TryGetProperty(&spProperty, propertyName)) return spProperty; throw APIException(TX_RESULT_NOTFOUND, "Property not found"); } /*********************************************************************************************************************/ template inline std::vector> InteractionObjectBase::GetProperties() const { std::vector propertyHandles; TX_VALIDATE(Tx::Utils::GetBufferData(propertyHandles, txGetProperties, _hObject)); std::vector> properties; for(auto& hProperty : propertyHandles) { auto spProperty = _spContext->CreateProperty(hProperty); properties.push_back(spProperty); } return properties; } /*********************************************************************************************************************/ template inline void InteractionObjectBase::CopyPropertiesTo(const std::shared_ptr& spObject) const { TX_VALIDATE(txCopyProperties(_hObject, spObject->GetHandle())); } /*********************************************************************************************************************/ template inline std::string InteractionObjectBase::FormatAsText() const { return GetString(txFormatObjectAsText, _hObject, 512); } /*********************************************************************************************************************/ template template inline typename PropertyValueResolver::ValueType InteractionObjectBase::GetPropertyValue(const std::string& propertyName) const { auto spProperty = GetProperty(propertyName); return spProperty->GetValue(); } /*********************************************************************************************************************/ template template inline bool InteractionObjectBase::TryGetPropertyValue(TValue* pValue, const std::string& propertyName) const { std::shared_ptr spProperty; if(!TryGetProperty(&spProperty, propertyName)) return false; if(!spProperty->TryGetValue(pValue)) return false; return true; } /*********************************************************************************************************************/ /*********************************************************************************************************************/ inline InteractionObject::InteractionObject(const std::shared_ptr& spContext, TX_HANDLE hObject) : InteractionObjectBase(spContext, hObject) { } /*********************************************************************************************************************/ inline InteractionObject::~InteractionObject() { txReleaseObject(&_hObject); } /*********************************************************************************************************************/ inline std::shared_ptr InteractionObject::CreateProperty(const std::string& propertyName) { TX_PROPERTYHANDLE hProperty; TX_VALIDATE(txCreateProperty(_hObject, &hProperty, propertyName.c_str())); auto spProperty = _spContext->CreateProperty(hProperty); return spProperty; } /*********************************************************************************************************************/ template inline void InteractionObject::SetPropertyValue(const std::string& propertyName, const TValue& value) { std::shared_ptr spProperty; if(!TryGetProperty(&spProperty, propertyName)) spProperty = CreateProperty(propertyName); spProperty->SetValue(value); } /*********************************************************************************************************************/ TX_NAMESPACE_END /*********************************************************************************************************************/ #endif // !defined(__TOBII_TX_CLIENT_CPPBINDINGS_INTERACTIONOBJECT__INL__) /*********************************************************************************************************************/