Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions libs/openFrameworks/types/ofParameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include "ofColor.h"
#include "ofLog.h"
#include "ofRectangle.h"
#include "ofMathConstants.h"
#include "ofRectangle.h"
#include "ofUtils.h" // ofToString

template <typename ParameterType>
Expand Down Expand Up @@ -498,10 +498,46 @@ typename std::enable_if<!of::priv::has_loading_support<ParameterType>::value, Pa
template <typename ParameterType>
class ofParameter : public ofAbstractParameter {
public:

/// \brief constructs a default ofParameter of type ParameterType
/// \tparam ParameterType the type of the Value held by the ofParameter
ofParameter();

/// \brief constructs an ofParameter of type ParameterType as an alias of the Value of another ofParameter
/// \tparam ParameterType the type of the value held by the ofParameter
/// \param v the ofParameter to link to it's value
ofParameter(const ofParameter<ParameterType> & v);

/// \brief constructs an ofParameter of type ParameterType initialized to value of same-type v
/// \tparam ParameterType the type of the value held by the ofParameter
/// \param v the value to initialize to
ofParameter(const ParameterType & v);

/// \brief constructs an ofParameter of type ParameterType initialized to value of v
/// where v is convertible to ParameterType, with an exception for bool which can cause
/// unexpected behavious (as string and char arrays are convertible to bool)
/// \tparam ParameterType the type of the value held by the ofParameter
/// \tparam Arg a type convertible to ParameterType
/// \param v the value to initialize to
template <
typename Arg,
typename = std::enable_if_t<(std::is_convertible_v<Arg, ParameterType> and
!((std::is_same_v<ParameterType, bool>)and!(std::is_arithmetic_v<Arg>)))>>
ofParameter(const Arg & v);

/// \brief constructs a named ofParameter of type ParameterType initialized to value of v
/// \tparam ParameterType the type of the value held by the ofParameter
/// \param name name of the parameter
/// \param v the value to initialize to
ofParameter(const std::string & name, const ParameterType & v);

/// \brief constructs a named ofParameter of type ParameterType initialized to value of v,
/// with non-enforced constraints on the range of possible values
/// \tparam ParameterType the type of the value held by the ofParameter
/// \param name name of the parameter
/// \param v the value to initialize to
/// \param min the minimum value to be held
/// \param max the maximum value to be held
ofParameter(const std::string & name, const ParameterType & v, const ParameterType & min, const ParameterType & max);

const ParameterType & get() const;
Expand Down Expand Up @@ -677,7 +713,8 @@ ofParameter<ParameterType>::ofParameter(const ofParameter<ParameterType> & v)
, setMethod(std::bind(&ofParameter<ParameterType>::eventsSetValue, this, std::placeholders::_1)) { }

template <typename ParameterType>
ofParameter<ParameterType>::ofParameter(const ParameterType & v)
template <typename Arg, typename>
ofParameter<ParameterType>::ofParameter(const Arg & v)
: obj(std::make_shared<Value>(v))
, setMethod(std::bind(&ofParameter<ParameterType>::eventsSetValue, this, std::placeholders::_1)) { }

Expand Down
Loading