mirror of https://github.com/JAJames/Jupiter.git
Jessica James
8 years ago
14 changed files with 39 additions and 1306 deletions
@ -1,646 +0,0 @@ |
|||||
/**
|
|
||||
* Copyright (C) 2013-2015 Jessica James. |
|
||||
* |
|
||||
* Permission to use, copy, modify, and/or distribute this software for any |
|
||||
* purpose with or without fee is hereby granted, provided that the above |
|
||||
* copyright notice and this permission notice appear in all copies. |
|
||||
* |
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
* |
|
||||
* Written by Jessica James <jessica.aj@outlook.com> |
|
||||
*/ |
|
||||
|
|
||||
#include <cstring> |
|
||||
#include <cstdlib> |
|
||||
#include <cstdio> |
|
||||
#include "Functions.h" |
|
||||
#include "File.h" |
|
||||
#include "INIFile.h" |
|
||||
#include "CString.h" |
|
||||
#include "String.h" |
|
||||
#include "ArrayList.h" |
|
||||
#include "InvalidIndex.h" |
|
||||
#include "Reference_String.h" |
|
||||
|
|
||||
/**
|
|
||||
* TODO: |
|
||||
* Rewrite using String, and ArrayList. Consider using File when reading data. |
|
||||
* Add support for unspecified section. |
|
||||
* Consider sort/search optimization. |
|
||||
*/ |
|
||||
|
|
||||
/** KeyValuePair implementation */ |
|
||||
|
|
||||
struct Jupiter::INIFile::Section::KeyValuePair::Data |
|
||||
{ |
|
||||
unsigned int keySum = 0; |
|
||||
Jupiter::StringS key; |
|
||||
Jupiter::StringS value; |
|
||||
}; |
|
||||
|
|
||||
Jupiter::INIFile::Section::KeyValuePair::KeyValuePair() |
|
||||
{ |
|
||||
Jupiter::INIFile::Section::KeyValuePair::data_ = new Jupiter::INIFile::Section::KeyValuePair::Data(); |
|
||||
} |
|
||||
|
|
||||
Jupiter::INIFile::Section::KeyValuePair::KeyValuePair(const KeyValuePair &source) |
|
||||
{ |
|
||||
Jupiter::INIFile::Section::KeyValuePair::data_ = new Jupiter::INIFile::Section::KeyValuePair::Data(); |
|
||||
Jupiter::INIFile::Section::KeyValuePair::data_->key = source.data_->key; |
|
||||
Jupiter::INIFile::Section::KeyValuePair::data_->value = source.data_->value; |
|
||||
Jupiter::INIFile::Section::KeyValuePair::data_->keySum = Jupiter::INIFile::Section::KeyValuePair::data_->key.calcChecksumi(); |
|
||||
} |
|
||||
|
|
||||
Jupiter::INIFile::Section::KeyValuePair::~KeyValuePair() |
|
||||
{ |
|
||||
delete Jupiter::INIFile::Section::KeyValuePair::data_; |
|
||||
} |
|
||||
|
|
||||
unsigned int Jupiter::INIFile::Section::KeyValuePair::getKeyChecksum() const |
|
||||
{ |
|
||||
return Jupiter::INIFile::Section::KeyValuePair::data_->keySum; |
|
||||
} |
|
||||
|
|
||||
const Jupiter::ReadableString &Jupiter::INIFile::Section::KeyValuePair::getKey() const |
|
||||
{ |
|
||||
return Jupiter::INIFile::Section::KeyValuePair::data_->key; |
|
||||
} |
|
||||
|
|
||||
const Jupiter::ReadableString &Jupiter::INIFile::Section::KeyValuePair::getValue() const |
|
||||
{ |
|
||||
return Jupiter::INIFile::Section::KeyValuePair::data_->value; |
|
||||
} |
|
||||
|
|
||||
void Jupiter::INIFile::Section::KeyValuePair::setValue(const Jupiter::ReadableString &value) |
|
||||
{ |
|
||||
Jupiter::INIFile::Section::KeyValuePair::data_->value = value; |
|
||||
} |
|
||||
|
|
||||
/** Section implementation */ |
|
||||
|
|
||||
struct Jupiter::INIFile::Section::Data |
|
||||
{ |
|
||||
unsigned int nameSum = 0; |
|
||||
Jupiter::StringS name; |
|
||||
Jupiter::ArrayList<Jupiter::INIFile::Section::KeyValuePair> data; |
|
||||
~Data(); |
|
||||
}; |
|
||||
|
|
||||
Jupiter::INIFile::Section::Data::~Data() |
|
||||
{ |
|
||||
Jupiter::INIFile::Section::Data::data.emptyAndDelete(); |
|
||||
} |
|
||||
|
|
||||
Jupiter::INIFile::Section::Section() |
|
||||
{ |
|
||||
Jupiter::INIFile::Section::data_ = new Jupiter::INIFile::Section::Data(); |
|
||||
} |
|
||||
|
|
||||
Jupiter::INIFile::Section::Section(const Jupiter::ReadableString &name) |
|
||||
{ |
|
||||
Jupiter::INIFile::Section::data_ = new Jupiter::INIFile::Section::Data(); |
|
||||
Jupiter::INIFile::Section::data_->nameSum = name.calcChecksumi(); |
|
||||
Jupiter::INIFile::Section::data_->name = name; |
|
||||
} |
|
||||
|
|
||||
Jupiter::INIFile::Section::Section(const Jupiter::INIFile::Section &source) |
|
||||
{ |
|
||||
Jupiter::INIFile::Section::data_ = new Jupiter::INIFile::Section::Data(); |
|
||||
Jupiter::INIFile::Section::data_->name = source.data_->name; |
|
||||
for (size_t i = 0, sourceSize = source.data_->data.size(); i != sourceSize; i++) |
|
||||
Jupiter::INIFile::Section::data_->data.add(new Jupiter::INIFile::Section::KeyValuePair(*source.data_->data.get(i))); |
|
||||
} |
|
||||
|
|
||||
Jupiter::INIFile::Section::~Section() |
|
||||
{ |
|
||||
delete Jupiter::INIFile::Section::data_; |
|
||||
} |
|
||||
|
|
||||
unsigned int Jupiter::INIFile::Section::getNameChecksum() const |
|
||||
{ |
|
||||
return Jupiter::INIFile::Section::data_->nameSum; |
|
||||
} |
|
||||
|
|
||||
const Jupiter::ReadableString &Jupiter::INIFile::Section::getName() const |
|
||||
{ |
|
||||
return Jupiter::INIFile::Section::data_->name; |
|
||||
} |
|
||||
|
|
||||
const Jupiter::ReadableString &Jupiter::INIFile::Section::get(size_t index) const |
|
||||
{ |
|
||||
return Jupiter::INIFile::Section::data_->data.get(index)->data_->value; |
|
||||
} |
|
||||
|
|
||||
const Jupiter::ReadableString &Jupiter::INIFile::Section::get(const Jupiter::ReadableString &key, const Jupiter::ReadableString &defaultValue) const |
|
||||
{ |
|
||||
Jupiter::INIFile::Section::KeyValuePair *pair; |
|
||||
const unsigned int keySum = key.calcChecksumi(); |
|
||||
size_t index = Jupiter::INIFile::Section::data_->data.size(); |
|
||||
while (index != 0) |
|
||||
{ |
|
||||
pair = Jupiter::INIFile::Section::data_->data.get(--index); |
|
||||
if (keySum == pair->getKeyChecksum() && pair->getKey().equalsi(key)) |
|
||||
return pair->getValue(); |
|
||||
} |
|
||||
return defaultValue; |
|
||||
} |
|
||||
|
|
||||
bool Jupiter::INIFile::Section::getBool(const Jupiter::ReadableString &key, bool defaultValue) const |
|
||||
{ |
|
||||
const Jupiter::ReadableString &val = Jupiter::INIFile::Section::get(key); |
|
||||
if (val.isNotEmpty()) |
|
||||
return val.asBool(); |
|
||||
return defaultValue; |
|
||||
} |
|
||||
|
|
||||
short Jupiter::INIFile::Section::getShort(const Jupiter::ReadableString &key, short defaultValue) const |
|
||||
{ |
|
||||
return static_cast<short>(Jupiter::INIFile::Section::getInt(key, defaultValue)); |
|
||||
} |
|
||||
|
|
||||
int Jupiter::INIFile::Section::getInt(const Jupiter::ReadableString &key, int defaultValue) const |
|
||||
{ |
|
||||
const Jupiter::ReadableString &val = Jupiter::INIFile::Section::get(key); |
|
||||
if (val.isNotEmpty()) |
|
||||
return val.asInt(); |
|
||||
return defaultValue; |
|
||||
} |
|
||||
|
|
||||
long Jupiter::INIFile::Section::getLong(const Jupiter::ReadableString &key, long defaultValue) const |
|
||||
{ |
|
||||
const Jupiter::ReadableString &val = Jupiter::INIFile::Section::get(key); |
|
||||
if (val.isNotEmpty()) |
|
||||
return val.asInt(); |
|
||||
return defaultValue; |
|
||||
} |
|
||||
|
|
||||
long long Jupiter::INIFile::Section::getLongLong(const Jupiter::ReadableString &key, long long defaultValue) const |
|
||||
{ |
|
||||
const Jupiter::ReadableString &val = Jupiter::INIFile::Section::get(key); |
|
||||
if (val.isNotEmpty()) |
|
||||
return val.asLongLong(); |
|
||||
return defaultValue; |
|
||||
} |
|
||||
|
|
||||
float Jupiter::INIFile::Section::getFloat(const Jupiter::ReadableString &key, float defaultValue) const |
|
||||
{ |
|
||||
const Jupiter::ReadableString &val = Jupiter::INIFile::Section::get(key); |
|
||||
if (val.isNotEmpty()) |
|
||||
return float(val.asDouble()); |
|
||||
return defaultValue; |
|
||||
} |
|
||||
|
|
||||
double Jupiter::INIFile::Section::getDouble(const Jupiter::ReadableString &key, double defaultValue) const |
|
||||
{ |
|
||||
const Jupiter::ReadableString &val = Jupiter::INIFile::Section::get(key); |
|
||||
if (val.isNotEmpty()) |
|
||||
return val.asDouble(); |
|
||||
return defaultValue; |
|
||||
} |
|
||||
|
|
||||
long double Jupiter::INIFile::Section::getLongDouble(const Jupiter::ReadableString &key, long double defaultValue) const |
|
||||
{ |
|
||||
const Jupiter::ReadableString &val = Jupiter::INIFile::Section::get(key); |
|
||||
if (val.isNotEmpty()) |
|
||||
return val.asDouble(); |
|
||||
return defaultValue; |
|
||||
} |
|
||||
|
|
||||
Jupiter::INIFile::Section::KeyValuePair *Jupiter::INIFile::Section::getPair(size_t index) const |
|
||||
{ |
|
||||
return Jupiter::INIFile::Section::data_->data.get(index); |
|
||||
} |
|
||||
|
|
||||
Jupiter::INIFile::Section::KeyValuePair *Jupiter::INIFile::Section::getPair(const Jupiter::ReadableString &key) const |
|
||||
{ |
|
||||
Jupiter::INIFile::Section::KeyValuePair *pair; |
|
||||
const unsigned int keySum = key.calcChecksumi(); |
|
||||
size_t index = Jupiter::INIFile::Section::data_->data.size(); |
|
||||
while (index != 0) |
|
||||
{ |
|
||||
pair = Jupiter::INIFile::Section::data_->data.get(--index); |
|
||||
if (keySum == pair->getKeyChecksum() && pair->getKey().equalsi(key)) |
|
||||
return pair; |
|
||||
} |
|
||||
return nullptr; |
|
||||
} |
|
||||
|
|
||||
size_t Jupiter::INIFile::Section::size() const |
|
||||
{ |
|
||||
return Jupiter::INIFile::Section::data_->data.size(); |
|
||||
} |
|
||||
|
|
||||
bool Jupiter::INIFile::Section::hasKey(const Jupiter::ReadableString &key) const |
|
||||
{ |
|
||||
Jupiter::INIFile::Section::KeyValuePair *pair; |
|
||||
const unsigned int keySum = key.calcChecksumi(); |
|
||||
size_t index = Jupiter::INIFile::Section::data_->data.size(); |
|
||||
while (index != 0) |
|
||||
{ |
|
||||
pair = Jupiter::INIFile::Section::data_->data.get(--index); |
|
||||
if (keySum == pair->getKeyChecksum() && pair->getKey().equalsi(key)) |
|
||||
return true; |
|
||||
} |
|
||||
return false; |
|
||||
} |
|
||||
|
|
||||
bool Jupiter::INIFile::Section::set(const Jupiter::ReadableString &key, const Jupiter::ReadableString &value) |
|
||||
{ |
|
||||
Jupiter::INIFile::Section::KeyValuePair *pair; |
|
||||
const unsigned int keySum = key.calcChecksumi(); |
|
||||
size_t index = Jupiter::INIFile::Section::data_->data.size(); |
|
||||
while (index != 0) |
|
||||
{ |
|
||||
pair = Jupiter::INIFile::Section::data_->data.get(--index); |
|
||||
if (keySum == pair->getKeyChecksum() && pair->getKey().equalsi(key)) |
|
||||
{ |
|
||||
pair->data_->value = value; |
|
||||
return false; |
|
||||
} |
|
||||
} |
|
||||
pair = new Jupiter::INIFile::Section::KeyValuePair(); |
|
||||
pair->data_->keySum = keySum; |
|
||||
pair->data_->key = key; |
|
||||
pair->data_->value = value; |
|
||||
Jupiter::INIFile::Section::data_->data.add(pair); |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
void Jupiter::INIFile::Section::setName(const Jupiter::ReadableString &name) |
|
||||
{ |
|
||||
Jupiter::INIFile::Section::data_->nameSum = name.calcChecksumi(); |
|
||||
Jupiter::INIFile::Section::data_->name = name; |
|
||||
} |
|
||||
|
|
||||
bool Jupiter::INIFile::Section::remove(const Jupiter::ReadableString &key) |
|
||||
{ |
|
||||
Jupiter::INIFile::Section::KeyValuePair *pair; |
|
||||
const unsigned int keySum = key.calcChecksumi(); |
|
||||
size_t index = Jupiter::INIFile::Section::data_->data.size(); |
|
||||
while (index != 0) |
|
||||
{ |
|
||||
pair = Jupiter::INIFile::Section::data_->data.get(--index); |
|
||||
if (keySum == pair->getKeyChecksum() && pair->getKey().equalsi(key)) |
|
||||
{ |
|
||||
delete Jupiter::INIFile::Section::data_->data.remove(index); |
|
||||
return true; |
|
||||
} |
|
||||
} |
|
||||
return false; |
|
||||
} |
|
||||
|
|
||||
/** INIFile implementation */ |
|
||||
|
|
||||
struct Jupiter::INIFile::Data |
|
||||
{ |
|
||||
Jupiter::ArrayList<Section> data; |
|
||||
Jupiter::CStringS fName; |
|
||||
~Data(); |
|
||||
}; |
|
||||
|
|
||||
Jupiter::INIFile::Data::~Data() |
|
||||
{ |
|
||||
Jupiter::INIFile::Data::data.emptyAndDelete(); |
|
||||
} |
|
||||
|
|
||||
Jupiter::INIFile::INIFile() |
|
||||
{ |
|
||||
Jupiter::INIFile::data_ = new Jupiter::INIFile::Data; |
|
||||
} |
|
||||
|
|
||||
Jupiter::INIFile::INIFile(const INIFile &source) |
|
||||
{ |
|
||||
Jupiter::INIFile::data_ = new Jupiter::INIFile::Data; |
|
||||
Jupiter::INIFile::data_->fName = source.data_->fName; |
|
||||
for (size_t i = 0, sourceSize = source.data_->data.size(); i != sourceSize; i++) |
|
||||
Jupiter::INIFile::data_->data.add(new Jupiter::INIFile::Section(*source.data_->data.get(i))); |
|
||||
} |
|
||||
|
|
||||
Jupiter::INIFile::~INIFile() |
|
||||
{ |
|
||||
delete Jupiter::INIFile::data_; |
|
||||
} |
|
||||
|
|
||||
void Jupiter::INIFile::flushData() |
|
||||
{ |
|
||||
delete Jupiter::INIFile::data_; |
|
||||
Jupiter::INIFile::data_ = new Jupiter::INIFile::Data(); |
|
||||
} |
|
||||
|
|
||||
unsigned int Jupiter::INIFile::readFile(const char *fileName) |
|
||||
{ |
|
||||
size_t total = 0; |
|
||||
Jupiter::File file; |
|
||||
if (file.load(fileName) == false) |
|
||||
return Jupiter::ERROR_INDICATOR; |
|
||||
|
|
||||
Jupiter::INIFile::data_->fName = file.getFileName(); |
|
||||
Jupiter::ReferenceString section; |
|
||||
Jupiter::ReferenceString line; |
|
||||
for (size_t index = 0; index != file.getLineCount(); index++) |
|
||||
{ |
|
||||
line = file.getLine(index); |
|
||||
|
|
||||
// check if line is a comment.
|
|
||||
while (line.isNotEmpty() && isspace(line.get(0))) |
|
||||
line.shiftRight(1); |
|
||||
|
|
||||
if (line.isEmpty() || line.get(0) == ';') |
|
||||
continue; |
|
||||
|
|
||||
while (isspace(line.get(line.size() - 1))) // This is safe due to the previous check, which confirms that there is a non-whitespace character.
|
|
||||
line.truncate(1); |
|
||||
|
|
||||
if (line.get(0) == '[') // changing sections.
|
|
||||
{ |
|
||||
line.shiftRight(1); |
|
||||
|
|
||||
// Truncate up to the last ']'.
|
|
||||
while (line.isNotEmpty() && line.get(line.size() - 1) != ']') |
|
||||
line.truncate(1); |
|
||||
line.truncate(1); // Truncate the ']' we stoped at.
|
|
||||
|
|
||||
section.set(line); |
|
||||
} |
|
||||
else if (line.contains('=')) // key/value pair.
|
|
||||
{ |
|
||||
Jupiter::ReferenceString key = line.getWord(0, "="); |
|
||||
Jupiter::ReferenceString value = line.substring(key.size() + 1); |
|
||||
while (key.isNotEmpty() && isspace(key.get(key.size() - 1))) |
|
||||
key.truncate(1); |
|
||||
|
|
||||
while (value.isNotEmpty() && isspace(value.get(0))) |
|
||||
value.shiftRight(1); |
|
||||
|
|
||||
if (Jupiter::INIFile::set(section, key, value)) |
|
||||
total++; |
|
||||
} |
|
||||
} |
|
||||
return total; |
|
||||
} |
|
||||
|
|
||||
unsigned int Jupiter::INIFile::readFile(const Jupiter::ReadableString &file) |
|
||||
{ |
|
||||
return Jupiter::INIFile::readFile(Jupiter::CStringS(file).c_str()); |
|
||||
} |
|
||||
|
|
||||
unsigned int Jupiter::INIFile::reload() |
|
||||
{ |
|
||||
Jupiter::CStringS fileName = Jupiter::INIFile::data_->fName; |
|
||||
Jupiter::INIFile::flushData(); |
|
||||
return Jupiter::INIFile::readFile(fileName.c_str()); |
|
||||
} |
|
||||
|
|
||||
bool Jupiter::INIFile::sync(const char *fileName) |
|
||||
{ |
|
||||
Jupiter::INIFile::Section *section; |
|
||||
Jupiter::INIFile::Section::KeyValuePair *pair; |
|
||||
|
|
||||
FILE *file = fopen(fileName, "wb"); |
|
||||
if (file == nullptr) return false; |
|
||||
fputs("; This file was automatically generated by Agent's INI parser." ENDL "; The currently used data values are as follows." ENDL ENDL, file); |
|
||||
for (size_t a = 0; a != Jupiter::INIFile::data_->data.size(); a++) |
|
||||
{ |
|
||||
section = Jupiter::INIFile::data_->data.get(a); |
|
||||
fputc('[', file); |
|
||||
section->getName().print(file); |
|
||||
fputs("]" ENDL, file); |
|
||||
|
|
||||
for (size_t b = 0; b != section->size(); b++) |
|
||||
{ |
|
||||
pair = section->getPair(b); |
|
||||
pair->getKey().print(file); |
|
||||
fputc('=', file); |
|
||||
pair->getValue().print(file); |
|
||||
fputs(ENDL, file); |
|
||||
} |
|
||||
fputs(ENDL, file); |
|
||||
} |
|
||||
fputs("; EOF", file); |
|
||||
fclose(file); |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
bool Jupiter::INIFile::sync(const Jupiter::ReadableString &file) |
|
||||
{ |
|
||||
return Jupiter::INIFile::sync(Jupiter::CStringS(file).c_str()); |
|
||||
} |
|
||||
|
|
||||
bool Jupiter::INIFile::sync() |
|
||||
{ |
|
||||
if (Jupiter::INIFile::data_->fName.isEmpty()) |
|
||||
return false; |
|
||||
return Jupiter::INIFile::sync(Jupiter::INIFile::data_->fName.c_str()); |
|
||||
} |
|
||||
|
|
||||
bool Jupiter::INIFile::set(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, const Jupiter::ReadableString &value) |
|
||||
{ |
|
||||
Jupiter::INIFile::Section *sec; |
|
||||
unsigned int nameSum = section.calcChecksumi(); |
|
||||
size_t index = Jupiter::INIFile::data_->data.size(); |
|
||||
while (index != 0) |
|
||||
{ |
|
||||
sec = Jupiter::INIFile::data_->data.get(--index); |
|
||||
if (nameSum == sec->getNameChecksum() && sec->getName().equalsi(section)) |
|
||||
return sec->set(key, value); |
|
||||
} |
|
||||
sec = new Jupiter::INIFile::Section(section); |
|
||||
sec->set(key, value); |
|
||||
Jupiter::INIFile::data_->data.add(sec); |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
bool Jupiter::INIFile::remove(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key) |
|
||||
{ |
|
||||
Jupiter::INIFile::Section *sec; |
|
||||
unsigned int nameSum = section.calcChecksumi(); |
|
||||
size_t index = Jupiter::INIFile::data_->data.size(); |
|
||||
while (index != 0) |
|
||||
{ |
|
||||
sec = Jupiter::INIFile::data_->data.get(--index); |
|
||||
if (nameSum == sec->getNameChecksum() && sec->getName().equalsi(section)) |
|
||||
return sec->remove(key); |
|
||||
} |
|
||||
return false; |
|
||||
} |
|
||||
|
|
||||
bool Jupiter::INIFile::remove(size_t section_index) |
|
||||
{ |
|
||||
delete Jupiter::INIFile::data_->data.remove(section_index); |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
bool Jupiter::INIFile::remove(const Jupiter::INIFile::Section *section) |
|
||||
{ |
|
||||
size_t i = Jupiter::INIFile::data_->data.size(); |
|
||||
while (i != 0) |
|
||||
if (Jupiter::INIFile::data_->data.get(--i) == section) |
|
||||
return Jupiter::INIFile::remove(i); |
|
||||
return false; |
|
||||
} |
|
||||
|
|
||||
bool Jupiter::INIFile::remove(const Jupiter::ReadableString §ion) |
|
||||
{ |
|
||||
unsigned int nameSum = section.calcChecksumi(); |
|
||||
size_t i = Jupiter::INIFile::data_->data.size(); |
|
||||
while (i != 0) |
|
||||
if (Jupiter::INIFile::data_->data.get(--i)->getNameChecksum() == nameSum && Jupiter::INIFile::data_->data.get(i)->getName().equalsi(section)) |
|
||||
return Jupiter::INIFile::remove(i); |
|
||||
return false; |
|
||||
} |
|
||||
|
|
||||
size_t Jupiter::INIFile::getSections() const |
|
||||
{ |
|
||||
return Jupiter::INIFile::data_->data.size(); |
|
||||
} |
|
||||
|
|
||||
Jupiter::INIFile::Section *Jupiter::INIFile::getSection(size_t index) const |
|
||||
{ |
|
||||
return Jupiter::INIFile::data_->data.get(index); |
|
||||
} |
|
||||
|
|
||||
Jupiter::INIFile::Section *Jupiter::INIFile::getSection(const Jupiter::ReadableString §ion) const |
|
||||
{ |
|
||||
Jupiter::INIFile::Section *sec; |
|
||||
unsigned int nameSum = section.calcChecksumi(); |
|
||||
size_t index = Jupiter::INIFile::data_->data.size(); |
|
||||
while (index != 0) |
|
||||
{ |
|
||||
sec = Jupiter::INIFile::data_->data.get(--index); |
|
||||
if (nameSum == sec->getNameChecksum() && sec->getName().equalsi(section)) |
|
||||
return Jupiter::INIFile::data_->data.get(index); |
|
||||
} |
|
||||
return nullptr; |
|
||||
} |
|
||||
|
|
||||
size_t Jupiter::INIFile::getSectionIndex(const Jupiter::ReadableString §ion) const |
|
||||
{ |
|
||||
Jupiter::INIFile::Section *sec; |
|
||||
unsigned int nameSum = section.calcChecksumi(); |
|
||||
size_t index = Jupiter::INIFile::data_->data.size(); |
|
||||
while (index != 0) |
|
||||
{ |
|
||||
sec = Jupiter::INIFile::data_->data.get(--index); |
|
||||
if (nameSum == sec->getNameChecksum() && sec->getName().equalsi(section)) |
|
||||
return index; |
|
||||
} |
|
||||
return Jupiter::INVALID_INDEX; |
|
||||
} |
|
||||
|
|
||||
size_t Jupiter::INIFile::getSectionLength(size_t index) const |
|
||||
{ |
|
||||
return Jupiter::INIFile::data_->data.get(index)->size(); |
|
||||
} |
|
||||
|
|
||||
const Jupiter::ReadableString &Jupiter::INIFile::getKey(const Jupiter::ReadableString §ion, size_t index) const |
|
||||
{ |
|
||||
size_t sectionIndex = Jupiter::INIFile::getSectionIndex(section); |
|
||||
if (sectionIndex == Jupiter::INVALID_INDEX) |
|
||||
return Jupiter::ReferenceString::empty; |
|
||||
return Jupiter::INIFile::data_->data.get(sectionIndex)->getPair(index)->getKey(); |
|
||||
} |
|
||||
|
|
||||
size_t Jupiter::INIFile::getKeyIndex(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key) const |
|
||||
{ |
|
||||
size_t sectionIndex = Jupiter::INIFile::getSectionIndex(section); |
|
||||
if (sectionIndex == Jupiter::INVALID_INDEX) |
|
||||
return Jupiter::INVALID_INDEX; |
|
||||
|
|
||||
Jupiter::INIFile::Section::KeyValuePair *pair; |
|
||||
Jupiter::INIFile::Section *sec = Jupiter::INIFile::data_->data.get(sectionIndex); |
|
||||
unsigned int keySum = key.calcChecksumi(); |
|
||||
size_t index = sec->size(); |
|
||||
while (index != 0) |
|
||||
{ |
|
||||
pair = sec->getPair(--index); |
|
||||
if (keySum == pair->getKeyChecksum() && pair->getKey().equalsi(key)) |
|
||||
return index; |
|
||||
} |
|
||||
return Jupiter::INVALID_INDEX; |
|
||||
} |
|
||||
|
|
||||
const Jupiter::ReadableString &Jupiter::INIFile::get(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, const Jupiter::ReadableString &defaultValue) const |
|
||||
{ |
|
||||
Jupiter::INIFile::Section *sec; |
|
||||
unsigned int nameSum = section.calcChecksumi(); |
|
||||
size_t index = Jupiter::INIFile::data_->data.size(); |
|
||||
while (index != 0) |
|
||||
{ |
|
||||
sec = Jupiter::INIFile::data_->data.get(--index); |
|
||||
if (nameSum == sec->getNameChecksum() && sec->getName().equalsi(section)) |
|
||||
{ |
|
||||
Jupiter::INIFile::Section::KeyValuePair *pair = sec->getPair(key); |
|
||||
if (pair == nullptr) |
|
||||
return defaultValue; |
|
||||
return pair->getValue(); |
|
||||
} |
|
||||
} |
|
||||
return defaultValue; |
|
||||
} |
|
||||
|
|
||||
bool Jupiter::INIFile::getBool(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, bool defaultValue) const |
|
||||
{ |
|
||||
const Jupiter::ReadableString &val = Jupiter::INIFile::get(section, key); |
|
||||
if (val.isNotEmpty()) |
|
||||
return val.asBool(); |
|
||||
return defaultValue; |
|
||||
} |
|
||||
|
|
||||
short Jupiter::INIFile::getShort(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, short defaultValue) const |
|
||||
{ |
|
||||
return static_cast<short>(Jupiter::INIFile::getInt(section, key, defaultValue)); |
|
||||
} |
|
||||
|
|
||||
int Jupiter::INIFile::getInt(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, int defaultValue) const |
|
||||
{ |
|
||||
const Jupiter::ReadableString &val = Jupiter::INIFile::get(section, key); |
|
||||
if (val.isNotEmpty()) |
|
||||
return val.asInt(); |
|
||||
return defaultValue; |
|
||||
} |
|
||||
|
|
||||
long Jupiter::INIFile::getLong(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, long defaultValue) const |
|
||||
{ |
|
||||
const Jupiter::ReadableString &val = Jupiter::INIFile::get(section, key); |
|
||||
if (val.isNotEmpty()) |
|
||||
return val.asInt(); |
|
||||
return defaultValue; |
|
||||
} |
|
||||
|
|
||||
long long Jupiter::INIFile::getLongLong(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, long long defaultValue) const |
|
||||
{ |
|
||||
const Jupiter::ReadableString &val = Jupiter::INIFile::get(section, key); |
|
||||
if (val.isNotEmpty()) |
|
||||
return val.asLongLong(); |
|
||||
return defaultValue; |
|
||||
} |
|
||||
|
|
||||
float Jupiter::INIFile::getFloat(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, float defaultValue) const |
|
||||
{ |
|
||||
const Jupiter::ReadableString &val = Jupiter::INIFile::get(section, key); |
|
||||
if (val.isNotEmpty()) |
|
||||
return float(val.asDouble()); |
|
||||
return defaultValue; |
|
||||
} |
|
||||
|
|
||||
double Jupiter::INIFile::getDouble(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, double defaultValue) const |
|
||||
{ |
|
||||
const Jupiter::ReadableString &val = Jupiter::INIFile::get(section, key); |
|
||||
if (val.isNotEmpty()) |
|
||||
return val.asDouble(); |
|
||||
return defaultValue; |
|
||||
} |
|
||||
|
|
||||
long double Jupiter::INIFile::getLongDouble(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, long double defaultValue) const |
|
||||
{ |
|
||||
const Jupiter::ReadableString &val = Jupiter::INIFile::get(section, key); |
|
||||
if (val.isNotEmpty()) |
|
||||
return val.asDouble(); |
|
||||
return defaultValue; |
|
||||
} |
|
@ -1,522 +0,0 @@ |
|||||
/**
|
|
||||
* Copyright (C) 2013-2015 Jessica James. |
|
||||
* |
|
||||
* Permission to use, copy, modify, and/or distribute this software for any |
|
||||
* purpose with or without fee is hereby granted, provided that the above |
|
||||
* copyright notice and this permission notice appear in all copies. |
|
||||
* |
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
* |
|
||||
* Written by Jessica James <jessica.aj@outlook.com> |
|
||||
*/ |
|
||||
|
|
||||
#if !defined _INIFILE_H_HEADER |
|
||||
#define _INIFILE_H_HEADER |
|
||||
|
|
||||
/**
|
|
||||
* @file INIFile.h |
|
||||
* @brief Provides interaction with INI files. |
|
||||
*/ |
|
||||
|
|
||||
#include "Jupiter.h" |
|
||||
#include "Reference_String.h" |
|
||||
#include "InvalidIndex.h" |
|
||||
|
|
||||
namespace Jupiter |
|
||||
{ |
|
||||
/**
|
|
||||
* @brief Provides interfacing with INI files. |
|
||||
* INIFile objects store the contents of .INI files into memory, |
|
||||
* and access them as neccessary. The INIFile object can store |
|
||||
* the contents of multiple files at a time, but does not store |
|
||||
* where data came from. As such, you can read from multiple files, |
|
||||
* however the contents will always go to a single file when synced. |
|
||||
* Disk contents are only modified when sync() is called. |
|
||||
*/ |
|
||||
class JUPITER_API INIFile |
|
||||
{ |
|
||||
public: |
|
||||
|
|
||||
class JUPITER_API Section |
|
||||
{ |
|
||||
public: |
|
||||
class JUPITER_API KeyValuePair |
|
||||
{ |
|
||||
friend class Jupiter::INIFile::Section; |
|
||||
public: |
|
||||
|
|
||||
/**
|
|
||||
* @brief Fetches the checksum of the key in a key-value pair. |
|
||||
* |
|
||||
* @return Checksum of the key. |
|
||||
*/ |
|
||||
unsigned int getKeyChecksum() const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Fetches the key in the key-value pair. |
|
||||
* |
|
||||
* @return Reference to the key String in the pair. |
|
||||
*/ |
|
||||
const Jupiter::ReadableString &getKey() const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Fetches the value in the key-value pair. |
|
||||
* |
|
||||
* @return Reference to the value String in the pair. |
|
||||
*/ |
|
||||
const Jupiter::ReadableString &getValue() const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Sets the value of a key-value pair. |
|
||||
* |
|
||||
* @param value Value to set the key-value pair to. |
|
||||
*/ |
|
||||
void setValue(const Jupiter::ReadableString &value); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Default constructor for the KeyValuePair class. |
|
||||
*/ |
|
||||
KeyValuePair(); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Copy constructor for the KeyValuePair class. |
|
||||
*/ |
|
||||
KeyValuePair(const KeyValuePair &); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Destructor for the KeyValuePair class. |
|
||||
*/ |
|
||||
~KeyValuePair(); |
|
||||
|
|
||||
private: |
|
||||
struct Data; |
|
||||
Data *data_; |
|
||||
}; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Fetches the checksum of the name of a section. |
|
||||
* |
|
||||
* @return Checmsum of the name. |
|
||||
*/ |
|
||||
unsigned int getNameChecksum() const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Fetches the name of a section. |
|
||||
* |
|
||||
* @return Name of the section in a String. |
|
||||
*/ |
|
||||
const Jupiter::ReadableString &getName() const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Fetches the value of a key-value pair at a specified index. |
|
||||
* |
|
||||
* @param index Index of the key-value pair. |
|
||||
* @return Value of a key-value pair at a specified index. |
|
||||
*/ |
|
||||
const Jupiter::ReadableString &get(size_t index) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Fetches the value of a key-value pair. |
|
||||
* |
|
||||
* @param key Key of the key-value pair. |
|
||||
* @return Value of a key-value pair, or an empty string if none is found. |
|
||||
*/ |
|
||||
const Jupiter::ReadableString &get(const Jupiter::ReadableString &key, const Jupiter::ReadableString &defaultValue = Jupiter::ReferenceString::empty) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Translates and returns the value of a key-value pair as a boolean. |
|
||||
* |
|
||||
* @param key String containing key name. |
|
||||
* @param defaultValue Value to return if none is found. |
|
||||
* @return true if key exists and is not "false" or "0", defaultValue otherwise. |
|
||||
*/ |
|
||||
bool getBool(const Jupiter::ReadableString &key, bool defaultValue = false) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Translates and returns the value of a key-value pair as a short. |
|
||||
* |
|
||||
* @param key String containing key name. |
|
||||
* @param defaultValue Value to return if none is found. |
|
||||
* @return short value of the key if it exits, defaultValue otherwise. |
|
||||
*/ |
|
||||
short getShort(const Jupiter::ReadableString &key, short defaultValue = 0) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Translates and returns the value of a key-value pair as an int. |
|
||||
* |
|
||||
* @param key String containing key name. |
|
||||
* @param defaultValue Value to return if none is found. |
|
||||
* @return int value of the key if it exits, defaultValue otherwise. |
|
||||
*/ |
|
||||
int getInt(const Jupiter::ReadableString &key, int defaultValue = 0) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Translates and returns the value of a key-value pair as a long. |
|
||||
* |
|
||||
* @param key String containing key name. |
|
||||
* @param defaultValue Value to return if none is found. |
|
||||
* @return long value of the key if it exits, defaultValue otherwise. |
|
||||
*/ |
|
||||
long getLong(const Jupiter::ReadableString &key, long defaultValue = 0) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Translates and returns the value of a key-value pair as a long long. |
|
||||
* |
|
||||
* @param key String containing key name. |
|
||||
* @param defaultValue Value to return if none is found. |
|
||||
* @return long long value of the key if it exits, defaultValue otherwise. |
|
||||
*/ |
|
||||
long long getLongLong(const Jupiter::ReadableString &key, long long defaultValue = 0) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Translates and returns the value of a key-value pair as a float. |
|
||||
* |
|
||||
* @param key String containing key name. |
|
||||
* @param defaultValue Value to return if none is found. |
|
||||
* @return float value of the key if it exits, defaultValue otherwise. |
|
||||
*/ |
|
||||
float getFloat(const Jupiter::ReadableString &key, float defaultValue = 0) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Translates and returns the value of a key-value pair as a double. |
|
||||
* |
|
||||
* @param key String containing key name. |
|
||||
* @param defaultValue Value to return if none is found. |
|
||||
* @return double value of the key if it exits, defaultValue otherwise. |
|
||||
*/ |
|
||||
double getDouble(const Jupiter::ReadableString &key, double defaultValue = 0) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Translates and returns the value of a key-value pair as a long double. |
|
||||
* |
|
||||
* @param key String containing key name. |
|
||||
* @param defaultValue Value to return if none is found. |
|
||||
* @return long double value of the key if it exits, defaultValue otherwise. |
|
||||
*/ |
|
||||
long double getLongDouble(const Jupiter::ReadableString &key, long double defaultValue = 0) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Fetches a key-value pair at a specified index. |
|
||||
* |
|
||||
* @param index Index of the key-value pair to fetch. |
|
||||
* @return The key-value pair at the specified index. |
|
||||
*/ |
|
||||
Jupiter::INIFile::Section::KeyValuePair *getPair(size_t index) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Fetches a key-value pair. |
|
||||
* |
|
||||
* @param key Key of the key-value pair. |
|
||||
* @return A key-value pair if a match is found, nullptr otherwise. |
|
||||
*/ |
|
||||
Jupiter::INIFile::Section::KeyValuePair *getPair(const Jupiter::ReadableString &key) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Fetches the number of key-value pairs in the section. |
|
||||
* |
|
||||
* @return Number of key-value pairs in the section. |
|
||||
*/ |
|
||||
size_t size() const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Checks if a section has a key-value pair with a specified key. |
|
||||
* |
|
||||
* @param key Key of the key-value pair to search for. |
|
||||
* @return True if a match is found, false otherwise. |
|
||||
*/ |
|
||||
bool hasKey(const Jupiter::ReadableString &key) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Sets a key-value pair's value to a specified value. Creates a new pair if none is found. |
|
||||
* |
|
||||
* @param key Key of the key-value pair to search for or create. |
|
||||
* @param value Value to set the key-value pair to. |
|
||||
* @return True if a new key-value pair was created, false otherwise. |
|
||||
*/ |
|
||||
bool set(const Jupiter::ReadableString &key, const Jupiter::ReadableString &value); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Sets the name of a section. |
|
||||
* |
|
||||
* @param name String to set the section name to. |
|
||||
*/ |
|
||||
void setName(const Jupiter::ReadableString &name); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Removes a key-value pair from the section. |
|
||||
* |
|
||||
* @param key Key of the key-value pair to remove. |
|
||||
* @return True if a key-value pair was removed, false otherwise. |
|
||||
*/ |
|
||||
bool remove(const Jupiter::ReadableString &key); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Default constructor for the Section class. |
|
||||
*/ |
|
||||
Section(); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Name-specifiable constructors for the Section class |
|
||||
*/ |
|
||||
Section(const Jupiter::ReadableString &name); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Copy constructor for the Section class. |
|
||||
*/ |
|
||||
Section(const Section &); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Destructor for the Section class. |
|
||||
*/ |
|
||||
~Section(); |
|
||||
|
|
||||
private: |
|
||||
struct Data; |
|
||||
Data *data_; |
|
||||
}; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Flushes all stored data. |
|
||||
*/ |
|
||||
void flushData(); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Reads data from a file. |
|
||||
* The parser will automatically remove any excessive whitespace, including any whitespace |
|
||||
* prefixing a key name, prefixing a key value, trailing a key name, or trailing a key value. |
|
||||
* Whitespace is defined by locale. Please refer to C's isspace() documentation for details. |
|
||||
* |
|
||||
* @param fileName String containing the name of a file. |
|
||||
* @return The number of key-value pairs added on success, ERROR_INDICATOR (-1) otherwise. |
|
||||
*/ |
|
||||
unsigned int readFile(const char *fileName); |
|
||||
unsigned int readFile(const Jupiter::ReadableString &file); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Flushes all stored data and recollects from the last read file. |
|
||||
* |
|
||||
* @return The number of key-value pairs added on success, ERROR_INDICATOR (-1) otherwise. |
|
||||
*/ |
|
||||
unsigned int reload(); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Syncs data to a file. |
|
||||
* |
|
||||
* @param fileName String containing the name of a file. |
|
||||
* @return True on success, false otherwise. |
|
||||
*/ |
|
||||
bool sync(const char *fileName); |
|
||||
bool sync(const Jupiter::ReadableString &file); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Syncs data to the file that was last read from. |
|
||||
* |
|
||||
* @return True on success, false otherwise. |
|
||||
*/ |
|
||||
bool sync(); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Sets a key's value. Adds a key if an existing one is not found. Does not modify any files. |
|
||||
* |
|
||||
* @param section Section within which the data is to be stored. |
|
||||
* @param keyName String containing key name. |
|
||||
* @param keyValue String containing new key value. |
|
||||
* @return True if a new key was added, false otherwise. |
|
||||
*/ |
|
||||
bool set(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &keyName, const Jupiter::ReadableString &keyValue); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Removes a key. Does not modify any files. |
|
||||
* |
|
||||
* @param section String containing section. |
|
||||
* @param keyName String containing key name. |
|
||||
* @return True if an entry was removed, false otherwise. |
|
||||
*/ |
|
||||
bool remove(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &keyName); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Removes a section. Does not modify any files. |
|
||||
* |
|
||||
* @param section Section to remove. |
|
||||
* @return True if a section was removed, false otherwise. |
|
||||
*/ |
|
||||
bool remove(size_t section_index); |
|
||||
bool remove(const Jupiter::INIFile::Section *section); |
|
||||
bool remove(const Jupiter::ReadableString §ion); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Returns the number of sections in memory. |
|
||||
* |
|
||||
* @return Number of sections. |
|
||||
*/ |
|
||||
size_t getSections() const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Returns a section. |
|
||||
* |
|
||||
* @param index Index of the section to get. |
|
||||
* @return Section if it exists, nullptr otherwise. |
|
||||
*/ |
|
||||
Jupiter::INIFile::Section *getSection(size_t index) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Returns a section. |
|
||||
* |
|
||||
* @param section Name of the section. |
|
||||
* @return Section if it exists, nullptr otherwise. |
|
||||
*/ |
|
||||
Jupiter::INIFile::Section *getSection(const Jupiter::ReadableString §ion) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Returns the index of a section. |
|
||||
* |
|
||||
* @param section Name of the section. |
|
||||
* @return The index of section if it exists, INVALID_INDEX (-1) otherwise. |
|
||||
*/ |
|
||||
size_t getSectionIndex(const Jupiter::ReadableString §ion) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Returns the number of keys in a section. |
|
||||
* |
|
||||
* @return Number of data entries in a section. |
|
||||
*/ |
|
||||
size_t getSectionLength(size_t index) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Returns a key name. |
|
||||
* |
|
||||
* @param section String containing section. |
|
||||
* @param keyIndex Index of the key. |
|
||||
* @return Key name on success, nullptr otherwise. |
|
||||
*/ |
|
||||
const Jupiter::ReadableString &getKey(const Jupiter::ReadableString §ion, size_t index) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Returns the index of a key. |
|
||||
* |
|
||||
* @param section String containing section. |
|
||||
* @param key String containing key name. |
|
||||
* @return Index of key if it exists, INVALID_INDEX (-1) otherwise. |
|
||||
*/ |
|
||||
size_t getKeyIndex(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Returns the value of a key. |
|
||||
* |
|
||||
* @param section String containing section. |
|
||||
* @param key String containing key name. |
|
||||
* @param defaultValue Value to return if none is found. |
|
||||
* @return Pointer to a string containing key value if it exists, defaultValue otherwise. |
|
||||
*/ |
|
||||
const Jupiter::ReadableString &get(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, const Jupiter::ReadableString &defaultValue = Jupiter::ReferenceString::empty) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Translates and returns the value of a key as a boolean. |
|
||||
* |
|
||||
* @param section String containing section. |
|
||||
* @param key String containing key name. |
|
||||
* @param defaultValue Value to return if none is found. |
|
||||
* @return true if key exists and is not "false" or "0", defaultValue otherwise. |
|
||||
*/ |
|
||||
bool getBool(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, bool defaultValue = false) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Translates and returns the value of a key as a short. |
|
||||
* |
|
||||
* @param section String containing section. |
|
||||
* @param key String containing key name. |
|
||||
* @param defaultValue Value to return if none is found. |
|
||||
* @return short value of the key if it exits, defaultValue otherwise. |
|
||||
*/ |
|
||||
short getShort(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, short defaultValue = 0) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Translates and returns the value of a key as an int. |
|
||||
* |
|
||||
* @param section String containing section. |
|
||||
* @param key String containing key name. |
|
||||
* @param defaultValue Value to return if none is found. |
|
||||
* @return int value of the key if it exits, defaultValue otherwise. |
|
||||
*/ |
|
||||
int getInt(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, int defaultValue = 0) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Translates and returns the value of a key as a long. |
|
||||
* |
|
||||
* @param section String containing section. |
|
||||
* @param key String containing key name. |
|
||||
* @param defaultValue Value to return if none is found. |
|
||||
* @return long value of the key if it exits, defaultValue otherwise. |
|
||||
*/ |
|
||||
long getLong(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, long defaultValue = 0) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Translates and returns the value of a key as a long long. |
|
||||
* |
|
||||
* @param section String containing section. |
|
||||
* @param key String containing key name. |
|
||||
* @param defaultValue Value to return if none is found. |
|
||||
* @return long long value of the key if it exits, defaultValue otherwise. |
|
||||
*/ |
|
||||
long long getLongLong(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, long long defaultValue = 0) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Translates and returns the value of a key as a float. |
|
||||
* |
|
||||
* @param section String containing section. |
|
||||
* @param key String containing key name. |
|
||||
* @param defaultValue Value to return if none is found. |
|
||||
* @return float value of the key if it exits, defaultValue otherwise. |
|
||||
*/ |
|
||||
float getFloat(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, float defaultValue = 0) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Translates and returns the value of a key as a double. |
|
||||
* |
|
||||
* @param section String containing section. |
|
||||
* @param key String containing key name. |
|
||||
* @param defaultValue Value to return if none is found. |
|
||||
* @return double value of the key if it exits, defaultValue otherwise. |
|
||||
*/ |
|
||||
double getDouble(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, double defaultValue = 0) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Translates and returns the value of a key as a long double. |
|
||||
* |
|
||||
* @param section String containing section. |
|
||||
* @param key String containing key name. |
|
||||
* @param defaultValue Value to return if none is found. |
|
||||
* @return long double value of the key if it exits, defaultValue otherwise. |
|
||||
*/ |
|
||||
long double getLongDouble(const Jupiter::ReadableString §ion, const Jupiter::ReadableString &key, long double defaultValue = 0) const; |
|
||||
|
|
||||
/**
|
|
||||
* @brief Default constructor for the INIFile class. |
|
||||
*/ |
|
||||
INIFile(); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Copy constructor for the INIFile class. |
|
||||
*/ |
|
||||
INIFile(const INIFile &); |
|
||||
|
|
||||
/**
|
|
||||
* @brief Destructor for the INIFile class. |
|
||||
*/ |
|
||||
~INIFile(); |
|
||||
|
|
||||
/** Private members */ |
|
||||
private: |
|
||||
struct Data; |
|
||||
Data *data_; |
|
||||
}; |
|
||||
|
|
||||
} |
|
||||
|
|
||||
#endif // _INIFILE_H_HEADER
|
|
@ -1,31 +0,0 @@ |
|||||
/**
|
|
||||
* Copyright (C) 2014-2015 Jessica James. |
|
||||
* |
|
||||
* Permission to use, copy, modify, and/or distribute this software for any |
|
||||
* purpose with or without fee is hereby granted, provided that the above |
|
||||
* copyright notice and this permission notice appear in all copies. |
|
||||
* |
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
* |
|
||||
* Written by Jessica James <jessica.aj@outlook.com> |
|
||||
*/ |
|
||||
|
|
||||
#include "IRC_Server.h" |
|
||||
#include <string> |
|
||||
|
|
||||
struct SClient |
|
||||
{ |
|
||||
Jupiter::Socket *sock; |
|
||||
}; |
|
||||
|
|
||||
struct Jupiter::IRC::Server::Data |
|
||||
{ |
|
||||
Data(); |
|
||||
~Data(); |
|
||||
}; |
|
@ -1,50 +0,0 @@ |
|||||
/**
|
|
||||
* Copyright (C) 2014-2015 Jessica James. |
|
||||
* |
|
||||
* Permission to use, copy, modify, and/or distribute this software for any |
|
||||
* purpose with or without fee is hereby granted, provided that the above |
|
||||
* copyright notice and this permission notice appear in all copies. |
|
||||
* |
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
* |
|
||||
* Written by Jessica James <jessica.aj@outlook.com> |
|
||||
*/ |
|
||||
|
|
||||
#if !defined _IRC_SERVER_H_HEADER |
|
||||
#define _IRC_SERVER_H_HEADER |
|
||||
|
|
||||
#include "Thinker.h" |
|
||||
#include "TCPSocket.h" |
|
||||
#include "INIFile.h" |
|
||||
#include "IRC.h" |
|
||||
|
|
||||
namespace Jupiter |
|
||||
{ |
|
||||
|
|
||||
namespace IRC |
|
||||
{ |
|
||||
|
|
||||
class Server : public Thinker |
|
||||
{ |
|
||||
struct Data; |
|
||||
Data *data_; |
|
||||
class Client |
|
||||
{ |
|
||||
}; |
|
||||
class Channel |
|
||||
{ |
|
||||
}; |
|
||||
|
|
||||
}; |
|
||||
|
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
#endif // _IRC_SERVER_H_HEADER
|
|
Loading…
Reference in new issue