Browse Source

Deleted INIFile.cpp, INIFile.h, IRC_Server.cpp, IRC_Server.h; adjusted code as necessary

release/0.19
Jessica James 8 years ago
parent
commit
9e9cb33487
  1. 4
      Jupiter/Config.h
  2. 4
      Jupiter/HTTP_QueryString.h
  3. 1
      Jupiter/INIConfig.cpp
  4. 646
      Jupiter/INIFile.cpp
  5. 522
      Jupiter/INIFile.h
  6. 23
      Jupiter/IRC_Client.cpp
  7. 12
      Jupiter/IRC_Client.h
  8. 31
      Jupiter/IRC_Server.cpp
  9. 50
      Jupiter/IRC_Server.h
  10. 4
      Jupiter/Jupiter.vcxproj
  11. 12
      Jupiter/Jupiter.vcxproj.filters
  12. 4
      Jupiter/Plugin.cpp
  13. 6
      Jupiter/Plugin.h
  14. 26
      Jupiter/Readable_String.h

4
Jupiter/Config.h

@ -72,7 +72,7 @@ namespace Jupiter
* @param in_default_value Value to return if no such entry exists * @param in_default_value Value to return if no such entry exists
* @return Value of the entry if it exists, 0 otherwise. * @return Value of the entry if it exists, 0 otherwise.
*/ */
template<typename T> T get(const Jupiter::ReadableString &in_key, T in_default_value = 0); template<typename T> T get(const Jupiter::ReadableString &in_key, T in_default_value = 0) const;
/** /**
* @brief Fetches a section based on its name * @brief Fetches a section based on its name
@ -235,7 +235,7 @@ namespace Jupiter
/** Template function implementations */ /** Template function implementations */
template<typename T> inline T Jupiter::Config::get(const Jupiter::ReadableString &in_key, T in_default_value) template<typename T> inline T Jupiter::Config::get(const Jupiter::ReadableString &in_key, T in_default_value) const
{ {
const Jupiter::ReadableString *result = m_table.get(in_key); const Jupiter::ReadableString *result = m_table.get(in_key);

4
Jupiter/HTTP_QueryString.h

@ -20,7 +20,7 @@
#define _HTTP_QUERYSTRING_H_HEADER #define _HTTP_QUERYSTRING_H_HEADER
#include "String.h" #include "String.h"
#include "INIFile.h" #include "INIConfig.h"
/** /**
* @file HTTP_QueryString.h * @file HTTP_QueryString.h
@ -52,7 +52,7 @@ namespace Jupiter
HTMLFormResponse() = delete; HTMLFormResponse() = delete;
inline HTMLFormResponse(const Jupiter::ReadableString &query_string) : HTMLFormResponse(query_string.ptr(), query_string.size()) {} inline HTMLFormResponse(const Jupiter::ReadableString &query_string) : HTMLFormResponse(query_string.ptr(), query_string.size()) {}
inline HTMLFormResponse(const char *ptr, size_t str_size); inline HTMLFormResponse(const char *ptr, size_t str_size);
Jupiter::INIFile::Section table; Jupiter::HashTable table;
}; };
} }
} }

1
Jupiter/INIConfig.cpp

@ -17,7 +17,6 @@
*/ */
#include <stack> #include <stack>
#include <functional>
#include "INIConfig.h" #include "INIConfig.h"
#include "Socket.h" #include "Socket.h"

646
Jupiter/INIFile.cpp

@ -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 &section, 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 &section, 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 &section)
{
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 &section) 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 &section) 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 &section, 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 &section, 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 &section, 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 &section, 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 &section, const Jupiter::ReadableString &key, short defaultValue) const
{
return static_cast<short>(Jupiter::INIFile::getInt(section, key, defaultValue));
}
int Jupiter::INIFile::getInt(const Jupiter::ReadableString &section, 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 &section, 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 &section, 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 &section, 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 &section, 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 &section, 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;
}

522
Jupiter/INIFile.h

