Created
May 17, 2021 01:51
-
-
Save MonteLogic/b736e3d1db104948b8a077505951c969 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is made so that the string that comes in on timeInFull is placed into the String newTimeInFull then that variable is | |
to be writeen on the xml file. However, the program is not letting me write from two different functions. | |
The same logic that works perfectly on line 106 and 107 happens to produces a segmentation dump when copied and | |
pasted onto line 138 and 139. | |
Solution find a way to properly use a shared pointer so that the function can be exectued into to different places. | |
Alternatively you caould have it fire in one place but the xml function loadData() is going to have to be run twice. | |
Once at open and again when new information is added. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
============================================================================== | |
LoadSaveXml.cpp | |
Created: 6 Apr 2021 2:56:45pm | |
Author: deckard | |
============================================================================== | |
*/ | |
#include <JuceHeader.h> | |
#include "LoadSaveXml.h" | |
#include "MainComponent.h" | |
//============================================================================== | |
LoadSaveXml::LoadSaveXml() | |
{ | |
loadData(); | |
printNodeOne = "Printed node one, this statement was not replaced."; | |
printNodeTwo = "Node two"; | |
printNodeThree = "Node three"; | |
} | |
LoadSaveXml::~LoadSaveXml() | |
{ | |
} | |
void LoadSaveXml::saveDuration(String timeInFull){ | |
std::cout << "Time in full: " << timeInFull << std::endl; | |
newTimeInFull = timeInFull; | |
writeData(); | |
} | |
void LoadSaveXml::loadData(){ | |
// A preamble to queue all files. | |
dir = juce::File::getCurrentWorkingDirectory(); | |
int numTries = 0; | |
while (! dir.getChildFile ("Resources").exists() && numTries++ < 15) | |
dir = dir.getParentDirectory(); | |
myxmlfile = dir.getChildFile ("Resources").getChildFile ("FilePaths.xml"); | |
auto outputNameofFile = myxmlfile.getFullPathName(); | |
if (myxmlfile.exists()) { | |
Logger::outputDebugString(outputNameofFile); | |
Logger::outputDebugString("Existent"); | |
xmlMadeThing = juce::XmlDocument::parse(myxmlfile); | |
if (xmlMadeThing->hasTagName("PATHS")) | |
{ | |
// Checking to see if the file exist and is reading the tags. | |
Logger::outputDebugString("Statement 6, The xml file does have that tag name."); | |
// Reading the xml string. | |
nodeOne = xmlMadeThing->getFirstChildElement(); | |
std::cout << "nodeOne first reference: " << nodeOne << std::endl; | |
printNodeOne = nodeOne->getAllSubText(); | |
Logger::outputDebugString(printNodeOne); | |
nodeTwo = nodeOne->getNextElement(); | |
printNodeTwo = nodeTwo->getAllSubText(); | |
Logger::outputDebugString(printNodeTwo); | |
nodeThree = nodeTwo->getNextElement(); | |
printNodeThree = nodeThree->getAllSubText(); | |
std::cout << printNodeThree << std::endl; | |
std::cout << newTimeInFull << std::endl; | |
// writeData(); | |
nodeThree->setAttribute ("ID", "Changed3"); | |
xmlMadeThing->writeTo(myxmlfile, XmlElement::TextFormat()); | |
} | |
} | |
if (!myxmlfile.exists()) { | |
Logger::outputDebugString(outputNameofFile); | |
Logger::outputDebugString("Non-Existent"); | |
} | |
} | |
void LoadSaveXml::writeData(){ | |
if (newTimeInFull.isEmpty() ) { | |
std::cout << "New timeInFull isEmpty" << std::endl; | |
} | |
if (newTimeInFull.isNotEmpty() ) { | |
std::cout << "New timeInFull isNotEmpty" << std::endl; | |
// The below lines uncommented produce a segmentation fault. | |
// nodeOne->setAttribute ("ID", newTimeInFull); | |
// xmlMadeThing->writeTo(myxmlfile, XmlElement::TextFormat()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
============================================================================== | |
LoadSaveXml.h | |
Created: 6 Apr 2021 2:56:45pm | |
Author: deckard | |
============================================================================== | |
*/ | |
#pragma once | |
#include <JuceHeader.h> | |
//============================================================================== | |
/* | |
*/ | |
class LoadSaveXml : public juce::Component | |
{ | |
public: | |
LoadSaveXml(); | |
~LoadSaveXml() override; | |
String newString = "YeahYeah"; | |
//void saveData(); | |
void loadData(); | |
void saveDuration(String timeInFull); | |
void writeData(); | |
// FILE * myxmlfile; | |
// FILE * dir; | |
juce::File myxmlfile; | |
juce::File dir; | |
// getFirstChildElement | |
juce::XmlElement* nodeOne = nullptr; | |
juce::XmlElement* nodeTwo = nullptr; | |
juce::XmlElement* nodeThree = nullptr; | |
juce::XmlElement* nodeFour = nullptr; | |
std::shared_ptr<juce::XmlElement> xmlMadeThing; | |
String printNodeOne; | |
String printNodeTwo; | |
String printNodeThree; // I think printNodeThree maybe destroyed once the scope ends. | |
String printNodeFour; | |
String newTimeInFull; | |
private: | |
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LoadSaveXml) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment