Browse Source

Removed the ini parser dep and just wrote my own. While I wanted to avoid it (avoid NIH sydrom), I couldn't find a lib that matched my needs and didn't crash.

master
DomtronVox 1 year ago
parent
commit
9859e5107b
12 changed files with 53 additions and 1438 deletions
  1. +0
    -32
      dependencies/cpp-feather-ini-parser/.gitignore
  2. +0
    -665
      dependencies/cpp-feather-ini-parser/INI.h
  3. +0
    -21
      dependencies/cpp-feather-ini-parser/LICENSE
  4. +0
    -80
      dependencies/cpp-feather-ini-parser/README.md
  5. +0
    -130
      dependencies/cpp-feather-ini-parser/example/example.cpp
  6. +0
    -5
      dependencies/cpp-feather-ini-parser/example/file.ini
  7. +0
    -400
      dependencies/cpp-feather-ini-parser/example/file_ints.ini
  8. +0
    -5
      dependencies/cpp-feather-ini-parser/example/merge.ini
  9. +0
    -57
      dependencies/cpp-feather-ini-parser/example/project.cbp
  10. +0
    -1
      examples/1_minimal/mods/mod1/mod.ini
  11. +1
    -1
      examples/1_minimal/src/main.cpp
  12. +52
    -41
      src/Configuration/ConfigLoaderINI.cpp

+ 0
- 32
dependencies/cpp-feather-ini-parser/.gitignore View File

@@ -1,32 +0,0 @@
# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# Other
*.depend
*.layout

+ 0
- 665
dependencies/cpp-feather-ini-parser/INI.h View File

@@ -1,665 +0,0 @@
/*
Feather INI Parser - 1.41
You are free to use this however you wish.

If you find a bug, please attept to debug the cause.
Post your environment details and the cause or fix in the issues section of GitHub.

Written by Turbine.

Website:
https://github.com/Turbine1991/feather-ini-parser
http://code.google.com/p/feather-ini-parser/downloads

Help:
Bundled example & readme.
http://code.google.com/p/feather-ini-parser/wiki/Tutorials
*/

#pragma once

#include <string>
#include <fstream>
#include <sstream>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <ostream>

#define FINI_SAFE
#define FINI_BUFFER_SIZE 256

#if __cplusplus >= 201103L
#include <unordered_map>
#define FINI_CPP11
#define ALLOCATE_SECTIONS 100
#define ALLOCATE_KEYS 5
#else
#include <map>
#endif

#ifdef FINI_WIDE_SUPPORT
#include <wchar.h>

typedef std::wstringstream fini_sstream_t;
typedef std::wstring fini_string_t;
typedef wchar_t fini_char_t;
typedef std::wifstream fini_ifstream_t;
typedef std::wofstream fini_ofstream_t;

#define fini_strlen(a) wcslen(a)
#define fini_strncpy(a, b) wcscpy(a, b)
#define fini_strncpy(a, b, c) wcsncpy(a, b, c)
#define fini_strtok(a, b) wcstok(a, b)

#define _T(x) L ##x
#else
#include <cstring>

typedef std::stringstream fini_sstream_t;
typedef std::string fini_string_t;
typedef char fini_char_t;
typedef std::ifstream fini_ifstream_t;
typedef std::ofstream fini_ofstream_t;

#define fini_strlen(a) strlen(a)
#define fini_strcpy(a, b) strcpy(a, b)
#define fini_strncpy(a, b, c) strncpy(a, b, c)
#define fini_strtok(a, b) strtok(a, b)

#define _T(x) x
#endif

#define CHAR_SIZE sizeof(fini_char_t)

///Simple converter using templates and streams to effectively required for the flexibility of handling native types
class Converters
{
public:
template <typename T, typename U>
static T Convert(U value);
template <typename T>
static void GetLine(fini_sstream_t& out, T& value);
static void GetLine(fini_sstream_t& out, fini_string_t& value);
template <typename T>
static size_t GetDataSize(T& value);
static size_t GetDataSize(fini_string_t value);
};

