Skip to content

Commit 09c762f

Browse files
Virtual ofParameter reInit() (#7900)
* ofAbstractParameter::reInit (virtual) and ofParameterGroup::reInit * ofParameter<void>::isInit() inversion of result --------- Co-authored-by: alexandre burton <burton@artificiel.org>
1 parent c9561a0 commit 09c762f

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

libs/openFrameworks/types/ofParameter.h

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ template <typename ParameterType, typename Friend>
2323
class ofReadOnlyParameter;
2424

2525
class ofParameterGroup;
26-
26+
2727
//----------------------------------------------------------------------
2828
/// Base class for ofParameter, ofReadOnlyParameter and ofParameterGroup
2929
class ofAbstractParameter {
@@ -39,6 +39,7 @@ class ofAbstractParameter {
3939
virtual std::string valueType() const = 0;
4040

4141
virtual bool isInit() const = 0;
42+
virtual void reInit() = 0;
4243

4344
virtual void setParent(ofParameterGroup & _parent) = 0;
4445
std::vector<std::string> getGroupHierarchyNames() const;
@@ -192,6 +193,12 @@ class ofParameterGroup : public ofAbstractParameter {
192193
}
193194
return true;
194195
}
196+
197+
void reInit() {
198+
for (int i = 0; i < size(); i++) {
199+
get(i).reInit();
200+
}
201+
}
195202

196203
const ofAbstractParameter & get(const std::string & name) const;
197204
const ofAbstractParameter & get(std::size_t pos) const;
@@ -560,7 +567,6 @@ class ofParameter : public ofAbstractParameter {
560567

561568
ParameterType getInit() const;
562569

563-
void reInit();
564570

565571
/// \brief queries the parameter's event about its notification state
566572
/// \returns true if the event was notified since last check
@@ -641,6 +647,7 @@ class ofParameter : public ofAbstractParameter {
641647
void setMax(const ParameterType & max);
642648
void setInit(const ParameterType & init);
643649
bool isInit() const;
650+
void reInit();
644651

645652
void setSerializable(bool serializable);
646653
std::shared_ptr<ofAbstractParameter> newReference() const;
@@ -1087,7 +1094,14 @@ class ofParameter<void> : public ofAbstractParameter {
10871094
ofParameter();
10881095
ofParameter(const std::string & name);
10891096

1090-
bool isInit() const { return false; }
1097+
bool isInit() const {
1098+
ofLogVerbose("ofParameter<void>::isInit()") << "isInit() called on ofParameter<void>, where it always returns true";
1099+
return true;
1100+
}
1101+
1102+
void reInit() {
1103+
ofLogVerbose("ofParameter<void>::reInit()") << "isInit() called on ofParameter<void>, where it is a no-op";
1104+
}
10911105

10921106
ofParameter<void> & set(const std::string & name);
10931107

@@ -1264,6 +1278,7 @@ class ofReadOnlyParameter : public ofAbstractParameter {
12641278
void setMax(const ParameterType & max);
12651279
void setInit(const ParameterType & init);
12661280
bool isInit() const;
1281+
void reInit();
12671282

12681283
void fromString(const std::string & str);
12691284

@@ -1554,11 +1569,18 @@ template <typename ParameterType, typename Friend>
15541569
inline bool ofReadOnlyParameter<ParameterType, Friend>::isInit() const {
15551570
// not sure what the expected behaviour for isInit() would be for ReadOnlyParameter
15561571
// as-is, it fails with : No member named 'value' in 'ofParameter<std::string>'
1557-
// returning true while informaing with a log msg seems sane
1572+
// returning true while informing with a log msg seems sane
15581573
ofLogVerbose("ofReadOnlyParameter::isInit()") << "isInit() called on ofReadOnlyParameter, where it always returns true";
15591574
return true;
15601575
}
15611576

1577+
template <typename ParameterType, typename Friend>
1578+
inline void ofReadOnlyParameter<ParameterType, Friend>::reInit() {
1579+
// not sure what the expected behaviour for reInit() would be for ReadOnlyParameter
1580+
// informing with a log msg seems sane
1581+
ofLogVerbose("ofReadOnlyParameter::reInit()") << "reInit() called on ofReadOnlyParameter, where it is a no-op";
1582+
}
1583+
15621584
template <typename ParameterType, typename Friend>
15631585
inline void ofReadOnlyParameter<ParameterType, Friend>::fromString(const std::string & str) {
15641586
parameter.fromString(str);

0 commit comments

Comments
 (0)