You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ovdTAttributeHandler.cpp 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "ovdTAttributeHandler.h"
  2. #include <cstdlib>
  3. namespace OpenViBE {
  4. namespace Designer {
  5. bool TAttributeHandler::removeAttribute(const CIdentifier& id)
  6. {
  7. if (!m_attributable) { return false; }
  8. return m_attributable->removeAttribute(id);
  9. }
  10. bool TAttributeHandler::removeAllAttributes()
  11. {
  12. if (!m_attributable) { return false; }
  13. return m_attributable->removeAllAttributes();
  14. }
  15. template <>
  16. bool TAttributeHandler::addAttribute(const CIdentifier& id, const int& value) const
  17. {
  18. if (!m_attributable) { return false; }
  19. const std::string str = std::to_string(value); // pass directly std::to_string().c_str() with int value can return anything
  20. return m_attributable->addAttribute(id, str.c_str());
  21. }
  22. template <>
  23. bool TAttributeHandler::addAttribute(const CIdentifier& id, const bool& value) const
  24. {
  25. if (!m_attributable) { return false; }
  26. return m_attributable->addAttribute(id, (value ? "true" : "false"));
  27. }
  28. template <>
  29. int TAttributeHandler::getAttributeValue<int>(const CIdentifier& id) const { return strtol(m_constAttributable->getAttributeValue(id), nullptr, 10); }
  30. template <>
  31. bool TAttributeHandler::getAttributeValue<bool>(const CIdentifier& id) const
  32. {
  33. bool res = false;
  34. const CString value(m_constAttributable->getAttributeValue(id));
  35. if (value == CString("true")) { res = true; }
  36. return res;
  37. }
  38. template <>
  39. bool TAttributeHandler::setAttributeValue(const CIdentifier& id, const int& value)
  40. {
  41. if (!m_attributable) { return false; }
  42. const std::string str = std::to_string(value); // pass directly std::to_string().c_str() with int value can return anything
  43. return m_attributable->setAttributeValue(id, str.c_str());
  44. }
  45. template <>
  46. bool TAttributeHandler::setAttributeValue(const CIdentifier& id, const bool& value)
  47. {
  48. if (!m_attributable) { return false; }
  49. return m_attributable->setAttributeValue(id, (value ? "true" : "false"));
  50. }
  51. } // namespace Designer
  52. } // namespace OpenViBE