///
template <typename T = fini_string_t, typename U = fini_string_t, typename V = fini_string_t>
class INI
{
public:
typedef T section_t;
typedef U key_t;
typedef V value_t;
typedef INI<section_t, key_t, value_t> ini_t;

///Type definition declarations
#ifdef FINI_CPP11
typedef typename std::unordered_map<key_t, value_t> keys_t;
typedef typename std::unordered_map<section_t, keys_t*> sections_t;
#else
typedef typename std::map<key_t, value_t> keys_t;
typedef typename std::map<section_t, keys_t*> sections_t;
#endif

typedef typename keys_t::iterator keysit_t;
typedef typename sections_t::iterator sectionsit_t;

typedef typename std::pair<key_t, value_t> keyspair_t;
typedef typename std::pair<section_t, keys_t*> sectionspair_t;

typedef char data_t;

enum source_e {SOURCE_FILE, SOURCE_MEMORY};

///Data members
std::string filename;
data_t* data;
size_t dataSize;
keys_t* current;
sections_t sections;
source_e source;

///Constuctor/Destructor
//Specify the filename to associate and whether to parse immediately
INI(const std::string filename, bool doParse): filename(filename)
{
init(SOURCE_FILE, doParse);
}

//Used for loading INI from memory
INI(void* data, size_t dataSize, bool doParse): data((data_t*)data), dataSize(dataSize)
{
init(SOURCE_MEMORY, doParse);
}

~INI()
{
clear();
}

///Access Content
//Provide bracket access to section contents
keys_t& operator[](section_t section)
{
#ifdef FINI_SAFE
if (!sections[section])
sections[section] = new keys_t;
#endif

return *sections[section];
}

//Create a new section and select it
bool create(const section_t section)
{
if (select(section))
return false;

current = new keys_t;
sections[section] = current;

reserveKeys(current);

return true;
}

//Select a section for performing operations
bool select(const section_t section)
{
sectionsit_t sectionsit = sections.find(section);
if (sectionsit == sections.end())
return false;

current = sectionsit->second;

return true;
}

///Debug
friend std::ostream& operator<<(std::ostream& os, const ini_t& ini)
{
#ifdef FINI_CPP11
for(auto i = ini.sections.begin(); i != ini.sections.end(); i++) //typename ini_t::sectionsit_t
{
//Section name as ini_t::section_t
os << '[' << i->first << ']' << std::endl;

if (i->second->size() == 0) //No keys/values in section, skip to next
continue;

for(typename ini_t::keysit_t j = i->second->begin(); j != i->second->end(); j++)
{
//Name as ini_t::key_t & Value as ini_t::key_t
os << " " << j->first << "=" << j->second << std::endl;
}
}
#else
std::cout << "Error: FINI requires CPP11 when outputting to stream." << std::endl;
#endif

return os;
}
///Set
//Assign a value for key under the selected section
bool set(const key_t key, const value_t value)
{
if (current == NULL)
return false;

(*current)[key] = value;

return true;
}

template <typename W, typename X>
bool set(const W key, const X value)
{ return set(Converters::Convert<key_t>(key), Converters::Convert<value_t>(value)); }

///Get
value_t get(const key_t key, value_t def = value_t())
{
keysit_t it = current->find(key);
if (current == NULL || it == current->end())
return def;

return it->second;
}

value_t get(const section_t section, const key_t key, value_t def)
{
if (!select(section))
return def;

return get(key, def);
}

template <typename W, typename X>
X get(const W key, const X def = value_t())
{ return Converters::Convert<X>(get(Converters::Convert<key_t>(key), Converters::Convert<value_t>(def))); }

template <typename W>
fini_string_t get(const W key, const fini_char_t* def = _T("")) //Handle C string default value without casting
{ return Converters::Convert<fini_string_t>(get(Converters::Convert<key_t>(key), Converters::Convert<value_t>(def))); }

template <typename W, typename X, typename Y>
Y get(const W section, const X key, const Y def)
{ return Converters::Convert<Y>(get(Converters::Convert<section_t>(section), Converters::Convert<key_t>(key), Converters::Convert<value_t>(def))); }

template <typename W, typename X>
fini_string_t get(const W section, const X key, const fini_char_t* def) //Handle C string default value without casting
{ return Converters::Convert<fini_string_t>(get(Converters::Convert<section_t>(section), Converters::Convert<key_t>(key), Converters::Convert<value_t>(def))); }

///Functions
void parse(std::istream& file)
{
fini_char_t line[FINI_BUFFER_SIZE];
bool first = true;
fini_sstream_t out;

while(!file.eof())
{
file.getline(line, FINI_BUFFER_SIZE);

if (first)
{
first = false;
if (line[0] == 0xEF) //Allows handling of UTF-16/32 documents
{
memmove(line, line + (CHAR_SIZE * 3), CHAR_SIZE * (FINI_BUFFER_SIZE - 3));
return;
}
}

nake(line);

if (line[0])
{
size_t len = fini_strlen(line);
if (len > 0 && !((len >= 2 && (line[0] == '/' && line[1] == '/')) || (len >= 1 && line[0] == '#'))) //Ignore comment and empty lines
{
if (line[0] == '[') //Section
{
section_t section;
size_t length = fini_strlen(line) - 2; //Without section brackets
while(isspace(line[length + 1])) //Leave out any additional new line characters, not "spaces" as the name suggests
--length;

fini_char_t* ssection = (fini_char_t*)calloc(CHAR_SIZE, length + 1);
fini_strncpy(ssection, line + 1, length); //Count after first bracket

current = new keys_t;

out << ssection;
free(ssection);
Converters::GetLine(out, section);

sections[section] = current;
}
else //Key
{
key_t key;
value_t value;

fini_char_t* skey;
fini_char_t* svalue;

skey = fini_strtok(line, _T("="));
svalue = fini_strtok(NULL, _T("\n"));

if (skey && svalue)
{
size_t index = 0; //Without section brackets
while(isspace(skey[index])) //Leave out any additional new line characters, not "spaces" as the name suggests
index++;

if (index != 0) //Has preceeding white space
fini_strcpy(skey, skey + index);

out << skey;

Converters::GetLine(out, key);

out.clear();
out.str(fini_string_t());

out << svalue;
Converters::GetLine(out, value);

if (value != value_t())
(*current)[key] = value;
}
}

out.clear();
out.str(fini_string_t()); //Clear existing stream;
}
}
}
}

//Parse an INI's contents into memory from the filename given during construction
bool parse()
{
switch(source)
{
case SOURCE_FILE: {
fini_ifstream_t file(filename.c_str());

if (!file.is_open())
return false;

parse(file);

file.close();
}
break;

case SOURCE_MEMORY: {
std::stringstream sstream;
sstream.rdbuf()->pubsetbuf(data, dataSize);

parse(sstream);
}
break;
}

return true;
}

bool parseBinary()
{
fini_ifstream_t file(filename.c_str(), std::ios::binary);
if (!file.is_open())
return false;

size_t sectionCount;
size_t keyCount;
key_t key;
value_t value;
section_t section;

//file.read((fini_char_t*)&sectionCount, sizeof(sectionCount));
file >> sectionCount;

for(size_t i = 0; i < sectionCount; i++)
{
if (i > 0)
file.seekg(1 + file.tellg());

file.read((fini_char_t*)&keyCount, sizeof(keyCount));
file >> section;

create(section);

for(size_t j = 0; j < keyCount; j++)
{
file >> key;
file >> value;
set(key, value);
}
}

file.close();

return true;
}

//Clear the contents from memory
void clear()
{
clean();
sections.clear();
}

///Output
//Save from memory into file
bool save(const std::string filename = "")
{
if (!hasFileAssociation(filename))
return false;

fini_ofstream_t file(((filename == "")? this->filename: filename).c_str(), std::ios::trunc);
if (!file.is_open())
return false;

//Loop through sections
for(typename INI::sectionsit_t i = sections.begin(); i != sections.end(); i++)
{
if (i->second->size() == 0) //No keys/values in section, skip to next
continue;

//Write section
const fini_string_t temp = makeSection(i->first);
const fini_char_t* line = temp.c_str();
file.write(line, fini_strlen(line));

for(typename INI::keysit_t j = i->second->begin(); j != i->second->end(); j++)
{
//Write key and value
const fini_string_t temp = makeKeyValue(j->first, j->second);
const fini_char_t* line = temp.c_str();
file.write(line, fini_strlen(line));
}
}

file.close();

return true;
}

//Saves it without any conventional INI formatting characters, however it only uses string streams
bool saveBinary(const std::string filename = "")
{
if (!hasFileAssociation(filename))
return false;

fini_ofstream_t file(((filename == "")? this->filename: filename).c_str(), std::ios::trunc | std::ios::binary);
if (!file.is_open())
return false;

size_t sectionCount = sections.size();
size_t keyCount;

file.write((fini_char_t*)&sectionCount, sizeof(sectionCount));

//Loop through sections
for(typename INI::sectionsit_t i = sections.begin(); i != sections.end(); i++)
{
keyCount = i->second->size();
file.write((fini_char_t*)&keyCount, sizeof(keyCount));

file << i->first << std::endl;

for(typename INI::keysit_t j = i->second->begin(); j != i->second->end(); j++)
{
file << j->first << std::endl;
file << j->second << std::endl;
}
}

file.close();

return true;
}

//Saves it as a true binary file, intended to replace the existing one. Don't bother using it with all strings.
bool saveBinaryExperimental(std::string filename = "")
{
if (!hasFileAssociation(filename))
return false;

fini_ofstream_t file(((filename == "")? this->filename: filename).c_str(), std::ios::trunc | std::ios::binary);
if (!file.is_open())
return false;

size_t sectionCount = sections.size();
size_t keyCount;

file.write((fini_char_t*)&sectionCount, sizeof(sectionCount));

//Loop through sections
for(typename INI::sectionsit_t i = sections.begin(); i != sections.end(); i++)
{
keyCount = i->second->size();
file.write((fini_char_t*)&keyCount, sizeof(keyCount));

file.write((fini_char_t*)&i->first, Converters::GetDataSize(i->first));

for(typename INI::keysit_t j = i->second->begin(); j != i->second->end(); j++)
{
file.write((fini_char_t*)&j->first, Converters::GetDataSize(j->first));
file.write((fini_char_t*)&j->second, Converters::GetDataSize(j->second));
}
}

file.close();

return true;
}

//Alows another INI's contents to be insert into another, with the ability to retain the original values
void merge(ini_t& other, bool retainValues = true)
{
for(typename INI::sectionsit_t i = other.sections.begin(); i != other.sections.end(); i++)
{
if (!select(i->first)) //Create and insert all key values into a missing section
{
keys_t* keys = new keys_t(*i->second);
sections.insert(std::make_pair(i->first, keys));
}
else
{
for(typename INI::keysit_t j = i->second->begin(); j != i->second->end(); j++)
{
keysit_t it = current->find(j->first);
if (it == current->end())
current->insert(std::make_pair(j->first, j->second));
else if (!retainValues)
it->second = j->second;
}
}
}
}

private:
///Functions
//Init the INI in with values set by constructor
void init(source_e source, bool doParse)
{
this->source = source;

reserveSections();
if (doParse)
parse();
}

//Clean the contents for descruction
void clean()
{
for(sectionsit_t i = sections.begin(); i != sections.end(); i++)
delete i->second;

current = NULL;
}

//Make any alterations to the raw line
void nake(const fini_char_t*) //Strip the line of any non-interpretable characters
{

}

void reserveSections()
{
#ifdef FINI_CPP11
sections.reserve(ALLOCATE_SECTIONS);
#endif
}

void reserveKeys(keys_t* current)
{
#ifdef FINI_CPP11
current->reserve(ALLOCATE_KEYS);
#endif
}

bool hasFileAssociation(std::string filename)
{
if (source == SOURCE_MEMORY && filename == "") //No association to a file
return false;

return true;
}

///Output
//Creates a section as a string
fini_string_t makeSection(const section_t& section)
{
fini_sstream_t line;
line << '[' << section << ']' << std::endl;

return line.str();
}

//Creates a key and a value as a string
fini_string_t makeKeyValue(const key_t& key, const value_t& value)
{
fini_sstream_t line;
line << key << '=' << value << std::endl;

return line.str();
}
};

