13 changed files with 51 additions and 404 deletions
@ -1,21 +0,0 @@
|
||||
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. |
||||
@ -1,29 +0,0 @@
|
||||
// Copyright Dmitro bjornus Szewczuk 2017 under zlib license
|
||||
|
||||
#pragma once |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
#include <memory> |
||||
|
||||
namespace radon |
||||
{ |
||||
class Section; |
||||
|
||||
class File |
||||
{ |
||||
public: |
||||
|
||||
File(const std::string & path, bool reading = true); |
||||
|
||||
Section* getSection(const std::string & name); |
||||
|
||||
void addSection(const std::string & name); |
||||
|
||||
void saveToFile(); |
||||
|
||||
private: |
||||
std::vector<Section> sections; |
||||
std::string path; |
||||
}; |
||||
} |
||||
@ -1,35 +0,0 @@
|
||||
// Copyright Dmitro bjornus Szewczuk 2017 under zlib license
|
||||
|
||||
#pragma once |
||||
|
||||
#include <string> |
||||
|
||||
#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, float value); |
||||
|
||||
std::string getStringValue(); |
||||
|
||||
float getFloatValue(); |
||||
|
||||
void setValue(float value); |
||||
|
||||
void setValue(std::string & value); |
||||
|
||||
private: |
||||
std::string value; |
||||
|
||||
friend class File; |
||||
}; |
||||
} |
||||
@ -1,24 +0,0 @@
|
||||
// Copyright Dmitro bjornus Szewczuk 2017 under zlib license
|
||||
|
||||
#pragma once |
||||
|
||||
#include <string> |
||||
|
||||
namespace radon |
||||
{ |
||||
class Named |
||||
{ |
||||
public: |
||||
|
||||
Named(); |
||||
|
||||
Named(const std::string & name); |
||||
|
||||
void setName(const std::string & name); |
||||
|
||||
std::string getName(); |
||||
|
||||
protected: |
||||
std::string name; |
||||
}; |
||||
} |
||||
@ -1,9 +0,0 @@
|
||||
// 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" |
||||
@ -1,32 +0,0 @@
|
||||
// Copyright Dmitro bjornus Szewczuk 2017 under zlib license
|
||||
|
||||
#pragma once |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#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<Key> keys; |
||||
|
||||
friend class File; |
||||
}; |
||||
} |
||||
@ -1,82 +0,0 @@
|
||||
// Copyright Dmitro bjornus Szewczuk 2017
|
||||
|
||||
#include "../include/Radon.hpp" |
||||
|
||||
#include <string> |
||||
#include <fstream> |
||||
#include <algorithm> |
||||
#include <iostream> |
||||
#include <assert.h> |
||||
|
||||
namespace radon |
||||
{ |
||||
File::File(const std::string & path, bool reading) |
||||
{ |
||||
this->path = path; |
||||
if (reading) |
||||
{ |
||||
std::ifstream stream(path.c_str()); |
||||
|
||||
if (stream.is_open()) |
||||
{ |
||||
std::string buffer; |
||||
std::string nameOfCurrent = ""; |
||||
|
||||
while (std::getline(stream, buffer)) |
||||
{ |
||||
if (buffer[0] == ';' || buffer[0] == '#') continue; |
||||
if (buffer[0] == '[') |
||||
{ |
||||
nameOfCurrent = buffer.substr(buffer.find("[") + 1, buffer.find("]") - 1); |
||||
sections.push_back(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)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
Section *File::getSection(const std::string & name) |
||||
{ |
||||
for (int i = 0; i < (int)sections.size(); i++) |
||||
{ |
||||
if (sections[i].getName() == name) |
||||
{ |
||||
return §ions[i]; |
||||
} |
||||
} |
||||
|
||||
return NULL; |
||||
} |
||||
|
||||
|
||||
void File::addSection(const std::string & name) |
||||
{ |
||||
sections.push_back(Section(name)); |
||||
} |
||||
|
||||
|
||||
void File::saveToFile() |
||||
{ |
||||
std::ofstream file(path.data(), std::ios::out | std::ios::trunc); |
||||
|
||||
for (int i = 0; i < (int)sections.size(); i++) |
||||
{ |
||||
file << "[" << sections[i].getName() << "] \n"; |
||||
for(int j = 0; j < (int)sections[i].keys.size(); j++) |
||||
{ |
||||
file << sections[i].keys[j].getName() << "=" << sections[i].keys[j].getStringValue() << "\n"; |
||||
} |
||||
} |
||||
file.close(); |
||||
} |
||||
} |
||||
@ -1,56 +0,0 @@
|
||||
// Copyright Dmitro bjornus Szewczuk 2017
|
||||
|
||||
#include "../include/Radon.hpp" |
||||
#include <sstream> |
||||
|
||||
std::string Float2String(float fVal) |
||||
{ |
||||
std::ostringstream ss; |
||||
ss << fVal; |
||||
std::string s(ss.str()); |
||||
return s; |
||||
} |
||||
|
||||
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, float value) |
||||
: Named(name), value(Float2String(value)) |
||||
{ |
||||
} |
||||
|
||||
|
||||
std::string Key::getStringValue() |
||||
{ |
||||
return value; |
||||
} |
||||
|
||||
|
||||
float Key::getFloatValue() |
||||
{ |
||||
return (float)(atof(value.data())); |
||||
} |
||||
|
||||
|
||||
void Key::setValue(float value) |
||||
{ |
||||
this->value = Float2String(value); |
||||
} |
||||
|
||||
|
||||
void Key::setValue(std::string & value) |
||||
{ |
||||
this->value = value; |
||||
} |
||||
} |
||||
@ -1,29 +0,0 @@
|
||||
// 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; |
||||
} |
||||
} |
||||
@ -1,37 +0,0 @@
|
||||
// Copyright Dmitro bjornus Szewczuk 2017
|
||||
|
||||
#include "../include/Radon.hpp" |
||||
|
||||
#include <assert.h> |
||||
|
||||
namespace radon |
||||
{ |
||||
Section::Section() |
||||
: Named() |
||||
{ |
||||
} |
||||
|
||||
|
||||
Section::Section(const std::string & name) |
||||
: Named(name) |
||||
{ |
||||
} |
||||
|
||||
|
||||
Key *Section::getKey(const std::string & name) |
||||
{ |
||||
for (int i = 0; i < (int)keys.size(); i++) |
||||
{ |
||||
if (keys[i].getName() == name) |
||||
return &keys[i]; |
||||
} |
||||
|
||||
return NULL; |
||||
} |
||||
|
||||
|
||||
void Section::addKey(Key key) |
||||
{ |
||||
keys.push_back(key); |
||||
} |
||||
} |
||||
@ -0,0 +1,11 @@
|
||||
include(FetchContent_MakeAvailableExcludeFromAll) |
||||
|
||||
include(FetchContent) |
||||
FetchContent_Declare(simpleini |
||||
GIT_REPOSITORY https://github.com/brofield/simpleini.git |
||||
GIT_TAG 7bca74f6535a37846162383e52071f380c99a43a |
||||
) |
||||
FetchContent_MakeAvailableExcludeFromAll(simpleini) |
||||
|
||||
add_library(simpleini INTERFACE) |
||||
target_include_directories(simpleini INTERFACE ${simpleini_SOURCE_DIR}) |
||||
Loading…
Reference in new issue