8 #include "Mountain/core.hpp" 9 #include "Mountain/utils/reference_counter.hpp" 67 template <
typename... Args>
111 const T*
Get()
const;
154 template <
typename U>
158 template <
typename U>
163 explicit operator const T*()
const;
167 explicit operator T*();
172 operator bool_t()
const;
191 ReferenceCounter<T>* m_ReferenceCounter =
nullptr;
193 bool_t m_IsStrongReference =
false;
195 explicit Pointer(ReferenceCounter<T>*&& referenceCounter, bool_t strongReference);
197 void SetReferenceCounter(ReferenceCounter<T>* newReferenceCounter);
199 void CheckReferenceCounterValid();
203 #include "Mountain/utils/pointer.inl" 206 template <
typename T>
210 template <
class ParseContext>
211 constexpr
typename ParseContext::iterator
parse(ParseContext& ctx)
213 auto it = ctx.begin();
218 throw std::format_error(
"Invalid format args for Mountain::Pointer");
225 template <
class FormatContext>
228 std::ostringstream out;
230 out <<
"0x" <<
static_cast<const T*
>(pointer);
232 return std::ranges::copy(std::move(out).str(), ctx.out()).out;
243 const std::size_t h1 = std::hash<decltype(p.GetReferenceCounter())>{}(
const_cast<decltype(p.
GetReferenceCounter())
>(p.GetReferenceCounter()));
244 const std::size_t h2 = std::hash<bool_t>{}(p.GetIsStrongReference());
245 return h1 ^ (h2 << 1);
T * operator->()
Dereferences this Pointer, which gives a reference to the underlying Type.
void ToStrongReference()
Converts this Pointer to a strong reference.
static Pointer New()
Creates a Pointer with a default-initialized value.
std::size_t operator()(const Mountain::Pointer< T > &p) const noexcept
Hashes the given Mountain::Pointer.
T & operator*()
Dereferences this Pointer, which gives a reference to the underlying Type.
Pointer CreateStrongReference() const
Creates a new strong reference to this pointer.
Pointer & operator=(const Pointer &other)
Sets this Pointer to the values of other.
Custom Mountain smart pointer. Represents both a std::shared_ptr and a std::weak_ptr.
const ReferenceCounter< T > * GetReferenceCounter() const
Returns the underlying ReferenceCounter.
void Reset()
Resets this Pointer to a nullptr.
bool_t IsValid() const
Returns whether this Pointer is nullptr.
const T * Get() const
Gets the underlying raw pointer.
Pointer()=default
Creates an empty Pointer without a reference counter and pointing to nullptr.
Encapsulates a GPU shader.
bool_t GetIsStrongReference() const
Returns whether this Pointer is holding a strong reference.
void ToWeakReference()
Converts this Pointer to a weak reference.
~Pointer()
Destroys this Pointer, deallocating any memory if this is the last strong reference.
Contains all declarations of the Mountain Framework.