Skip to content

Commit

Permalink
Move type GetterFunction into struct ReadableProperty.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-rapp committed Jul 21, 2024
1 parent 144b413 commit 1dc640e
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions cpp/subprojects/common/include/mlrl/common/util/properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
#include <memory>
#include <utility>

/**
* A getter function.
*
* @tparam T The return type of the getter function
*/
template<typename T>
using GetterFunction = std::function<T&()>;

/**
* Provides access to a property via a getter function.
*
Expand All @@ -24,15 +16,20 @@ template<typename T>
struct ReadableProperty {
public:

/**
* A getter function.
*/
typedef std::function<T&()> GetterFunction;

/**
* The getter function.
*/
const GetterFunction<T> get;
const GetterFunction get;

/**
* @param getterFunction The getter function
*/
ReadableProperty(GetterFunction<T> getterFunction) : get(getterFunction) {}
ReadableProperty(GetterFunction getterFunction) : get(getterFunction) {}
};

/**
Expand Down Expand Up @@ -74,7 +71,8 @@ struct Property : public ReadableProperty<T>,
* @param getterFunction The getter function
* @param setterFunction The setter function
*/
Property(GetterFunction<T> getterFunction, typename WritableProperty<T>::SetterFunction setterFunction)
Property(typename ReadableProperty<T>::GetterFunction getterFunction,
typename WritableProperty<T>::SetterFunction setterFunction)
: ReadableProperty<T>(getterFunction), WritableProperty<T>(setterFunction) {}
};

Expand All @@ -86,7 +84,7 @@ struct Property : public ReadableProperty<T>,
* @return The `GetterFunction` that has been created
*/
template<typename T>
static inline GetterFunction<T> getterFunction(const std::unique_ptr<T>& uniquePtr) {
static inline typename ReadableProperty<T>::GetterFunction getterFunction(const std::unique_ptr<T>& uniquePtr) {
return [&uniquePtr]() -> T& {
return *uniquePtr;
};
Expand Down

0 comments on commit 1dc640e

Please sign in to comment.