Browse Source

Another batch of conversion of methods which returned bare XmlElement* to return unique_ptrs

tags/2021-05-28
jules 6 years ago
parent
commit
6463529371
23 changed files with 63 additions and 65 deletions
  1. +3
    -3
      extras/AudioPluginHost/Source/Filters/FilterGraph.cpp
  2. +2
    -2
      extras/AudioPluginHost/Source/Filters/FilterGraph.h
  3. +1
    -1
      extras/AudioPluginHost/Source/UI/MainHostWindow.cpp
  4. +2
    -2
      extras/Projucer/Source/CodeEditor/jucer_OpenDocumentManager.cpp
  5. +1
    -1
      extras/Projucer/Source/CodeEditor/jucer_OpenDocumentManager.h
  6. +5
    -5
      extras/Projucer/Source/ComponentEditor/Components/jucer_TabbedComponentHandler.h
  7. +5
    -8
      extras/Projucer/Source/ComponentEditor/Documents/jucer_ButtonDocument.cpp
  8. +2
    -2
      extras/Projucer/Source/ComponentEditor/Documents/jucer_ButtonDocument.h
  9. +4
    -6
      extras/Projucer/Source/ComponentEditor/Documents/jucer_ComponentDocument.cpp
  10. +1
    -1
      extras/Projucer/Source/ComponentEditor/Documents/jucer_ComponentDocument.h
  11. +2
    -2
      extras/Projucer/Source/ComponentEditor/jucer_JucerDocument.cpp
  12. +1
    -1
      extras/Projucer/Source/ComponentEditor/jucer_JucerDocument.h
  13. +2
    -2
      modules/juce_audio_basics/sources/juce_ChannelRemappingAudioSource.cpp
  14. +1
    -1
      modules/juce_audio_basics/sources/juce_ChannelRemappingAudioSource.h
  15. +8
    -7
      modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp
  16. +1
    -1
      modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.h
  17. +1
    -1
      modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h
  18. +4
    -2
      modules/juce_audio_processors/processors/juce_PluginDescription.cpp
  19. +1
    -1
      modules/juce_audio_processors/processors/juce_PluginDescription.h
  20. +3
    -3
      modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp
  21. +1
    -1
      modules/juce_audio_processors/scanning/juce_KnownPluginList.h
  22. +11
    -11
      modules/juce_gui_basics/commands/juce_KeyPressMappingSet.cpp
  23. +1
    -1
      modules/juce_gui_basics/commands/juce_KeyPressMappingSet.h

+ 3
- 3
extras/AudioPluginHost/Source/Filters/FilterGraph.cpp View File

