ProxyPointer.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. /*
  3. * Copyright (c) Contributors to the Open 3D Engine Project.
  4. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. *
  6. * SPDX-License-Identifier: Apache-2.0 OR MIT
  7. *
  8. */
  9. namespace AZ
  10. {
  11. namespace SceneAPI
  12. {
  13. namespace Containers
  14. {
  15. // Utility class that stores (or references if possible) the given value
  16. // but otherwise acts as a pointer. This can be useful for functions
  17. // that require returning a pointer but don't store a local copy to
  18. // return.
  19. template<typename Type>
  20. class ProxyPointer
  21. {
  22. public:
  23. ProxyPointer(const Type& value);
  24. Type& operator*();
  25. const Type& operator*() const;
  26. Type* operator->();
  27. const Type* operator->() const;
  28. private:
  29. Type m_value;
  30. };
  31. template<typename Type>
  32. class ProxyPointer<Type&>
  33. {
  34. public:
  35. ProxyPointer(Type& value);
  36. Type* operator->();
  37. const Type& operator*() const;
  38. Type& operator*();
  39. const Type* operator->() const;
  40. private:
  41. Type& m_value;
  42. };
  43. } // Containers
  44. } // SceneAPI
  45. } // AZ
  46. #include <SceneAPI/SceneCore/Containers/Utilities/ProxyPointer.inl>