From c29eea44e34917cd57aa7e6b6c599e28bdb0da28 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 18 Dec 2018 12:33:43 +0000 Subject: [PATCH] Added a getUndoManager() method to CachedValue and ValueWithDefault and made CachedValue weak referenceable --- modules/juce_data_structures/values/juce_CachedValue.cpp | 5 ----- modules/juce_data_structures/values/juce_CachedValue.h | 9 +++++++-- .../juce_data_structures/values/juce_ValueWithDefault.h | 7 +++++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/modules/juce_data_structures/values/juce_CachedValue.cpp b/modules/juce_data_structures/values/juce_CachedValue.cpp index ace2c41de7..ac43492bcc 100644 --- a/modules/juce_data_structures/values/juce_CachedValue.cpp +++ b/modules/juce_data_structures/values/juce_CachedValue.cpp @@ -144,11 +144,6 @@ public: expect (t["testkey"] == var()); } - - beginTest ("reset value"); - { - - } } }; diff --git a/modules/juce_data_structures/values/juce_CachedValue.h b/modules/juce_data_structures/values/juce_CachedValue.h index ef974a8cca..3fd83bb9e6 100644 --- a/modules/juce_data_structures/values/juce_CachedValue.h +++ b/modules/juce_data_structures/values/juce_CachedValue.h @@ -181,11 +181,14 @@ public: /** Returns the property ID of the referenced property. */ const Identifier& getPropertyID() const noexcept { return targetProperty; } + /** Returns the UndoManager that is being used. */ + UndoManager* getUndoManager() noexcept { return undoManager; } + private: //============================================================================== ValueTree targetTree; Identifier targetProperty; - UndoManager* undoManager; + UndoManager* undoManager = nullptr; Type defaultValue; Type cachedValue; @@ -199,13 +202,15 @@ private: void valueTreeChildOrderChanged (ValueTree&, int, int) override {} void valueTreeParentChanged (ValueTree&) override {} + //============================================================================== + JUCE_DECLARE_WEAK_REFERENCEABLE (CachedValue) JUCE_DECLARE_NON_COPYABLE (CachedValue) }; //============================================================================== template -inline CachedValue::CachedValue() : undoManager (nullptr) {} +inline CachedValue::CachedValue() {} template inline CachedValue::CachedValue (ValueTree& v, const Identifier& i, UndoManager* um) diff --git a/modules/juce_data_structures/values/juce_ValueWithDefault.h b/modules/juce_data_structures/values/juce_ValueWithDefault.h index bb056f8641..d29d73512a 100644 --- a/modules/juce_data_structures/values/juce_ValueWithDefault.h +++ b/modules/juce_data_structures/values/juce_ValueWithDefault.h @@ -41,7 +41,7 @@ class ValueWithDefault public: //============================================================================== /** Creates an unitialised ValueWithDefault. Initialise it using one of the referTo() methods. */ - ValueWithDefault() : undoManager (nullptr) {} + ValueWithDefault() {} /** Creates an ValueWithDefault object. The default value will be an empty var. */ ValueWithDefault (ValueTree& tree, const Identifier& propertyID, UndoManager* um) @@ -181,6 +181,9 @@ public: /** Returns the property ID of the referenced property. */ Identifier& getPropertyID() noexcept { return targetProperty; } + /** Returns the UndoManager that is being used. */ + UndoManager* getUndoManager() noexcept { return undoManager; } + //============================================================================== ValueWithDefault& operator= (const ValueWithDefault& other) { @@ -194,7 +197,7 @@ private: //============================================================================== ValueTree targetTree; Identifier targetProperty; - UndoManager* undoManager; + UndoManager* undoManager = nullptr; var defaultValue; String delimiter;