Browse Source

DynamicObject: Update signature of clone to return unique_ptr

v7.0.9
reuk 2 years ago
parent
commit
6420ab31b6
No known key found for this signature in database GPG Key ID: FCB43929F012EE5C
5 changed files with 34 additions and 7 deletions
  1. +27
    -0
      BREAKING-CHANGES.txt
  2. +4
    -4
      modules/juce_core/containers/juce_DynamicObject.cpp
  3. +1
    -1
      modules/juce_core/containers/juce_DynamicObject.h
  4. +1
    -1
      modules/juce_core/containers/juce_Variant.cpp
  5. +1
    -1
      modules/juce_core/javascript/juce_Javascript.cpp

+ 27
- 0
BREAKING-CHANGES.txt View File

@@ -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
=============



+ 4
- 4
modules/juce_core/containers/juce_DynamicObject.cpp View File

@@ -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)


+ 1
- 1
modules/juce_core/containers/juce_DynamicObject.h View File

@@ -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.


+ 1
- 1
modules/juce_core/containers/juce_Variant.cpp View File

@@ -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 {};


+ 1
- 1
modules/juce_core/javascript/juce_Javascript.cpp View File

@@ -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…
Cancel
Save