diff --git a/3rdParty/Radon/LICENSE b/3rdParty/Radon/LICENSE new file mode 100644 index 000000000..71e60e010 --- /dev/null +++ b/3rdParty/Radon/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Dmitro Szewczuk + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/3rdParty/Radon/Radon/include/File.hpp b/3rdParty/Radon/Radon/include/File.hpp new file mode 100644 index 000000000..b60423640 --- /dev/null +++ b/3rdParty/Radon/Radon/include/File.hpp @@ -0,0 +1,29 @@ +// Copyright Dmitro bjornus Szewczuk 2017 under zlib license + +#pragma once + +#include +#include +#include + +namespace radon +{ + class Section; + + class File + { + public: + + File(const std::string & path, bool reading = true); + + std::unique_ptr
getSection(const std::string & name); + + void addSection(Section & category); + + void saveToFile(); + + private: + std::vector> sections; + std::string path; + }; +} \ No newline at end of file diff --git a/3rdParty/Radon/Radon/include/Key.hpp b/3rdParty/Radon/Radon/include/Key.hpp new file mode 100644 index 000000000..8d36ea5d0 --- /dev/null +++ b/3rdParty/Radon/Radon/include/Key.hpp @@ -0,0 +1,35 @@ +// Copyright Dmitro bjornus Szewczuk 2017 under zlib license + +#pragma once + +#include + +#include "Named.hpp" + +namespace radon +{ + class Key + : public Named + { + public: + + Key(); + + Key(const std::string & name, const std::string & value); + + Key(const std::string & name, const float & value); + + std::string getStringValue(); + + float getFloatValue(); + + void setValue(float & value); + + void setValue(std::string & value); + + private: + std::string value; + + friend class File; + }; +} \ No newline at end of file diff --git a/3rdParty/Radon/Radon/include/Named.hpp b/3rdParty/Radon/Radon/include/Named.hpp new file mode 100644 index 000000000..dbbdd1bb0 --- /dev/null +++ b/3rdParty/Radon/Radon/include/Named.hpp @@ -0,0 +1,24 @@ +// Copyright Dmitro bjornus Szewczuk 2017 under zlib license + +#pragma once + +#include + +namespace radon +{ + class Named + { + public: + + Named(); + + Named(const std::string & name); + + void setName(const std::string & name); + + std::string getName(); + + protected: + std::string name; + }; +} \ No newline at end of file diff --git a/3rdParty/Radon/Radon/include/Radon.hpp b/3rdParty/Radon/Radon/include/Radon.hpp new file mode 100644 index 000000000..de898f963 --- /dev/null +++ b/3rdParty/Radon/Radon/include/Radon.hpp @@ -0,0 +1,9 @@ +// Copyright Dmitro bjornus Szewczuk 2017 under zlib license + +#pragma once + +#include "File.hpp" +#include "Key.hpp" +#include "Named.hpp" +#include "Radon.hpp" +#include "Section.hpp" \ No newline at end of file diff --git a/3rdParty/Radon/Radon/include/Section.hpp b/3rdParty/Radon/Radon/include/Section.hpp new file mode 100644 index 000000000..488dc3387 --- /dev/null +++ b/3rdParty/Radon/Radon/include/Section.hpp @@ -0,0 +1,32 @@ +// Copyright Dmitro bjornus Szewczuk 2017 under zlib license + +#pragma once + +#include +#include + +#include "Named.hpp" + +namespace radon +{ + class Key; + + class Section + : public Named + { + public: + + Section(); + + Section(const std::string & name); + + Key getKey(const std::string & name); + + void addKey(Key & variable); + + private: + std::vector keys; + + friend class File; + }; +} \ No newline at end of file diff --git a/3rdParty/Radon/Radon/source/File.cpp b/3rdParty/Radon/Radon/source/File.cpp new file mode 100644 index 000000000..8d74967f6 --- /dev/null +++ b/3rdParty/Radon/Radon/source/File.cpp @@ -0,0 +1,83 @@ +// Copyright Dmitro bjornus Szewczuk 2017 + +#include "../include/Radon.hpp" + +#include +#include +#include +#include +#include + +namespace radon +{ + File::File(const std::string & path, bool reading) + { + this->path = path; + if (reading) + { + std::ifstream stream(path); + + if (stream.is_open()) + { + std::string buffer; + std::string nameOfCurrent = ""; + + 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
(new Section(nameOfCurrent))); + } + else + { + int equalsPosition = buffer.find('='); + + std::string nameOfElement = buffer.substr(0, equalsPosition); + std::string valueOfElement = buffer.substr(equalsPosition + 1, buffer.size()); + + sections.back()->addKey(Key(nameOfElement, valueOfElement)); + } + } + } + } + } + + + std::unique_ptr
File::getSection(const std::string & name) + { + for (auto & section : sections) + { + if (section->getName() == name) + { + return std::make_unique
(*section); + } + } + + assert(1); + } + + + void File::addSection(Section & category) + { + sections.push_back(std::make_unique
(category)); + } + + + void File::saveToFile() + { + std::ofstream file(path.data(), std::ios::out | std::ios::trunc); + + for (auto & section : sections) + { + file << "[" << section->getName() << "] \n"; + for (auto & key : section->keys) + { + file << key.getName() << "=" << key.getStringValue() << "\n"; + } + } + file.close(); + } +} \ No newline at end of file diff --git a/3rdParty/Radon/Radon/source/Key.cpp b/3rdParty/Radon/Radon/source/Key.cpp new file mode 100644 index 000000000..8310fdcfe --- /dev/null +++ b/3rdParty/Radon/Radon/source/Key.cpp @@ -0,0 +1,47 @@ +// Copyright Dmitro bjornus Szewczuk 2017 + +#include "../include/Radon.hpp" + +namespace radon +{ + Key::Key() + : Named() + { + } + + + Key::Key(const std::string & name, const std::string & value) + : Named(name), value(value) + { + } + + + Key::Key(const std::string & name, const float & value) + : Named(name), value(std::to_string(value)) + { + } + + + std::string Key::getStringValue() + { + return value; + } + + + float Key::getFloatValue() + { + return (float)(atof(value.data())); + } + + + void Key::setValue(float & value) + { + this->value = std::to_string(value); + } + + + void Key::setValue(std::string & value) + { + this->value = value; + } +} \ No newline at end of file diff --git a/3rdParty/Radon/Radon/source/Named.cpp b/3rdParty/Radon/Radon/source/Named.cpp new file mode 100644 index 000000000..d6b26f27f --- /dev/null +++ b/3rdParty/Radon/Radon/source/Named.cpp @@ -0,0 +1,29 @@ +// Copyright Dmitro bjornus Szewczuk 2017 + +#include "../include/Radon.hpp" + +namespace radon +{ + Named::Named() + { + setName("You need to set name!"); + } + + + Named::Named(const std::string & name) + { + setName(name); + } + + + void Named::setName(const std::string & name) + { + this->name = name; + } + + + std::string Named::getName() + { + return name; + } +} \ No newline at end of file diff --git a/3rdParty/Radon/Radon/source/Section.cpp b/3rdParty/Radon/Radon/source/Section.cpp new file mode 100644 index 000000000..2f2145528 --- /dev/null +++ b/3rdParty/Radon/Radon/source/Section.cpp @@ -0,0 +1,37 @@ +// Copyright Dmitro bjornus Szewczuk 2017 + +#include "../include/Radon.hpp" + +#include + +namespace radon +{ + Section::Section() + : Named() + { + } + + + Section::Section(const std::string & name) + : Named(name) + { + } + + + Key Section::getKey(const std::string & name) + { + for each (auto var in keys) + { + if (var.getName() == name) + return var; + } + + assert(1); + } + + + void Section::addKey(Key & variable) + { + keys.push_back(variable); + } +} \ No newline at end of file