@@ -354,7 +354,7 @@ static XmlElement* createNodeXml (AudioProcessorGraph::Node* const node) noexcep
{
PluginDescription pd;
plugin->fillInPluginDescription (pd);
e->addChildElement (pd.createXml());
e->addChildElement (pd.createXml().release());
}
{
@@ -437,9 +437,9 @@ void FilterGraph::createNodeFromXml (const XmlElement& xml)
}
}
XmlElement* FilterGraph::createXml() const
std::unique_ptr<XmlElement> FilterGraph::createXml() const
{
auto* xml = new XmlElement ("FILTERGRAPH");
auto xml = std::make_unique<XmlElement> ("FILTERGRAPH");
for (auto* node : graph.getNodes())
xml->addChildElement (createNodeXml (node));


+ 2
- 2
extras/AudioPluginHost/Source/Filters/FilterGraph.h View File

@@ -64,8 +64,8 @@ public:
void audioProcessorChanged (AudioProcessor*) override { changed(); }
//==============================================================================
XmlElement* createXml() const;
void restoreFromXml (const XmlElement& xml);
std::unique_ptr<XmlElement> createXml() const;
void restoreFromXml (const XmlElement&);
static const char* getFilenameSuffix() { return ".filtergraph"; }
static const char* getFilenameWildcard() { return "*.filtergraph"; }


+ 1
- 1
extras/AudioPluginHost/Source/UI/MainHostWindow.cpp View File

@@ -574,7 +574,7 @@ void MainHostWindow::showAudioSettings()
ModalCallbackFunction::create
([safeThis] (int)
{
std::unique_ptr<XmlElement> audioState (safeThis->deviceManager.createStateXml());
auto audioState = safeThis->deviceManager.createStateXml();
getAppProperties().getUserSettings()->setValue ("audioDeviceState", audioState.get());
getAppProperties().getUserSettings()->saveIfNeeded();


+ 2
- 2
extras/Projucer/Source/CodeEditor/jucer_OpenDocumentManager.cpp View File

@@ -423,9 +423,9 @@ static void saveDocList (const Array <OpenDocumentManager::Document*>& list, Xml
}
}
XmlElement* RecentDocumentList::createXML() const
std::unique_ptr<XmlElement> RecentDocumentList::createXML() const
{
XmlElement* xml = new XmlElement ("RECENT_DOCUMENTS");
auto xml = std::make_unique<XmlElement> ("RECENT_DOCUMENTS");
saveDocList (previousDocs, *xml->createNewChildElement ("PREVIOUS"));
saveDocList (nextDocs, *xml->createNewChildElement ("NEXT"));


+ 1
- 1
extras/Projucer/Source/CodeEditor/jucer_OpenDocumentManager.h View File

@@ -142,7 +142,7 @@ public:
OpenDocumentManager::Document* getClosestPreviousDocOtherThan (OpenDocumentManager::Document* oneToAvoid) const;
void restoreFromXML (Project& project, const XmlElement& xml);
XmlElement* createXML() const;
std::unique_ptr<XmlElement> createXML() const;
private:
bool documentAboutToClose (OpenDocumentManager::Document*);


+ 5
- 5
extras/Projucer/Source/ComponentEditor/Components/jucer_TabbedComponentHandler.h View File

@@ -60,7 +60,7 @@ public:
e->setAttribute ("initialTab", t->getCurrentTabIndex());
for (int i = 0; i < t->getNumTabs(); ++i)
e->addChildElement (getTabState (t, i));
e->addChildElement (getTabState (t, i).release());
return e;
}
@@ -228,9 +228,9 @@ public:
}
//==============================================================================
static XmlElement* getTabState (TabbedComponent* tc, int tabIndex)
static std::unique_ptr<XmlElement> getTabState (TabbedComponent* tc, int tabIndex)
{
XmlElement* xml = new XmlElement ("TAB");
auto xml = std::make_unique<XmlElement> ("TAB");
xml->setAttribute ("name", tc->getTabNames() [tabIndex]);
xml->setAttribute ("colour", tc->getTabBackgroundColour (tabIndex).toString());
@@ -698,7 +698,7 @@ private:
: ComponentUndoableAction<TabbedComponent> (comp, l),
indexToRemove (indexToRemove_)
{
previousState.reset (getTabState (comp, indexToRemove));
previousState = getTabState (comp, indexToRemove);
}
bool perform()
@@ -1164,7 +1164,7 @@ private:
{
showCorrectTab();
std::unique_ptr<XmlElement> state (getTabState (getComponent(), from));
auto state = getTabState (getComponent(), from);
getComponent()->removeTab (from);
addNewTab (getComponent(), to);


+ 5
- 8
extras/Projucer/Source/ComponentEditor/Documents/jucer_ButtonDocument.cpp View File

@@ -165,22 +165,19 @@ String ButtonDocument::getTypeName() const
JucerDocument* ButtonDocument::createCopy()
{
ButtonDocument* newOne = new ButtonDocument (cpp);
auto newOne = new ButtonDocument (cpp);
newOne->resources = resources;
std::unique_ptr<XmlElement> xml (createXml());
newOne->loadFromXml (*xml);
newOne->loadFromXml (*createXml());
return newOne;
}
XmlElement* ButtonDocument::createXml() const
std::unique_ptr<XmlElement> ButtonDocument::createXml() const
{
XmlElement* const doc = JucerDocument::createXml();
auto doc = JucerDocument::createXml();
for (int i = 0; i < 7; ++i)
{
XmlElement* e = paintRoutines [i]->createXml();
auto e = paintRoutines[i]->createXml();
e->setAttribute ("buttonState", stateNames [i]);
e->setAttribute ("enabled", paintStatesEnabled [i]);


+ 2
- 2
extras/Projucer/Source/ComponentEditor/Documents/jucer_ButtonDocument.h View File

@@ -55,8 +55,8 @@ public:
void addExtraClassProperties (PropertyPanel&);
//==============================================================================
XmlElement* createXml() const;
bool loadFromXml (const XmlElement& xml);
std::unique_ptr<XmlElement> createXml() const;
bool loadFromXml (const XmlElement&);
void fillInGeneratedCode (GeneratedCode& code) const;
void fillInPaintCode (GeneratedCode& code) const;


+ 4
- 6
extras/Projucer/Source/ComponentEditor/Documents/jucer_ComponentDocument.cpp View File

@@ -51,19 +51,17 @@ String ComponentDocument::getTypeName() const
JucerDocument* ComponentDocument::createCopy()
{
ComponentDocument* newOne = new ComponentDocument (cpp);
auto newOne = new ComponentDocument (cpp);
newOne->resources = resources;
std::unique_ptr<XmlElement> xml (createXml());
newOne->loadFromXml (*xml);
newOne->loadFromXml (*createXml());
return newOne;
}
XmlElement* ComponentDocument::createXml() const
std::unique_ptr<XmlElement> ComponentDocument::createXml() const
{
XmlElement* const doc = JucerDocument::createXml();
auto doc = JucerDocument::createXml();
doc->addChildElement (backgroundGraphics->createXml());
components->addToXml (*doc);


+ 1
- 1
extras/Projucer/Source/ComponentEditor/Documents/jucer_ComponentDocument.h View File

@@ -48,7 +48,7 @@ public:
ComponentLayout* getComponentLayout() const { return components.get(); }
//==============================================================================
XmlElement* createXml() const;
std::unique_ptr<XmlElement> createXml() const;
bool loadFromXml (const XmlElement& xml);
void fillInGeneratedCode (GeneratedCode& code) const;


+ 2
- 2
extras/Projucer/Source/ComponentEditor/jucer_JucerDocument.cpp View File

@@ -322,9 +322,9 @@ void JucerDocument::addExtraClassProperties (PropertyPanel&)
//==============================================================================
const char* const JucerDocument::jucerCompXmlTag = "JUCER_COMPONENT";
XmlElement* JucerDocument::createXml() const
std::unique_ptr<XmlElement> JucerDocument::createXml() const
{
XmlElement* doc = new XmlElement (jucerCompXmlTag);
auto doc = std::make_unique<XmlElement> (jucerCompXmlTag);
doc->setAttribute ("documentType", getTypeName());
doc->setAttribute ("className", className);


+ 1
- 1
extras/Projucer/Source/ComponentEditor/jucer_JucerDocument.h View File

@@ -149,7 +149,7 @@ protected:
BinaryResources resources;
virtual XmlElement* createXml() const;
virtual std::unique_ptr<XmlElement> createXml() const;
virtual bool loadFromXml (const XmlElement&);
virtual void fillInGeneratedCode (GeneratedCode&) const;


+ 2
- 2
modules/juce_audio_basics/sources/juce_ChannelRemappingAudioSource.cpp View File

@@ -145,9 +145,9 @@ void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInf
}
//==============================================================================
XmlElement* ChannelRemappingAudioSource::createXml() const
std::unique_ptr<XmlElement> ChannelRemappingAudioSource::createXml() const
{
XmlElement* e = new XmlElement ("MAPPINGS");
auto e = std::make_unique<XmlElement> ("MAPPINGS");
String ins, outs;
const ScopedLock sl (lock);


+ 1
- 1
modules/juce_audio_basics/sources/juce_ChannelRemappingAudioSource.h View File

@@ -112,7 +112,7 @@ public:
/** Returns an XML object to encapsulate the state of the mappings.
@see restoreFromXml
*/
XmlElement* createXml() const;
std::unique_ptr<XmlElement> createXml() const;
/** Restores the mappings from an XML object created by createXML().
@see createXml


+ 8
- 7
modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp View File

@@ -139,12 +139,10 @@ void AudioDeviceManager::audioDeviceListChanged()
{
closeAudioDevice();
std::unique_ptr<XmlElement> e (createStateXml());
if (e == nullptr)
initialiseDefault (preferredDeviceName, &currentSetup);
else
if (auto e = createStateXml())
initialiseFromXML (*e, true, preferredDeviceName, &currentSetup);
else
initialiseDefault (preferredDeviceName, &currentSetup);
}
if (currentAudioDevice != nullptr)
@@ -344,9 +342,12 @@ void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) cons
}
}
XmlElement* AudioDeviceManager::createStateXml() const
std::unique_ptr<XmlElement> AudioDeviceManager::createStateXml() const
{
return createCopyIfNotNull (lastExplicitSettings.get());
if (lastExplicitSettings != nullptr)
return std::make_unique<XmlElement> (*lastExplicitSettings);
return {};
}
//==============================================================================


+ 1
- 1
modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.h View File

@@ -197,7 +197,7 @@ public:
Note that this can return a null pointer if no settings have been explicitly changed
(i.e. if the device manager has just been left in its default state).
*/
XmlElement* createStateXml() const;
std::unique_ptr<XmlElement> createStateXml() const;
//==============================================================================
/** Returns the current device properties that are in use.


+ 1
- 1
modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h View File

@@ -296,7 +296,7 @@ public:
{
if (settings != nullptr)
{
std::unique_ptr<XmlElement> xml (deviceManager.createStateXml());
auto xml = deviceManager.createStateXml();
settings->setValue ("audioSetup", xml.get());


+ 4
- 2
modules/juce_audio_processors/processors/juce_PluginDescription.cpp View File

@@ -100,10 +100,12 @@ String PluginDescription::createIdentifierString() const
return pluginFormatName + "-" + name + getPluginDescSuffix (*this);
}
XmlElement* PluginDescription::createXml() const
std::unique_ptr<XmlElement> PluginDescription::createXml() const
{
XmlElement* const e = new XmlElement ("PLUGIN");
auto e = std::make_unique<XmlElement> ("PLUGIN");
e->setAttribute ("name", name);
if (descriptiveName != name)
e->setAttribute ("descriptiveName", descriptiveName);


+ 1
- 1
modules/juce_audio_processors/processors/juce_PluginDescription.h View File

@@ -140,7 +140,7 @@ public:
@see loadFromXml
*/
XmlElement* createXml() const;
std::unique_ptr<XmlElement> createXml() const;
/** Reloads the info in this structure from an XML record that was previously
saved with createXML().


+ 3
- 3
modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp View File

@@ -319,15 +319,15 @@ void KnownPluginList::sort (const SortMethod method, bool forwards)
}
//==============================================================================
XmlElement* KnownPluginList::createXml() const
std::unique_ptr<XmlElement> KnownPluginList::createXml() const
{
auto e = new XmlElement ("KNOWNPLUGINS");
auto e = std::make_unique<XmlElement> ("KNOWNPLUGINS");
{
ScopedLock lock (typesArrayLock);
for (int i = types.size(); --i >= 0;)
e->prependChildElement (types.getUnchecked(i)->createXml());
e->prependChildElement (types.getUnchecked(i)->createXml().release());
}
for (auto& b : blacklist)


+ 1
- 1
modules/juce_audio_processors/scanning/juce_KnownPluginList.h View File

@@ -167,7 +167,7 @@ public:
//==============================================================================
/** Creates some XML that can be used to store the state of this list. */
XmlElement* createXml() const;
std::unique_ptr<XmlElement> createXml() const;
/** Recreates the state of this list from its stored XML format. */
void recreateFromXml (const XmlElement& xml);


+ 11
- 11
modules/juce_gui_basics/commands/juce_KeyPressMappingSet.cpp View File

@@ -234,7 +234,7 @@ bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
if (commandId != 0)
{
const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute ("key")));
auto key = KeyPress::createFromDescription (map->getStringAttribute ("key"));
if (map->hasTagName ("MAPPING"))
{
@@ -242,9 +242,9 @@ bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
}
else if (map->hasTagName ("UNMAPPING"))
{
for (int i = mappings.size(); --i >= 0;)
if (mappings.getUnchecked(i)->commandID == commandId)
mappings.getUnchecked(i)->keypresses.removeAllInstancesOf (key);
for (auto& m : mappings)
if (m->commandID == commandId)
m->keypresses.removeAllInstancesOf (key);
}
}
}
@@ -255,30 +255,30 @@ bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
return false;
}
XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
std::unique_ptr<XmlElement> KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
{
std::unique_ptr<KeyPressMappingSet> defaultSet;
if (saveDifferencesFromDefaultSet)
{
defaultSet.reset (new KeyPressMappingSet (commandManager));
defaultSet = std::make_unique<KeyPressMappingSet> (commandManager);
defaultSet->resetToDefaultMappings();
}
XmlElement* const doc = new XmlElement ("KEYMAPPINGS");
auto doc = std::make_unique<XmlElement> ("KEYMAPPINGS");
doc->setAttribute ("basedOnDefaults", saveDifferencesFromDefaultSet);
for (int i = 0; i < mappings.size(); ++i)
{
const CommandMapping& cm = *mappings.getUnchecked(i);
auto& cm = *mappings.getUnchecked(i);
for (int j = 0; j < cm.keypresses.size(); ++j)
{
if (defaultSet == nullptr
|| ! defaultSet->containsMapping (cm.commandID, cm.keypresses.getReference (j)))
{
XmlElement* const map = doc->createNewChildElement ("MAPPING");
auto map = doc->createNewChildElement ("MAPPING");
map->setAttribute ("commandId", String::toHexString ((int) cm.commandID));
map->setAttribute ("description", commandManager.getDescriptionOfCommand (cm.commandID));
@@ -291,13 +291,13 @@ XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefault
{
for (int i = 0; i < defaultSet->mappings.size(); ++i)
{
const CommandMapping& cm = *defaultSet->mappings.getUnchecked(i);
auto& cm = *defaultSet->mappings.getUnchecked(i);
for (int j = 0; j < cm.keypresses.size(); ++j)
{
if (! containsMapping (cm.commandID, cm.keypresses.getReference (j)))
{
XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
auto map = doc->createNewChildElement ("UNMAPPING");
map->setAttribute ("commandId", String::toHexString ((int) cm.commandID));
map->setAttribute ("description", commandManager.getDescriptionOfCommand (cm.commandID));


+ 1
- 1
modules/juce_gui_basics/commands/juce_KeyPressMappingSet.h View File

@@ -206,7 +206,7 @@ public:
@see restoreFromXml
*/
XmlElement* createXml (bool saveDifferencesFromDefaultSet) const;
std::unique_ptr<XmlElement> createXml (bool saveDifferencesFromDefaultSet) const;
//==============================================================================
/** @internal */


Loading…
Cancel
Save