-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Hi!
While testing for the 0.12.1 release, I found a regression in ofParameter related to the newly introduced ::isInit() method in commit e2bb65c
Currently, for this method to compile, ParameterType must implement operator==
openFrameworks/libs/openFrameworks/types/ofParameter.h
Lines 896 to 898 in c9561a0
| bool ofParameter<ParameterType>::isInit() const { | |
| return obj->value == obj->init; | |
| } |
Minimal example to reproduce issue.
//Does not compile
struct foo{
int x;
};
ofParameter<foo> pFoo;
//Does compile
struct bar{
int x;
bool operator==(const bar& other) const{return x == other.x;}
};
ofParameter<bar> pBar;In 0.12.0, both foo and bar compiled without issues.
I realize my use case for ofParameter goes beyond its intended design (I'm using it in ofxOceanode for sharing data between nodes). Some past issues I've encountered with ofParameter (such as #6576) have been related to this extended usage.
If you think this regression should be addressed, one potential approach could be similar to how ::fromString / ::toString handle types that lack stream operators.
Relevant parts of the ::fromString implementation:
openFrameworks/libs/openFrameworks/types/ofParameter.h
Lines 930 to 937 in c9561a0
| template <typename ParameterType> | |
| inline void ofParameter<ParameterType>::fromString(const std::string & str) { | |
| try { | |
| set(of::priv::fromStringImpl<ParameterType>(str)); | |
| } catch (...) { | |
| ofLogError("ofParameter") << "Trying to de-serialize non-serializable parameter"; | |
| } | |
| } |
openFrameworks/libs/openFrameworks/types/ofParameter.h
Lines 479 to 482 in c9561a0
| template <typename ParameterType> | |
| typename std::enable_if<of::priv::has_loading_support<ParameterType>::value, ParameterType>::type fromStringImpl(const std::string & str) { | |
| return ofFromString<ParameterType>(str); | |
| } |
openFrameworks/libs/openFrameworks/types/ofParameter.h
Lines 448 to 453 in c9561a0
| template <typename T> | |
| struct has_loading_support { | |
| static std::istream & stream; | |
| static T & x; | |
| static constexpr bool value = sizeof(check_op(stream >> x)) == sizeof(yes); | |
| }; |
cc @alexandreburton @artificiel What do you think? Would you like me to submit a PR to implement this approach?