///Definitions
template <typename T, typename U>
inline T Converters::Convert(U value)
{
fini_sstream_t sout;
T result;

sout << value;
sout >> result;

sout.str(fini_string_t());

return result;
}

template <>
inline fini_string_t Converters::Convert<fini_string_t, fini_string_t>(fini_string_t value)
{
return value;
}

template <>
inline fini_string_t Converters::Convert<fini_string_t>(const fini_char_t* value)
{
return value;
}

template <typename T>
inline void Converters::GetLine(fini_sstream_t& out, T& value)
{
out >> value;
}

inline void Converters::GetLine(fini_sstream_t& out, fini_string_t& value)
{
std::getline(out, value);
}

template <typename T>
inline size_t Converters::GetDataSize(T& value)
{
return sizeof(value);
}

inline size_t Converters::GetDataSize(fini_string_t value)
{
return value.size() + 1;
}

+ 0
- 21
dependencies/cpp-feather-ini-parser/LICENSE View File

@@ -1,21 +0,0 @@
The MIT License (MIT)

Copyright (c) 2014 Turbine1991

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.

+ 0
- 80
dependencies/cpp-feather-ini-parser/README.md View File

@@ -1,80 +0,0 @@
feather-ini-parser
==================

Intuitive, fast, lightweight, header, portable INI parser for ANSI C++.

