mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-09 23:34:20 +00:00
DynamicObject: Update signature of clone to return unique_ptr
This commit is contained in:
parent
679a33d657
commit
6420ab31b6
5 changed files with 34 additions and 7 deletions
|
|
@ -1,6 +1,33 @@
|
|||
JUCE breaking changes
|
||||
=====================
|
||||
|
||||
develop
|
||||
=======
|
||||
|
||||
Change
|
||||
------
|
||||
DynamicObject::clone now returns unique_ptr<DynamicObject> instead of
|
||||
ReferenceCountedObjectPtr<DynamicObject>.
|
||||
|
||||
Possible Issues
|
||||
---------------
|
||||
Overrides of this function using the old signature will fail to compile.
|
||||
The result of this function may need to be manually converted to a
|
||||
ReferenceCountedObjectPtr.
|
||||
|
||||
Workaround
|
||||
----------
|
||||
Update overrides to use the new signature.
|
||||
If necessary, manually construct a ReferenceCountedObjectPtr at call sites.
|
||||
|
||||
Rationale
|
||||
---------
|
||||
It's easy to safely upgrade a unique_ptr to a shared/refcounted pointer.
|
||||
However, it's not so easy to convert safely in the opposite direction.
|
||||
Generally, returning unique_ptrs rather than refcounted pointers leads to more
|
||||
flexible APIs.
|
||||
|
||||
|
||||
Version 7.0.7
|
||||
=============
|
||||
|
||||
|
|
|
|||
|
|
@ -87,11 +87,11 @@ void DynamicObject::cloneAllProperties()
|
|||
*v = v->clone();
|
||||
}
|
||||
|
||||
DynamicObject::Ptr DynamicObject::clone()
|
||||
std::unique_ptr<DynamicObject> DynamicObject::clone() const
|
||||
{
|
||||
Ptr d (new DynamicObject (*this));
|
||||
d->cloneAllProperties();
|
||||
return d;
|
||||
auto result = std::make_unique<DynamicObject> (*this);
|
||||
result->cloneAllProperties();
|
||||
return result;
|
||||
}
|
||||
|
||||
void DynamicObject::writeAsJSON (OutputStream& out, const int indentLevel, const bool allOnOneLine, int maximumDecimalPlaces)
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ public:
|
|||
with a (deep) copy of all of its properties. Subclasses can override this to
|
||||
implement their own custom copy routines.
|
||||
*/
|
||||
virtual Ptr clone();
|
||||
virtual std::unique_ptr<DynamicObject> clone() const;
|
||||
|
||||
//==============================================================================
|
||||
/** Writes this object to a text stream in JSON format.
|
||||
|
|
|
|||
|
|
@ -314,7 +314,7 @@ struct var::VariantType
|
|||
static var objectClone (const var& original)
|
||||
{
|
||||
if (auto* d = original.getDynamicObject())
|
||||
return d->clone().get();
|
||||
return d->clone().release();
|
||||
|
||||
jassertfalse; // can only clone DynamicObjects!
|
||||
return {};
|
||||
|
|
|
|||
|
|
@ -833,7 +833,7 @@ struct JavascriptEngine::RootObject : public DynamicObject
|
|||
tb.parseFunctionParamsAndBody (*this);
|
||||
}
|
||||
|
||||
DynamicObject::Ptr clone() override { return *new FunctionObject (*this); }
|
||||
std::unique_ptr<DynamicObject> clone() const override { return std::make_unique<FunctionObject> (*this); }
|
||||
|
||||
void writeAsJSON (OutputStream& out, int /*indentLevel*/, bool /*allOnOneLine*/, int /*maximumDecimalPlaces*/) override
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue