Browse Source

Fix saving and handeling missing ini section in Radon

pull/25/head
Anders Jenbo 7 years ago
parent
commit
c2c0dd05f2
  1. 8
      3rdParty/Radon/Radon/include/File.hpp
  2. 2
      3rdParty/Radon/Radon/include/Key.hpp
  3. 2
      3rdParty/Radon/Radon/include/Named.hpp
  4. 2
      3rdParty/Radon/Radon/include/Radon.hpp
  5. 6
      3rdParty/Radon/Radon/include/Section.hpp
  6. 23
      3rdParty/Radon/Radon/source/File.cpp
  7. 2
      3rdParty/Radon/Radon/source/Key.cpp
  8. 2
      3rdParty/Radon/Radon/source/Named.cpp
  9. 18
      3rdParty/Radon/Radon/source/Section.cpp

8
3rdParty/Radon/Radon/include/File.hpp vendored

@ -16,14 +16,14 @@ namespace radon
File(const std::string & path, bool reading = true);
std::unique_ptr<Section> getSection(const std::string & name);
Section* getSection(const std::string & name);
void addSection(Section & category);
void File::addSection(const std::string & name);
void saveToFile();
private:
std::vector<std::unique_ptr<Section>> sections;
std::vector<Section> sections;
std::string path;
};
}
}

2
3rdParty/Radon/Radon/include/Key.hpp vendored

@ -32,4 +32,4 @@ namespace radon
friend class File;
};
}
}

2
3rdParty/Radon/Radon/include/Named.hpp vendored

@ -21,4 +21,4 @@ namespace radon
protected:
std::string name;
};
}
}

2
3rdParty/Radon/Radon/include/Radon.hpp vendored

@ -6,4 +6,4 @@
#include "Key.hpp"
#include "Named.hpp"
#include "Radon.hpp"
#include "Section.hpp"
#include "Section.hpp"

6
3rdParty/Radon/Radon/include/Section.hpp vendored

@ -20,13 +20,13 @@ namespace radon
Section(const std::string & name);
Key getKey(const std::string & name);
Key *getKey(const std::string & name);
void addKey(Key & variable);
void addKey(Key variable);
private:
std::vector<Key> keys;
friend class File;
};
}
}

23
3rdParty/Radon/Radon/source/File.cpp vendored

@ -24,12 +24,11 @@ namespace radon
while (std::getline(stream, buffer))
{
buffer.erase(std::remove(buffer.begin(), buffer.end(), ' '), buffer.end());
if (buffer[0] == ';' || buffer[0] == '#') continue;
if (buffer[0] == '[')
{
nameOfCurrent = buffer.substr(buffer.find("[") + 1, buffer.find("]") - 1);
sections.push_back(std::unique_ptr<Section>(new Section(nameOfCurrent)));
sections.push_back(Section(nameOfCurrent));
}
else
{
@ -38,7 +37,7 @@ namespace radon
std::string nameOfElement = buffer.substr(0, equalsPosition);
std::string valueOfElement = buffer.substr(equalsPosition + 1, buffer.size());
sections.back()->addKey(Key(nameOfElement, valueOfElement));
sections.back().addKey(Key(nameOfElement, valueOfElement));
}
}
}
@ -46,23 +45,23 @@ namespace radon
}
std::unique_ptr<Section> File::getSection(const std::string & name)
Section *File::getSection(const std::string & name)
{
for (auto & section : sections)
{
if (section->getName() == name)
if (section.getName() == name)
{
return std::make_unique<Section>(*section);
return &section;
}
}
assert(1);
return nullptr;
}
void File::addSection(Section & category)
void File::addSection(const std::string & name)
{
sections.push_back(std::make_unique<Section>(category));
sections.push_back(Section(name));
}
@ -72,12 +71,12 @@ namespace radon
for (auto & section : sections)
{
file << "[" << section->getName() << "] \n";
for (auto & key : section->keys)
file << "[" << section.getName() << "] \n";
for (auto & key : section.keys)
{
file << key.getName() << "=" << key.getStringValue() << "\n";
}
}
file.close();
}
}
}

2
3rdParty/Radon/Radon/source/Key.cpp vendored

@ -44,4 +44,4 @@ namespace radon
{
this->value = value;
}
}
}

2
3rdParty/Radon/Radon/source/Named.cpp vendored

@ -26,4 +26,4 @@ namespace radon
{
return name;
}
}
}

18
3rdParty/Radon/Radon/source/Section.cpp vendored

@ -17,21 +17,19 @@ namespace radon
{
}
Key Section::getKey(const std::string & name)
Key *Section::getKey(const std::string & name)
{
for each (auto var in keys)
for (auto & key : keys)
{
if (var.getName() == name)
return var;
if (key.getName() == name)
return &key;
}
assert(1);
return nullptr;
}
void Section::addKey(Key & variable)
void Section::addKey(Key key)
{
keys.push_back(variable);
keys.push_back(key);
}
}
}

Loading…
Cancel
Save