```
INI<> ini("filename.ini", true); // Open and parse
ini.get("section", "key", "value", "default"); // Get section -> key -> value, return "default" if not found
ini.set("section", "key", "value"); // Set section -> key -> value
ini.save(); // Save over initial file

for(auto i: ini.sections) // Loop through all sections
{
String section = i.first;

for(auto j: *i.second) // Loop through all key/values
String key = j.first, value = j.second;
}
```

## Methods

Statement | Return Type
------------- | -------------
ini(filename, doParse)|constructor
ini(data, dataSize, doParse)|constructor
ini.parse()|bool
ini.merge(other INI, retainValues)|void
ini.create(section)|bool
ini.select(section)|bool
ini.set(key, value)|bool
ini.get(key, dvalue = value_t())|dvalue_t
ini.save(filename = "")|bool
ini.clear()|bool
ini[section][key]|value_t&
ini[section]|keys_t&

## Example
```
// Please view the complete list of examplex in 'example/example.cpp'

#include <iostream>
#include <String>
#include "INI.h"

using namespace std;
```
...
```
INI<> ini("filename.ini", true); // Load file and parse

ini.create("section1"); //Create a section and select it (into the active context)
ini.set("key", "value");
// Set equivelant
ini.set("section1", "key", "value");
// Set equivelant (non-safe, performance)
ini["section1"]["key"] = "value";

cout << ini.get("keynumeric", "default") << endl;
// Get equivelant
cout << ini.get("section1", "keynumeric", "default") << endl;

ini.save();

// Loop through all sections and keys (CPP11)
for(auto i: ini.sections)
{
String section = i.first;
cout << "[" << section << "]" << endl;

for(auto j: *i.second)
{
String key = j.first, value = j.second;
cout << " " << key << "=" << value << endl;
}
}
```

## More
Please see the example .cpp file and Code::Blocks .cbp project for a compilable GCC and VSC++ example. Further examples include enabling wide char support.

+ 0
- 130
dependencies/cpp-feather-ini-parser/example/example.cpp View File

@@ -1,130 +0,0 @@
#include <iostream>
#include <cstring>
#include <stdint.h>
#include "../INI.h"

using namespace std;

void centerString(string str); //Printing to console
std::string getStringFromFile(const std::string& path); //Source for data loading from memory.

int main()
{
///Declare
typedef INI<> ini_t; //Makes things shorter/easier to write <Section, Key, Value>
//or
//typedef INI<string, string, string> ini_t; //Equivelant to previous line when wide characters are disabled
ini_t ini("file.ini", true); //File to open/default save filename. The constuctor is set to parse by default, unless specified as false

///Manipulate and access contents
centerString("########## Access & Manipulate Contents ##########");

//Common usage
ini.create("Section 1");
ini.create("Section 2");
ini.get("Key1", "DefaultValue");
ini.select("Section 1");
ini.set("Key2", "Value");
ini.save(); //Save contents to file, optional filename parameter available
ini.clear(); //Clear INI contents from memory

//Extended usage
ini["Section Name"]["Key"] = "Value"; //You are not required to create a section first

ini.create("Section1"); //Also selects as current section
ini.create("Section2"); //Current

ini.set("Key1", "Value1"); //Added pair under section "Section2"

ini.select("Section1"); //Current
cout << ini.get("Key1", "-1") << endl; //Returns "-1" as no key exists, no default will return NULL for data type, eg int() is 0

ini.select("Section2");
ini.set("Key1", "1.123");
cout << ini.get("Key1", -1.0) << endl; //Return value as double
ini.set(123, 123); //Will convert to provided INI data type for key/value, in this case string for both

ini.save();
ini.clear();
ini.parse(); //Parses file into objects in memory

cout << ini["Section2"]["Key1"] << endl; //Returns "Value1", slightly more overhead involved seeking section, avoid using excessively

///Iterate through sections and keys for both C++11 and C++98
centerString("########## Iterate Contents ##########");

#ifdef FINI_CPP11
for(auto i: ini.sections)
{
cout << "[" << i.first << "]" << endl;

//for(auto j = i.second->begin(); j != i.second->end(); j++)
for(auto j: *i.second)
{
cout << " " << j.first << "=" << j.second << endl;
}
}
#else
for(ini_t::sectionsit_t i = ini.sections.begin(); i != ini.sections.end(); i++)
{
//Section name as ini_t::section_t
cout << i->first << endl;

if (i->second->size() == 0) //No keys/values in section, skip to next
continue;

for(ini_t::keysit_t j = i->second->begin(); j != i->second->end(); j++)
{
//Name as ini_t::key_t & Value as ini_t::key_t
cout << " " << j->first << "=" << j->second << endl;
}
}
#endif

///Example with different data types
typedef INI <unsigned char, string, float> ini_int_t; //Makes things shorter/easier to write <Section, Key, Value>
ini_int_t ini_int("file_ints.ini", false); //File to open/default save filename. The constuctor is set to parse by default, unless specified as false
for(int i = 1; i <= 200; i++)
{
ini_int.create(i); //Section
ini_int.set("Key", i / 2.f);
}

ini_int.save();

///Wide char support example (please define FINI_WIDE_SUPPORT in project)
/*
ini_t ini_w("file.ini", true);
wcout << ini_w[L"Section2"][L"Key1"] << endl;
*/

///Load from memory
std::string str = getStringFromFile("config/test.ini"); //Allows us to tap into a source for the purpose of this example

ini_t ini_mem((void*)str.c_str(), str.size(), true); //This is the line which parses data from memory

///Merge contents and keep values
ini_t inid("file.ini", true);
ini_t inis("merge.ini", true);
inid.merge(inis, true);
inid.save("merged.ini");

return EXIT_SUCCESS;
}

void centerString(string str)
{
const char* s = str.c_str();
int l = strlen(s);
int pos = (int)((80 - l) / 2);
for(int i = 0; i < pos; i++)
cout << " ";
cout << s << endl;
}

std::string getStringFromFile(const std::string& path) {
std::ostringstream buf;
std::ifstream input (path.c_str());
buf << input.rdbuf();
return buf.str();
}

+ 0
- 5
dependencies/cpp-feather-ini-parser/example/file.ini View File

@@ -1,5 +0,0 @@
[Section2]
123=123
Key1=1.123
[Section Name]
Key=Value

+ 0
- 400
dependencies/cpp-feather-ini-parser/example/file_ints.ini View File

@@ -1,400 +0,0 @@
[200]
Key=100
[199]
Key=99.5
[198]
Key=99
[197]
Key=98.5
[196]
Key=98
[195]
Key=97.5
[194]
Key=97
[193]
Key=96.5
[192]
Key=96
[191]
Key=95.5
[190]
Key=95
[189]
Key=94.5
[188]
Key=94
[187]
Key=93.5
[186]
Key=93
[185]
Key=92.5
[184]
Key=92
[183]
Key=91.5
[182]
Key=91
[181]
Key=90.5
[180]
Key=90
[179]
Key=89.5
[178]
Key=89
[177]
Key=88.5
[176]
Key=88
[175]
Key=87.5
[174]
Key=87
[173]
Key=86.5
[172]
Key=86
[171]
Key=85.5
[170]
Key=85
[169]
Key=84.5
[168]
Key=84
[167]
Key=83.5
[166]
Key=83
[165]
Key=82.5
[164]
Key=82
[163]
Key=81.5
[162]
Key=81
[161]
Key=80.5
[160]
Key=80
[159]
Key=79.5
[158]
Key=79
[157]
Key=78.5
[156]
Key=78
[155]
Key=77.5
[154]
Key=77
[153]
Key=76.5
[152]
Key=76
[151]
Key=75.5
[150]
Key=75
[149]
Key=74.5
[148]
Key=74
[147]
Key=73.5
[146]
Key=73
[145]
Key=72.5
[144]
Key=72
[143]
Key=71.5
[142]
Key=71
[141]
Key=70.5
[140]
Key=70
[139]
Key=69.5
[138]
Key=69
[137]
Key=68.5
[136]
Key=68
[135]
Key=67.5
[134]
Key=67
[133]
Key=66.5
[132]
Key=66
[131]
Key=65.5
[130]
Key=65
[129]
Key=64.5
[128]
Key=64
[127]
Key=63.5
[126]
Key=63
[125]
Key=62.5
[124]
Key=62
[123]
Key=61.5
[122]
Key=61
[121]
Key=60.5
[120]
Key=60
[119]
Key=59.5
[118]
Key=59
[117]
Key=58.5
[116]
Key=58
[115]
Key=57.5
[114]
Key=57
[113]
Key=56.5
[112]
Key=56
[111]
Key=55.5
[110]
Key=55
[109]
Key=54.5
[108]
Key=54
[107]
Key=53.5
[106]
Key=53
[105]
Key=52.5
[104]
Key=52
[103]
Key=51.5
[1]
Key=0.5
[2]
Key=1
[3]
Key=1.5
[4]
Key=2
[5]
Key=2.5
[6]
Key=3
[7]
Key=3.5
[8]
Key=4
[9]
Key=4.5
[10]
Key=5
[11]
Key=5.5
[12]
Key=6
[13]
Key=6.5
[14]
Key=7
[15]
Key=7.5
[16]
Key=8
[17]
Key=8.5
[18]
Key=9
[19]
Key=9.5
[20]
Key=10
[21]
Key=10.5
[22]
Key=11
[23]
Key=11.5
[24]
Key=12
[25]
Key=12.5
[26]
Key=13
[27]
Key=13.5
[28]
Key=14
[29]
Key=14.5
[30]
Key=15
[31]
Key=15.5
[32]
Key=16
[33]
Key=16.5
[34]
Key=17
[35]
Key=17.5
[36]
Key=18
[37]
Key=18.5
[38]
Key=19
[39]
Key=19.5
[40]
Key=20
[41]
Key=20.5
[42]
Key=21
[43]
Key=21.5
[44]
Key=22
[45]
Key=22.5
[46]
Key=23
[47]
Key=23.5
[48]
Key=24
[49]
Key=24.5
[50]
Key=25
[51]
Key=25.5
[52]
Key=26
[53]
Key=26.5
[54]
Key=27
[55]
Key=27.5
[56]
Key=28
[57]
Key=28.5
[58]
Key=29
[59]
Key=29.5
[60]
Key=30
[61]
Key=30.5
[62]
Key=31
[63]
Key=31.5
[64]
Key=32
[65]
Key=32.5
[66]
Key=33
[67]
Key=33.5
[68]
Key=34
[69]
Key=34.5
[70]
Key=35
[71]
Key=35.5
[72]
Key=36
[73]
Key=36.5
[74]
Key=37
[75]
Key=37.5
[76]
Key=38
[77]
Key=38.5
[78]
Key=39
[79]
Key=39.5
[80]
Key=40
[81]
Key=40.5
[82]
Key=41
[83]
Key=41.5
[84]
Key=42
[85]
Key=42.5
[86]
Key=43
[87]
Key=43.5
[88]
Key=44
[89]
Key=44.5
[90]
Key=45
[91]
Key=45.5
[92]
Key=46
[93]
Key=46.5
[94]
Key=47
[95]
Key=47.5
[96]
Key=48
[97]
Key=48.5
[98]
Key=49
[99]
Key=49.5
[100]
Key=50
[101]
Key=50.5
[102]
Key=51

