Last active
          May 13, 2021 02:35 
        
      - 
      
- 
        Save MonteLogic/99a91ab832d6ab7abc13dbc1c3bbaca6 to your computer and use it in GitHub Desktop. 
    Once the information is parsed xml I want to re-use that logic in saveDuration
  
        
  
    
      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
    
  
  
    
  | I have a function that can read and write xml but I want to change it into two functions, without copying and pasting the 10 | |
| lines of previous logic. | |
| I figured out how to get data from other .cpp files but that was with Strings. | |
| Any help is appreciated. | 
  
    
      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" | |
| //============================================================================== | |
| LoadSaveXml::LoadSaveXml() | |
| { | |
| // In your constructor, you should add any child components, and | |
| // initialise any special settings that your component needs. | |
| printNodeOne = "Printed node one, this statement was not replaced."; | |
| printNodeTwo = "Node two"; | |
| printNodeThree = "Node three"; | |
| loadData(); | |
| saveData(); | |
| } | |
| LoadSaveXml::~LoadSaveXml() | |
| { | |
| } | |
| void LoadSaveXml::loadData(){ | |
| // A preamble to queue all files. | |
| auto dir = juce::File::getCurrentWorkingDirectory(); | |
| int numTries = 0; | |
| while (! dir.getChildFile ("Resources").exists() && numTries++ < 15) | |
| dir = dir.getParentDirectory(); | |
| auto 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. | |
| auto* nodeOne = xmlMadeThing->getFirstChildElement(); | |
| printNodeOne = nodeOne->getAllSubText(); | |
| Logger::outputDebugString(printNodeOne); | |
| auto nodeTwo = nodeOne->getNextElement(); | |
| printNodeTwo = nodeTwo->getAllSubText(); | |
| Logger::outputDebugString(printNodeTwo); | |
| auto nodeThree = nodeTwo->getNextElement(); | |
| printNodeThree = nodeThree->getAllSubText(); | |
| Logger::outputDebugString(printNodeThree); | |
| // XmlElement writeNodeThree ("PATHS"); | |
| nodeThree->setAttribute ("ID", "changed1"); | |
| xmlMadeThing->writeTo(myxmlfile, XmlElement::TextFormat()); | |
| } | |
| } | |
| if (!myxmlfile.exists()) { | |
| Logger::outputDebugString(outputNameofFile); | |
| Logger::outputDebugString("Non-Existent"); | |
| } | |
| } | |
| void LoadSaveXml::saveData(){ | |
| std::cout << "Time in full: " << std::endl; | |
| auto* nodeThinger = xmlMadeThing->getFirstChildElement(); | |
| auto printNodeThinger= nodeThinger->getAllSubText(); | |
| std::cout << "print: " << printNodeThinger << std::endl; | |
| } | |
  
    
      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); | |
| std::unique_ptr<juce::XmlElement> xmlMadeThing; | |
| String printNodeOne; | |
| String printNodeTwo; | |
| String printNodeThree; | |
| 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