diff --git a/libs/openFrameworks/types/ofParameter.cpp b/libs/openFrameworks/types/ofParameter.cpp index b9d72a17420..a5ce77d25dd 100644 --- a/libs/openFrameworks/types/ofParameter.cpp +++ b/libs/openFrameworks/types/ofParameter.cpp @@ -43,6 +43,10 @@ vector ofAbstractParameter::getGroupHierarchyNames() const{ return hierarchy; } +bool ofAbstractParameter::isReferenceTo(const ofAbstractParameter &other) const{ + return getInternalObject() == other.getInternalObject(); +} + ostream& operator<<(ostream& os, const ofAbstractParameter& p){ os << p.toString(); return os; diff --git a/libs/openFrameworks/types/ofParameter.h b/libs/openFrameworks/types/ofParameter.h index c2ec05aecb0..6c67d399265 100644 --- a/libs/openFrameworks/types/ofParameter.h +++ b/libs/openFrameworks/types/ofParameter.h @@ -52,10 +52,13 @@ class ofAbstractParameter{ virtual bool isReadOnly() const = 0; virtual shared_ptr newReference() const = 0; + virtual bool isReferenceTo(const ofAbstractParameter& other) const; + protected: virtual const ofParameterGroup getFirstParent() const = 0; virtual void setSerializable(bool serializable)=0; virtual string escape(const string& str) const; + virtual const void* getInternalObject() const = 0; }; @@ -88,19 +91,6 @@ class ofParameterGroup: public ofAbstractParameter { void remove(std::size_t index); void remove(const std::string& name); - template - void remove(ofParameter& param){ - std::for_each(obj->parameters.begin(), obj->parameters.end(), [&](shared_ptr& p){ - if(p->type() == param.type()){ - auto other = static_pointer_cast>(p); - if(param.isReferenceTo(*other)){ - remove(param.getName()); - } - } - }); - } - - void clear(); const ofParameter & getBool(const string& name) const; @@ -226,6 +216,9 @@ class ofParameterGroup: public ofAbstractParameter { vector >::const_reverse_iterator rbegin() const; vector >::const_reverse_iterator rend() const; +protected: + const void* getInternalObject() const; + private: class Value{ public: @@ -501,8 +494,6 @@ class ofParameter: public ofAbstractParameter{ void setSerializable(bool serializable); shared_ptr newReference() const; - bool isReferenceTo(const ofParameter& other); - void setParent(ofParameterGroup & _parent); const ofParameterGroup getFirstParent() const{ @@ -518,6 +509,9 @@ class ofParameter: public ofAbstractParameter{ size_t getNumListeners() const; +protected: + const void* getInternalObject() const; + private: class Value{ public: @@ -903,11 +897,6 @@ shared_ptr ofParameter::newReference() const return std::make_shared>(*this); } -template -bool ofParameter::isReferenceTo(const ofParameter &other){ - return obj == other.obj; -} - template void ofParameter::setParent(ofParameterGroup & parent){ obj->parents.emplace_back(parent.obj); @@ -918,6 +907,11 @@ size_t ofParameter::getNumListeners() const{ return obj->changedE.size(); } +template +const void* ofParameter::getInternalObject() const{ + return obj.get(); +} + template<> class ofParameter: public ofAbstractParameter{ public: @@ -965,6 +959,12 @@ class ofParameter: public ofAbstractParameter{ } } size_t getNumListeners() const; + +protected: + const void* getInternalObject() const{ + return obj.get(); + } + private: class Value{ public: @@ -1084,6 +1084,10 @@ class ofReadOnlyParameter: public ofAbstractParameter{ return parameter.getFirstParent(); } + const void* getInternalObject() const{ + return parameter.getInternalObject(); + } + ofParameter parameter; diff --git a/libs/openFrameworks/types/ofParameterGroup.cpp b/libs/openFrameworks/types/ofParameterGroup.cpp index 86c534e24fa..5975710387b 100644 --- a/libs/openFrameworks/types/ofParameterGroup.cpp +++ b/libs/openFrameworks/types/ofParameterGroup.cpp @@ -20,8 +20,7 @@ void ofParameterGroup::add(ofAbstractParameter & parameter){ void ofParameterGroup::remove(ofAbstractParameter ¶m){ std::for_each(obj->parameters.begin(), obj->parameters.end(), [&](shared_ptr& p){ - //TODO: this is unsafe because it does not actually compare the two parameters - if(p->type() == param.type() && p->getName() == param.getName()){ + if(p->isReferenceTo(param)){ remove(param.getName()); } }); @@ -431,6 +430,10 @@ bool ofParameterGroup::isReadOnly() const{ return false; } +const void* ofParameterGroup::getInternalObject() const{ + return obj.get(); +} + shared_ptr ofParameterGroup::newReference() const{ return std::make_shared(*this); } @@ -475,3 +478,4 @@ vector >::const_reverse_iterator ofParameterGrou return obj->parameters.rend(); } +