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.

81 lines
2.4 KiB

1 year ago
  1. /**
  2. * @file IRefCounted.h
  3. * @brief Reference counted object interface.
  4. * @copyright VisionLabs LLC
  5. * @date 25.06.2014
  6. * */
  7. #pragma once
  8. #include <cstdint>
  9. namespace fsdk {
  10. /**
  11. * @addtogroup CoreGroup SDK core interfaces
  12. * @brief Common interfaces and macros shared across all SDK objects.
  13. * @{
  14. * */
  15. /**
  16. * @brief Base strong reference counted object interface.
  17. * @details Implements common reference counting routines to control object life time.
  18. *
  19. * Use retain() to notify the object you are going to use it, thus sharing it's ownership. Use release() to release object
  20. * reference when it is no longer needed. Use getRefCount() to obtain current reference count of the object.
  21. *
  22. * All objects are created with initial strong reference count of 1 and weak reference count of 1.
  23. *
  24. * When object reference count drops to 0, it's destroyed and deallocated automatically.
  25. *
  26. * All functions of this interface have thread safe implementations in SDK classes.
  27. *
  28. * @note You should always destroy reference counted objects by calling appropriate release() function and never try to call
  29. * delete on them directly!
  30. * */
  31. struct IRefCounted {
  32. /**
  33. * @brief Increase strong reference count.
  34. * @return actual reference counter value. If less than 1 is returned, it has failed
  35. * */
  36. virtual int32_t retain() noexcept = 0;
  37. /**
  38. * @brief Increase strong reference count thread safely.
  39. * @return actual reference counter value. If less than 1 is returned, it has failed
  40. * */
  41. virtual int32_t retainLocked() noexcept = 0;
  42. /**
  43. * @brief Decrease strong reference count.
  44. * @return actual reference counter value.
  45. * */
  46. virtual int32_t release() noexcept = 0;
  47. /**
  48. * @brief Get actual strong reference count.
  49. * @return actual reference counter value.
  50. * */
  51. virtual int32_t getRefCount() const noexcept = 0;
  52. /**
  53. * @brief Increase weak reference count.
  54. * @return actual reference counter value. If less than 1 is returned, it has failed
  55. * */
  56. virtual int32_t retainWeak() noexcept = 0;
  57. /**
  58. * @brief Decrease weak reference count.
  59. * @return actual reference counter value.
  60. * */
  61. virtual int32_t releaseWeak() noexcept = 0;
  62. /**
  63. * @brief Get actual weak reference count.
  64. * @return actual reference counter value.
  65. * */
  66. virtual int32_t getWeakRefCount() const noexcept = 0;
  67. };
  68. /** @} */ // end of CoreGroup
  69. }