diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-22 15:10:49 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-22 15:10:49 +0100 |
commit | d038f192c7dcb453c9fc19082cd1b642c8f70fc8 (patch) | |
tree | bcb539657cd8b35ed742f19e5673c777ab39610c /src/crepe/util | |
parent | c3c3476f1d82aa83d8f8dc706488475dc2cf1e55 (diff) | |
parent | 4117d1d287f1d87efd0577d56819520e981a7f1c (diff) |
merge with `master`
Diffstat (limited to 'src/crepe/util')
-rw-r--r-- | src/crepe/util/Log.h | 10 | ||||
-rw-r--r-- | src/crepe/util/OptionalRef.h | 36 | ||||
-rw-r--r-- | src/crepe/util/OptionalRef.hpp | 44 | ||||
-rw-r--r-- | src/crepe/util/Proxy.h | 2 | ||||
-rw-r--r-- | src/crepe/util/Proxy.hpp | 6 |
5 files changed, 30 insertions, 68 deletions
diff --git a/src/crepe/util/Log.h b/src/crepe/util/Log.h index d55b11e..fc0bb3a 100644 --- a/src/crepe/util/Log.h +++ b/src/crepe/util/Log.h @@ -34,11 +34,11 @@ class Log { public: //! Log message severity enum Level { - TRACE, //< Include (internal) function calls - DEBUG, //< Include dbg_logf output - INFO, //< General-purpose messages - WARNING, //< Non-fatal errors - ERROR, //< Fatal errors + TRACE, //!< Include (internal) function calls + DEBUG, //!< Include dbg_logf output + INFO, //!< General-purpose messages + WARNING, //!< Non-fatal errors + ERROR, //!< Fatal errors }; /** diff --git a/src/crepe/util/OptionalRef.h b/src/crepe/util/OptionalRef.h index 8417a25..3201667 100644 --- a/src/crepe/util/OptionalRef.h +++ b/src/crepe/util/OptionalRef.h @@ -23,20 +23,7 @@ public: * * \return Reference to this (required for operator) */ - OptionalRef<T> & operator=(T & ref); - /** - * \brief Check if this reference is not empty - * - * \returns `true` if reference is set, or `false` if it is not - */ - explicit operator bool() const noexcept; - - /** - * \brief Assign new reference - * - * \param ref Reference to assign - */ - void set(T &) noexcept; + OptionalRef<T> & operator=(T & ref); /** * \brief Retrieve this reference * @@ -44,21 +31,19 @@ public: * * \throws std::runtime_error if this function is called while the reference it not set */ - T & get() const; + operator T &() const; + /** + * \brief Check if this reference is not empty + * + * \returns `true` if reference is set, or `false` if it is not + */ + explicit operator bool() const noexcept; + /** * \brief Make this reference empty */ void clear() noexcept; - //! Copy constructor - OptionalRef(const OptionalRef<T> &); - //! Move constructor - OptionalRef(OptionalRef<T> &&); - //! Copy assignment - OptionalRef<T> & operator=(const OptionalRef<T> &); - //! Move assignment - OptionalRef<T> & operator=(OptionalRef<T> &&); - private: /** * \brief Reference to the value of type \c T @@ -68,7 +53,6 @@ private: T * ref = nullptr; }; -} +} // namespace crepe #include "OptionalRef.hpp" - diff --git a/src/crepe/util/OptionalRef.hpp b/src/crepe/util/OptionalRef.hpp index 7b201b0..4608c9e 100644 --- a/src/crepe/util/OptionalRef.hpp +++ b/src/crepe/util/OptionalRef.hpp @@ -8,53 +8,19 @@ namespace crepe { template <typename T> OptionalRef<T>::OptionalRef(T & ref) { - this->set(ref); -} - -template <typename T> -OptionalRef<T>::OptionalRef(const OptionalRef<T> & other) { - this->ref = other.ref; -} - -template <typename T> -OptionalRef<T>::OptionalRef(OptionalRef<T> && other) { - this->ref = other.ref; - other.clear(); -} - -template <typename T> -OptionalRef<T> & OptionalRef<T>::operator=(const OptionalRef<T> & other) { - this->ref = other.ref; - return *this; -} - -template <typename T> -OptionalRef<T> & OptionalRef<T>::operator=(OptionalRef<T> && other) { - this->ref = other.ref; - other.clear(); - return *this; + this->ref = &ref; } template <typename T> -T & OptionalRef<T>::get() const { +OptionalRef<T>::operator T &() const { if (this->ref == nullptr) throw std::runtime_error("OptionalRef: attempt to dereference nullptr"); return *this->ref; } template <typename T> -void OptionalRef<T>::set(T & ref) noexcept { - this->ref = &ref; -} - -template <typename T> -void OptionalRef<T>::clear() noexcept { - this->ref = nullptr; -} - -template <typename T> OptionalRef<T> & OptionalRef<T>::operator=(T & ref) { - this->set(ref); + this->ref = &ref; return *this; } @@ -63,5 +29,9 @@ OptionalRef<T>::operator bool() const noexcept { return this->ref != nullptr; } +template <typename T> +void OptionalRef<T>::clear() noexcept { + this->ref = nullptr; } +} // namespace crepe diff --git a/src/crepe/util/Proxy.h b/src/crepe/util/Proxy.h index b34f7c6..789144a 100644 --- a/src/crepe/util/Proxy.h +++ b/src/crepe/util/Proxy.h @@ -16,6 +16,8 @@ template <typename T> class Proxy { public: //! Set operator + Proxy & operator=(Proxy &); + //! Set operator Proxy & operator=(const T &); //! Get operator operator const T &(); diff --git a/src/crepe/util/Proxy.hpp b/src/crepe/util/Proxy.hpp index b9923db..ef2b69f 100644 --- a/src/crepe/util/Proxy.hpp +++ b/src/crepe/util/Proxy.hpp @@ -14,6 +14,12 @@ Proxy<T> & Proxy<T>::operator=(const T & val) { } template <typename T> +Proxy<T> & Proxy<T>::operator=(Proxy & proxy) { + this->broker.set(T(proxy)); + return *this; +} + +template <typename T> Proxy<T>::operator const T &() { return this->broker.get(); } |