1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

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

This commit is contained in:
jules 2019-05-10 18:35:00 +01:00
parent fef1093f6e
commit 6463529371
23 changed files with 63 additions and 65 deletions

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

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"; }

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();

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"));

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*);

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

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]);

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;

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

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;

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

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;

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

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

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 {};
}
//==============================================================================

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.

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());

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

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().

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)

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

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

View file

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