Control MIDI in Ableton Live with a MYO armband
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.

ThrowOnError.hpp 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (C) 2013-2014 Thalmic Labs Inc.
  2. // Distributed under the Myo SDK license agreement. See LICENSE.txt for details.
  3. #ifndef MYO_CXX_DETAIL_THROWONERROR_HPP
  4. #define MYO_CXX_DETAIL_THROWONERROR_HPP
  5. #include <stdexcept>
  6. #include <myo/libmyo.h>
  7. #if defined(_MSC_VER) && _MSC_VER <= 1800
  8. #define LIBMYO_NOEXCEPT(b)
  9. #else
  10. #if __cplusplus >= 201103L
  11. # define LIBMYO_NOEXCEPT(b) noexcept(b)
  12. #else
  13. # define LIBMYO_NOEXCEPT(b)
  14. #endif
  15. #endif
  16. namespace myo {
  17. class ThrowOnError {
  18. public:
  19. ThrowOnError()
  20. : _error()
  21. {
  22. }
  23. ~ThrowOnError() LIBMYO_NOEXCEPT(false)
  24. {
  25. if (_error)
  26. {
  27. switch (libmyo_error_kind(_error)) {
  28. case libmyo_error:
  29. case libmyo_error_runtime:
  30. {
  31. std::runtime_error exception(libmyo_error_cstring(_error));
  32. libmyo_free_error_details(_error);
  33. throw exception;
  34. }
  35. case libmyo_error_invalid_argument:
  36. {
  37. std::invalid_argument exception(libmyo_error_cstring(_error));
  38. libmyo_free_error_details(_error);
  39. throw exception;
  40. }
  41. case libmyo_success:
  42. {
  43. break;
  44. }
  45. }
  46. }
  47. }
  48. operator libmyo_error_details_t*()
  49. {
  50. return &_error;
  51. }
  52. private:
  53. libmyo_error_details_t _error;
  54. // Not implemented
  55. ThrowOnError(const ThrowOnError&); // = delete;
  56. ThrowOnError& operator=(const ThrowOnError&); // = delete;
  57. };
  58. } //namespace libmyo
  59. #endif // MYO_CXX_DETAIL_THROWONERROR_HPP