Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ofParameter: deprecate newReference() in favour of getSharedPtr() [NB: just a rename] #8128

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Next Next commit
ofParameter: deprecate newReference() in favour of getSharedPtr()
  • Loading branch information
alexandreburton committed Sep 21, 2024
commit 4636b48955f669a7abf538d51c3cd039f5a13633
6 changes: 5 additions & 1 deletion libs/openFrameworks/types/ofParameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,12 @@ void ofParameter<void>::setSerializable(bool serializable) {
obj->serializable = serializable;
}

std::shared_ptr<ofAbstractParameter> ofParameter<void>::getSharedPtr() const {
return std::make_shared<ofParameter<void>>(*this);
}

std::shared_ptr<ofAbstractParameter> ofParameter<void>::newReference() const {
return std::make_shared<ofParameter<void>>(*this);
return getSharedPtr();
}

void ofParameter<void>::setParent(ofParameterGroup & parent) {
Expand Down
24 changes: 24 additions & 0 deletions libs/openFrameworks/types/ofParameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ class ofAbstractParameter {

virtual bool isSerializable() const = 0;
virtual bool isReadOnly() const = 0;

[[deprecated("use getSharedPtr")]]
virtual std::shared_ptr<ofAbstractParameter> newReference() const = 0;
virtual std::shared_ptr<ofAbstractParameter> getSharedPtr() const = 0;

virtual bool isReferenceTo(const ofAbstractParameter & other) const;

Expand Down Expand Up @@ -249,7 +252,10 @@ class ofParameterGroup : public ofAbstractParameter {
void setSerializable(bool serializable);
bool isSerializable() const;
bool isReadOnly() const;

[[deprecated("use getSharedPtr")]]
std::shared_ptr<ofAbstractParameter> newReference() const;
std::shared_ptr<ofAbstractParameter> getSharedPtr() const;

void setParent(ofParameterGroup & parent);

Expand Down Expand Up @@ -593,7 +599,10 @@ class ofParameter : public ofAbstractParameter {
bool isInit() const;

void setSerializable(bool serializable);

[[deprecated("use getSharedPtr")]]
std::shared_ptr<ofAbstractParameter> newReference() const;
std::shared_ptr<ofAbstractParameter> getSharedPtr() const;

void setParent(ofParameterGroup & _parent);

Expand Down Expand Up @@ -1006,6 +1015,11 @@ void ofParameter<ParameterType>::makeReferenceTo(ofParameter<ParameterType> & mo

template <typename ParameterType>
std::shared_ptr<ofAbstractParameter> ofParameter<ParameterType>::newReference() const {
return getSharedPtr();
}

template <typename ParameterType>
std::shared_ptr<ofAbstractParameter> ofParameter<ParameterType>::getSharedPtr() const {
return std::make_shared<ofParameter<ParameterType>>(*this);
}

Expand Down Expand Up @@ -1073,7 +1087,10 @@ class ofParameter<void> : public ofAbstractParameter {
void makeReferenceTo(ofParameter<void> & mom);

void setSerializable(bool serializable);

[[deprecated("use getSharedPtr")]]
std::shared_ptr<ofAbstractParameter> newReference() const;
std::shared_ptr<ofAbstractParameter> getSharedPtr() const;

void setParent(ofParameterGroup & _parent);

Expand Down Expand Up @@ -1148,7 +1165,9 @@ class ofReadOnlyParameter : public ofAbstractParameter {
template <class ListenerClass, typename ListenerMethod>
void removeListener(ListenerClass * listener, ListenerMethod method, int prio = OF_EVENT_ORDER_AFTER_APP);

[[deprecated("use getSharedPtr")]]
std::shared_ptr<ofAbstractParameter> newReference() const;
std::shared_ptr<ofAbstractParameter> getSharedPtr() const;

template <typename... Args>
std::unique_ptr<of::priv::AbstractEventToken> newListener(Args... args);
Expand Down Expand Up @@ -1509,6 +1528,11 @@ inline void ofReadOnlyParameter<ParameterType, Friend>::fromString(const std::st

template <typename ParameterType, typename Friend>
std::shared_ptr<ofAbstractParameter> ofReadOnlyParameter<ParameterType, Friend>::newReference() const {
return getSharedPtr();
}

template <typename ParameterType, typename Friend>
std::shared_ptr<ofAbstractParameter> ofReadOnlyParameter<ParameterType, Friend>::getSharedPtr() const {
return std::make_shared<ofReadOnlyParameter<ParameterType, Friend>>(*this);
}

Expand Down
6 changes: 5 additions & 1 deletion libs/openFrameworks/types/ofParameterGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ofParameterGroup::ofParameterGroup()
}

void ofParameterGroup::add(ofAbstractParameter & parameter){
shared_ptr<ofAbstractParameter> param = parameter.newReference();
auto param = parameter.getSharedPtr();
const std::string name = param->getEscapedName();
if(obj->parametersIndex.find(name) != obj->parametersIndex.end()){
ofLogWarning() << "Adding another parameter with same name '" << param->getName() << "' to group '" << getName() << "'";
Expand Down Expand Up @@ -486,6 +486,10 @@ const void* ofParameterGroup::getInternalObject() const{
}

shared_ptr<ofAbstractParameter> ofParameterGroup::newReference() const{
return getSharedPtr();
}

shared_ptr<ofAbstractParameter> ofParameterGroup::getSharedPtr() const{
return std::make_shared<ofParameterGroup>(*this);
}

Expand Down