@ -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 &section, 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 &section, 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 &section);
/**
* @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 &section) 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 &section) 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 &section, 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 &section, 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 &section, 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 &section, 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 &section, 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 &section, 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 &section, 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 &section, 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 &section, 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 &section, 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 &section, 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

23
Jupiter/IRC_Client.cpp

@ -22,7 +22,6 @@
#include "Jupiter.h" #include "Jupiter.h"
#include "Functions.h" #include "Functions.h"
#include "IRC_Client.h" #include "IRC_Client.h"
#include "INIFile.h"
#include "TCPSocket.h" #include "TCPSocket.h"
#include "CString.h" #include "CString.h"
#include "String.h" #include "String.h"
@ -57,8 +56,8 @@ struct JUPITER_API Jupiter::IRC::Client::Data
Jupiter::StringS saslPass; Jupiter::StringS saslPass;
int connectionStatus; int connectionStatus;
Jupiter::StringS primary_section_name; Jupiter::StringS primary_section_name;
const Jupiter::INIFile::Section *primary_section; const Jupiter::Config *primary_section;
const Jupiter::INIFile::Section *secondary_section; const Jupiter::Config *secondary_section;
Jupiter::CStringS logFileName; Jupiter::CStringS logFileName;
Jupiter::StringS last_line; Jupiter::StringS last_line;
unsigned short serverPort; unsigned short serverPort;
@ -132,7 +131,7 @@ struct Jupiter::IRC::Client::Channel::Data
bool isAddingNames; bool isAddingNames;
}; };
Jupiter::IRC::Client::Client(const Jupiter::INIFile::Section *in_primary_section, const Jupiter::INIFile::Section *in_secondary_section) Jupiter::IRC::Client::Client(const Jupiter::Config *in_primary_section, const Jupiter::Config *in_secondary_section)
{ {
Jupiter::IRC::Client::data_ = new Jupiter::IRC::Client::Data(this); Jupiter::IRC::Client::data_ = new Jupiter::IRC::Client::Data(this);
@ -308,17 +307,17 @@ const Jupiter::ReadableString &Jupiter::IRC::Client::getConfigSection() const
return Jupiter::ReferenceString::empty; return Jupiter::ReferenceString::empty;
} }
const Jupiter::INIFile::Section *Jupiter::IRC::Client::getPrimaryConfigSection() const const Jupiter::Config *Jupiter::IRC::Client::getPrimaryConfigSection() const
{ {
return Jupiter::IRC::Client::data_->primary_section; return Jupiter::IRC::Client::data_->primary_section;
} }
const Jupiter::INIFile::Section *Jupiter::IRC::Client::getSecondaryConfigSection() const const Jupiter::Config *Jupiter::IRC::Client::getSecondaryConfigSection() const
{ {
return Jupiter::IRC::Client::data_->secondary_section; return Jupiter::IRC::Client::data_->secondary_section;
} }
void Jupiter::IRC::Client::setPrimaryConfigSection(const Jupiter::INIFile::Section *in_primary_section) void Jupiter::IRC::Client::setPrimaryConfigSection(const Jupiter::Config *in_primary_section)
{ {
Jupiter::IRC::Client::data_->primary_section = in_primary_section; Jupiter::IRC::Client::data_->primary_section = in_primary_section;
@ -328,7 +327,7 @@ void Jupiter::IRC::Client::setPrimaryConfigSection(const Jupiter::INIFile::Secti
Jupiter::IRC::Client::data_->primary_section_name.erase(); Jupiter::IRC::Client::data_->primary_section_name.erase();
} }
void Jupiter::IRC::Client::setSecondaryConfigSection(const Jupiter::INIFile::Section *in_secondary_section) void Jupiter::IRC::Client::setSecondaryConfigSection(const Jupiter::Config *in_secondary_section)
{ {
Jupiter::IRC::Client::data_->secondary_section = in_secondary_section; Jupiter::IRC::Client::data_->secondary_section = in_secondary_section;
} }
@ -1449,7 +1448,7 @@ bool Jupiter::IRC::Client::readConfigBool(const Jupiter::ReadableString &key, bo
} }
if (Jupiter::IRC::Client::data_->secondary_section != nullptr) if (Jupiter::IRC::Client::data_->secondary_section != nullptr)
return Jupiter::IRC::Client::data_->secondary_section->getBool(key, defaultValue); return Jupiter::IRC::Client::data_->secondary_section->get<bool>(key, defaultValue);
return defaultValue; return defaultValue;
} }
@ -1465,7 +1464,7 @@ int Jupiter::IRC::Client::readConfigInt(const Jupiter::ReadableString &key, int
} }
if (Jupiter::IRC::Client::data_->secondary_section != nullptr) if (Jupiter::IRC::Client::data_->secondary_section != nullptr)
return Jupiter::IRC::Client::data_->secondary_section->getInt(key, defaultValue); return Jupiter::IRC::Client::data_->secondary_section->get<int>(key, defaultValue);
return defaultValue; return defaultValue;
} }
@ -1481,7 +1480,7 @@ long Jupiter::IRC::Client::readConfigLong(const Jupiter::ReadableString &key, lo
} }
if (Jupiter::IRC::Client::data_->secondary_section != nullptr) if (Jupiter::IRC::Client::data_->secondary_section != nullptr)
return Jupiter::IRC::Client::data_->secondary_section->getLong(key, defaultValue); return Jupiter::IRC::Client::data_->secondary_section->get<long>(key, defaultValue);
return defaultValue; return defaultValue;
} }
@ -1497,7 +1496,7 @@ double Jupiter::IRC::Client::readConfigDouble(const Jupiter::ReadableString &key
} }
if (Jupiter::IRC::Client::data_->secondary_section != nullptr) if (Jupiter::IRC::Client::data_->secondary_section != nullptr)
return Jupiter::IRC::Client::data_->secondary_section->getDouble(key, defaultValue); return Jupiter::IRC::Client::data_->secondary_section->get<double>(key, defaultValue);
return defaultValue; return defaultValue;
} }

12
Jupiter/IRC_Client.h

@ -30,7 +30,7 @@
#include "Thinker.h" #include "Thinker.h"
#include "IRC.h" #include "IRC.h"
#include "Reference_String.h" #include "Reference_String.h"
#include "INIFile.h" #include "Config.h"
namespace Jupiter namespace Jupiter
{ {
@ -479,14 +479,14 @@ namespace Jupiter
* *
* @return The primary config section if it exists, nullptr otherwise. * @return The primary config section if it exists, nullptr otherwise.
*/ */
const Jupiter::INIFile::Section *getPrimaryConfigSection() const; const Jupiter::Config *getPrimaryConfigSection() const;
/** /**
* @brief Fetches the primary config section * @brief Fetches the primary config section
* *
* @return The primary config section if it exists, nullptr otherwise. * @return The primary config section if it exists, nullptr otherwise.
*/ */
const Jupiter::INIFile::Section *getSecondaryConfigSection() const; const Jupiter::Config *getSecondaryConfigSection() const;
/** /**
* @brief Sets the primary config section * @brief Sets the primary config section
@ -494,7 +494,7 @@ namespace Jupiter
* *
* @param in_primary_section Primary config section to begin using * @param in_primary_section Primary config section to begin using
*/ */
virtual void setPrimaryConfigSection(const Jupiter::INIFile::Section *in_primary_section); virtual void setPrimaryConfigSection(const Jupiter::Config *in_primary_section);
/** /**
* @brief Sets the secondary config section * @brief Sets the secondary config section
@ -502,7 +502,7 @@ namespace Jupiter
* *
* @param in_secondary_section Secondary config section to begin using * @param in_secondary_section Secondary config section to begin using
*/ */
virtual void setSecondaryConfigSection(const Jupiter::INIFile::Section *in_secondary_section); virtual void setSecondaryConfigSection(const Jupiter::Config *in_secondary_section);
/** /**
* @brief Returns the name of the file this logs to. * @brief Returns the name of the file this logs to.
@ -887,7 +887,7 @@ namespace Jupiter
* @param in_primary_section INIFile section to search first for a configuration option * @param in_primary_section INIFile section to search first for a configuration option
* @param in_secondary_section INIFile section to search second for a configuration, before using a pre-defined default value * @param in_secondary_section INIFile section to search second for a configuration, before using a pre-defined default value
*/ */
Client(const Jupiter::INIFile::Section *in_primary_section, const Jupiter::INIFile::Section *in_secondary_section); Client(const Jupiter::Config *in_primary_section, const Jupiter::Config *in_secondary_section);
/** /**
* @brief Destructor for a client. * @brief Destructor for a client.

31
Jupiter/IRC_Server.cpp

@ -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();
};

50
Jupiter/IRC_Server.h

@ -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

4
Jupiter/Jupiter.vcxproj

@ -187,9 +187,7 @@
<ClCompile Include="GenericCommand.cpp" /> <ClCompile Include="GenericCommand.cpp" />
<ClCompile Include="Hash.cpp" /> <ClCompile Include="Hash.cpp" />
<ClCompile Include="HTTP_Server.cpp" /> <ClCompile Include="HTTP_Server.cpp" />
<ClCompile Include="INIFile.cpp" />
<ClCompile Include="IRC_Client.cpp" /> <ClCompile Include="IRC_Client.cpp" />
<ClCompile Include="IRC_Server.cpp" />
<ClCompile Include="Jupiter.cpp" /> <ClCompile Include="Jupiter.cpp" />
<ClCompile Include="Plugin.cpp" /> <ClCompile Include="Plugin.cpp" />
<ClCompile Include="Queue.cpp" /> <ClCompile Include="Queue.cpp" />
@ -223,10 +221,8 @@
<ClInclude Include="InvalidIndex.h" /> <ClInclude Include="InvalidIndex.h" />
<ClInclude Include="IRC.h" /> <ClInclude Include="IRC.h" />
<ClInclude Include="IRC_Numerics.h" /> <ClInclude Include="IRC_Numerics.h" />
<ClInclude Include="IRC_Server.h" />
<ClInclude Include="Jupiter.h" /> <ClInclude Include="Jupiter.h" />
<ClInclude Include="Functions.h" /> <ClInclude Include="Functions.h" />
<ClInclude Include="INIFile.h" />
<ClInclude Include="IRC_Client.h" /> <ClInclude Include="IRC_Client.h" />
<ClInclude Include="List.h" /> <ClInclude Include="List.h" />
<ClInclude Include="Plugin.h" /> <ClInclude Include="Plugin.h" />

12
Jupiter/Jupiter.vcxproj.filters

@ -72,9 +72,6 @@
<ClCompile Include="Jupiter.cpp"> <ClCompile Include="Jupiter.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="IRC_Server.cpp">
<Filter>Source Files\IRC</Filter>
</ClCompile>
<ClCompile Include="Queue.cpp"> <ClCompile Include="Queue.cpp">
<Filter>Source Files\Lists</Filter> <Filter>Source Files\Lists</Filter>
</ClCompile> </ClCompile>
@ -90,9 +87,6 @@
<ClCompile Include="SecureSocket.cpp"> <ClCompile Include="SecureSocket.cpp">
<Filter>Source Files\Sockets</Filter> <Filter>Source Files\Sockets</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="INIFile.cpp">
<Filter>Source Files\Files</Filter>
</ClCompile>
<ClCompile Include="File.cpp"> <ClCompile Include="File.cpp">
<Filter>Source Files\Files</Filter> <Filter>Source Files\Files</Filter>
</ClCompile> </ClCompile>
@ -179,9 +173,6 @@
<ClInclude Include="IRC_Client.h"> <ClInclude Include="IRC_Client.h">
<Filter>Header Files\IRC</Filter> <Filter>Header Files\IRC</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="IRC_Server.h">
<Filter>Header Files\IRC</Filter>
</ClInclude>
<ClInclude Include="ArrayList.h"> <ClInclude Include="ArrayList.h">
<Filter>Header Files\Lists</Filter> <Filter>Header Files\Lists</Filter>
</ClInclude> </ClInclude>
@ -194,9 +185,6 @@
<ClInclude Include="CString_Imp.h"> <ClInclude Include="CString_Imp.h">
<Filter>Header Files\Strings</Filter> <Filter>Header Files\Strings</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="INIFile.h">
<Filter>Header Files\Files</Filter>
</ClInclude>
<ClInclude Include="File.h"> <ClInclude Include="File.h">
<Filter>Header Files\Files</Filter> <Filter>Header Files\Files</Filter>
</ClInclude> </ClInclude>

4
Jupiter/Plugin.cpp

@ -107,7 +107,7 @@ const Jupiter::ReadableString &Jupiter::Plugin::getName() const
return Jupiter::Plugin::name; return Jupiter::Plugin::name;
} }
const Jupiter::INIFile &Jupiter::Plugin::getConfig() const const Jupiter::Config &Jupiter::Plugin::getConfig() const
{ {
return Jupiter::Plugin::config; return Jupiter::Plugin::config;
} }
@ -186,7 +186,7 @@ Jupiter::Plugin *Jupiter::Plugin::load(const Jupiter::ReadableString &pluginName
// Initialize the plugin // Initialize the plugin
dPlug->plugin->name.set(pluginName); dPlug->plugin->name.set(pluginName);
dPlug->plugin->config.readFile(plugin_configs_directory + pluginName + config_file_extension); dPlug->plugin->config.read(plugin_configs_directory + pluginName + config_file_extension);
dPlug->plugin->initialize(); dPlug->plugin->initialize();
} }
{ {

6
Jupiter/Plugin.h

@ -27,7 +27,7 @@
#include "ArrayList.h" #include "ArrayList.h"
#include "Thinker.h" #include "Thinker.h"
#include "Rehash.h" #include "Rehash.h"
#include "INIFile.h" #include "INIConfig.h"
#include "String.h" #include "String.h"
/** DLL Linkage Nagging */ /** DLL Linkage Nagging */
@ -96,7 +96,7 @@ namespace Jupiter
* *
* @return Plugin's configuration file. * @return Plugin's configuration file.
*/ */
const Jupiter::INIFile &getConfig() const; const Jupiter::Config &getConfig() const;
/** /**
* @brief Initializes the plugin. * @brief Initializes the plugin.
@ -372,7 +372,7 @@ namespace Jupiter
protected: protected:
bool _shouldRemove = false; bool _shouldRemove = false;
Jupiter::StringS name; Jupiter::StringS name;
Jupiter::INIFile config; Jupiter::INIConfig config;
}; };
/** The list containing pointers to plugins */ /** The list containing pointers to plugins */