+ 0
- 5
dependencies/cpp-feather-ini-parser/example/merge.ini View File

@@ -1,5 +0,0 @@
[NewSection]
Key=Value
[Section2]
NewKey=Value
123=456

+ 0
- 57
dependencies/cpp-feather-ini-parser/example/project.cbp View File

@@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="project" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="gcc_mingw">
<Option output="bin/gcc_mingw/example" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/gcc_mingw/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
<Add option="-Wall" />
<Add option="-std=c++0x" />
</Compiler>
</Target>
<Target title="vs_2013">
<Option output="bin/vs/example" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/vs_2013/" />
<Option type="1" />
<Option compiler="microsoft_visual_c_2013" />
<Compiler>
<Add option="/EHa" />
<Add option="/W2" />
<Add directory="C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/include" />
</Compiler>
<Linker>
<Add directory="C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/lib" />
<Add directory="C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/Lib" />
</Linker>
</Target>
<Target title="vs_2010">
<Option output="bin/vs/example" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/vs_2010/" />
<Option type="1" />
<Option compiler="msvc10" />
<Compiler>
<Add option="/EHa" />
<Add option="/W2" />
</Compiler>
<Linker>
<Add directory="C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/Lib" />
</Linker>
</Target>
</Build>
<Unit filename="../INI.h" />
<Unit filename="example.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>

+ 0
- 1
examples/1_minimal/mods/mod1/mod.ini View File

