RefHolder.hpp 958 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ///
  2. /// \file Util/RefHolder.hpp
  3. ///
  4. /// Utility that allows derived objects to maintain references for garbage collection.
  5. ///
  6. /// \copyright
  7. /// Copyright (c) 2013-2014 Josh Blum
  8. /// SPDX-License-Identifier: BSL-1.0
  9. ///
  10. #pragma once
  11. #include <Pothos/Config.hpp>
  12. #include <Pothos/Object/Object.hpp>
  13. #include <vector>
  14. namespace Pothos {
  15. namespace Util {
  16. /*!
  17. * RefHolder stores a list of Objects which are reference counted objects.
  18. * Classes may derive from RefHolder and use it to store parent objects;
  19. * to avoid unnecessary lifetime management burdens for the user.
  20. */
  21. class POTHOS_API RefHolder
  22. {
  23. public:
  24. //! Virtual destructor for derived classes
  25. virtual ~RefHolder(void);
  26. //! Store a copy of this object container
  27. void holdRef(const Object &container);
  28. //! Drop a copy of this object container
  29. void dropRef(const Object &container);
  30. private:
  31. std::vector<Object> _refs;
  32. };
  33. } //namespace Util
  34. } //namespace Pothos