26
Jupiter/Readable_String.h

@ -430,19 +430,19 @@ namespace Jupiter
inline bool operator>=(const T right)const{ return !operator<(right); } inline bool operator>=(const T right)const{ return !operator<(right); }
/** Conversion operators */ /** Conversion operators */
explicit inline operator bool() { return this->asBool(); } explicit inline operator bool() const { return this->asBool(); }
explicit inline operator short() { return static_cast<short>(this->asInt()); } explicit inline operator short() const { return static_cast<short>(this->asInt()); }
explicit inline operator unsigned short() { return static_cast<unsigned short>(this->asUnsignedInt()); } explicit inline operator unsigned short() const { return static_cast<unsigned short>(this->asUnsignedInt()); }
explicit inline operator int() { return this->asInt(); } explicit inline operator int() const { return this->asInt(); }
explicit inline operator unsigned int() { return this->asUnsignedInt(); } explicit inline operator unsigned int() const { return this->asUnsignedInt(); }
explicit inline operator long() { return static_cast<long>(this->asLongLong()); } explicit inline operator long() const { return static_cast<long>(this->asLongLong()); }
explicit inline operator unsigned long() { return static_cast<unsigned long>(this->asLongLong()); } explicit inline operator unsigned long() const { return static_cast<unsigned long>(this->asLongLong()); }
explicit inline operator long long() { return this->asLongLong(); } explicit inline operator long long() const { return this->asLongLong(); }
explicit inline operator unsigned long long() { return this->asUnsignedLongLong(); } explicit inline operator unsigned long long() const { return this->asUnsignedLongLong(); }
explicit inline operator float() { return static_cast<float>(this->asDouble()); } explicit inline operator float() const { return static_cast<float>(this->asDouble()); }
explicit inline operator double() { return this->asDouble(); } explicit inline operator double() const { return this->asDouble(); }
explicit inline operator long double() { return this->asDouble(); } // NEEDS TO NOT CAST FROM DOUBLE explicit inline operator long double() const { return this->asDouble(); } // NEEDS TO NOT CAST FROM DOUBLE
explicit inline operator std::basic_string<T>() { return std::basic_string<T>(this->ptr(), this->size()); } explicit inline operator std::basic_string<T>() const { return std::basic_string<T>(this->ptr(), this->size()); }
private: private:
template<typename R> R calcChecksumiHelper() const; template<typename R> R calcChecksumiHelper() const;

Loading…
Cancel
Save