@@ -1,3 +1,2 @@
[mod]
name=mod 1
id=2dk53l89mn3n7JdY801264Kds0H

+ 1
- 1
examples/1_minimal/src/main.cpp View File

@@ -13,7 +13,7 @@ int main (int argc, char* argv[]) {
std::unique_ptr<ModdingFrameworkCore> mod_framework;
mod_framework = std::make_unique<ModdingFrameworkCore>("mods");

std::shared_ptr<ConfigStore> data = mod_framework->mod_config[0]->getNested("mod");
std::shared_ptr<ConfigStore> data = mod_framework->mod_config[0];

if ( data->isPopulated() ) {
std::cout << data->getStr("name") << "; " << data->getStr("id") << std::endl;


+ 52
- 41
src/Configuration/ConfigLoaderINI.cpp View File

@@ -1,30 +1,16 @@

#include "ConfigLoaderINI.h"
#include "ConfigStore.h"
#include "FileOperations.h" //for openFile, writeToTextFile, and trimString

//The following lets us include a 3rd party lib without throwing compile warnings
#ifdef linux
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#include "INI.h"
#pragma GCC diagnostic pop

#elif defined windows
//TODO: Not tested
//#pragma warning(push, 0)
//#include "INI.h"
//#pragma warning(pop)

#endif


#include <string>
#include <iostream>

#include <fstream>
#include <string>
#include <algorithm>

//make sure the given file is in fact a ini file
bool ConfigLoaderINI::validate(std::string filepath) {
INI<> reader(filepath, true);

//TODO
return false;
@@ -33,35 +19,60 @@ bool ConfigLoaderINI::validate(std::string filepath) {

//request parsing a given ini config file
std::shared_ptr<ConfigStore> ConfigLoaderINI::parse(std::string filepath) {
std::shared_ptr<ConfigStore> conf_store = std::make_shared<ConfigStore>();
INI<> reader(filepath, true);

//iterate over all the ini sections parsed from the file
for(auto s_iter: reader.sections) {
std::string section = s_iter.first;

//create a nested ConfigStore that holds the section's values
std::shared_ptr<ConfigStore> nested_store = std::make_shared<ConfigStore>();
//iterate over each key/val pair under the section.
for(auto pair_iter: *s_iter.second) {
std::string key = pair_iter.first, value = pair_iter.second;

//store string data
nested_store->set(key, value);
}
std::shared_ptr<ConfigStore> root_store = std::make_shared<ConfigStore>();

//try opening the file and if it fails return empty config store
//TODO do better error handeling
std::fstream ini_file = openFile(filepath, 'r');
if ( ! ini_file.is_open() ) { return root_store; }

std::shared_ptr<ConfigStore> cur_store = root_store;

//iterate over each line
std::string line;
std::string cur_section = "";
while ( getline(ini_file, line) ) {
//remove leading and trailing whitespace
line = trimString(line);

//used to test if a line has the key/value pairs and if so used to seperate them out
std::size_t seperator_pos = line.find("=");

//if section change cur_store
if ( line.front() == '[' && line.back() == ']' ) {
//extract just the section's name
std::string section_name = line.substr( 1, line.length()-2 );
//create new config store and set it in root config store
cur_store = std::make_shared<ConfigStore>();
root_store->set(section_name, cur_store);

//if there is a = sign in a line it will be treated as a key/value pair
} else if ( seperator_pos != std::string::npos ) {
//Store the data
cur_store->set(
line.substr(0, seperator_pos), //the key
line.substr(seperator_pos+1) //the value
);

//handle ';' comments and blank lines
} else if ( line[0] == ';' || line == "") {
//do nothing

//Otherwise an error has likely occured
} else {
//TODO do better error handeling

//store section data
conf_store->set(section, nested_store);
}
}

return conf_store;
return root_store;
}


//turn a ConfigStore into a ini file
bool ConfigLoaderINI::serialize(std::string filepath, std::shared_ptr<ConfigStore> data) {
INI<> writer(filepath, true);
/*INI<> writer(filepath, true);
for (auto iter = data->beginNested(); iter != data->endNested(); iter++) {
writer.create(iter->first);
@@ -72,7 +83,7 @@ bool ConfigLoaderINI::serialize(std::string filepath, std::shared_ptr<ConfigStor
}
}

writer.save();
writer.save();*/

return true;
}


Loading…
Cancel
Save