undetermined Config::Config

Started by
3 comments, last by rip-off 14 years, 11 months ago
Ok, so I am having some issues with some of my code...It's for my config files Here is the code for the .ini parser.. config.hpp
/**
 This code is not to be used in any projects without concent of the owners.**/

#ifndef CONFIG_HPP_INCLUDED
#define CONFIG_HPP_INCLUDED

#include <string>
#include <map>
#include <cstddef>

class Config;

#include "util.hpp"

/**
 * Reads configuration data from a file.
 * Does not support sections in files (they're usually ignored).
 */
class Config : public std::map<std::string, util::variant>
{
	protected:
		/**
		 * Filename of the configuration file.
		 * Stored in case save support is ever added.
		 */
		std::string filename;

	public:
		/**
		 * Maximum length of a line in the configuration file.
		 */
		static const std::size_t MaxLineLength = 4096;

		/**
		 * Construct an empty Config object which should have Read() called on it
		 */
		Config();

		/**
		 * Reads all configuration data from the file to memory.
		 * @param filename File to read from.
		 */
		Config(std::string filename);

		/**
		 * Reads all configuration data from the file to memory.
		 * @param filename File to read from.
		 */
		void Read(std::string filename);
};

#endif // CONFIG_HPP_INCLUDED

util.cpp

#include "util.hpp"

#include <list>
#include <vector>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <string>

namespace util
{

variant::variant()
{
	this->type = type_int;
	this->val_int = 0;
}

variant::variant(int i)
{
	this->SetInt(i);
}

variant::variant(double d)
{
	this->SetFloat(d);
}

variant::variant(const std::string &s)
{
	this->SetString(s);
}

int variant::int_length(int x)
{
	int count = 1;
	int val = 10;

	while (x >= val)
	{
		val *= 10;
		++count;
	}

	return count;
}

int variant::GetInt()
{
	switch (this->type)
	{
		case type_float:
			this->val_int = static_cast<int>(this->val_float);
			break;

		case type_string:
			this->val_int = 0;
			std::sscanf(this->val_string.c_str(), "%d", &this->val_int);
			break;
	}

	return this->val_int;
}

double variant::GetFloat()
{
	switch (this->type)
	{
		case type_int:
			this->val_float = static_cast<double>(this->val_int);
			break;

		case type_string:
			this->val_float = 0.0;
			std::sscanf(this->val_string.c_str(), "%lf", &this->val_float);
			break;
	}

	return this->val_float;
}

std::string variant::GetString()
{
	char buf[1024];

	switch (this->type)
	{
		case type_int:
			std::snprintf(buf, 1024, "%i", this->val_int);
			this->val_string = buf;
			break;

		case type_float:
			std::snprintf(buf, 1024, "%f", this->val_float);
			this->val_string = buf;
			break;
	}

	return this->val_string;
}

variant &variant::SetInt(int i)
{
	this->val_int = i;
	this->type = type_int;
	return *this;
}

variant &variant::SetFloat(double d)
{
	this->val_float = d;
	this->type = type_float;
	return *this;
}

variant &variant::SetString(const std::string &s)
{
	this->val_string = s;
	this->type = type_string;
	return *this;
}

variant &variant::operator =(int i)
{
	return this->SetInt(i);
}

variant &variant::operator =(double d)
{
	return this->SetFloat(d);
}

variant &variant::operator =(const std::string &s)
{
	return this->SetString(s);
}

variant::operator int()
{
	return this->GetInt();
}

variant::operator double()
{
	return this->GetFloat();
}

variant::operator std::string()
{
	return this->GetString();
}

std::string ltrim(const std::string &str)
{
	std::size_t si = str.find_first_not_of(" \t\n\r");

	if (si == std::string::npos)
	{
		si = 0;
	}
	else
	{
		--si;
	}
	++si;

	return str.substr(si);
}

std::string rtrim(const std::string &str)
{
	std::size_t ei = str.find_last_not_of(" \t\n\r");

	if (ei == std::string::npos)
	{
		ei = str.length()-1;
	}
	++ei;

	return str.substr(0, ei);
}

std::string trim(const std::string &str)
{
	std::size_t si, ei;
	bool notfound = false;

	si = str.find_first_not_of(" \t\n\r");
	if (si == std::string::npos)
	{
		si = 0;
		notfound = true;
	}

	ei = str.find_last_not_of(" \t\n\r");
	if (ei == std::string::npos)
	{
		if (notfound)
		{
			return "";
		}
		ei = str.length()-1;
	}
	++ei;

	return str.substr(si, ei);
}

std::vector<std::string> explode(char delimiter, std::string str)
{
	std::size_t lastpos = 0;
	std::size_t pos = 0;
	std::vector<std::string> pieces;

	for (pos = str.find_first_of(delimiter); pos != std::string::npos; )
	{
		pieces.push_back(str.substr(lastpos, pos - lastpos));
		lastpos = pos+1;
		pos = str.find_first_of(delimiter, pos+1);
	}
	pieces.push_back(str.substr(lastpos));

	return pieces;
}

double tdparse(std::string timestr)
{
	static char period_names[] = {'s', 'm',  'h',    'd'    };
	static double period_mul[] = {1.0, 60.0, 3600.0, 86400.0};
	double ret = 0.0;
	double val = 0;

	for (std::size_t i = 0; i < timestr.length(); ++i)
	{
		char c = timestr.c_str();
		bool found = false;

		if (c >= 'A' && c <= 'Z')
		{
			c -= 'A' - 'a';
		}

		for (std::size_t i = 0; i < sizeof(period_names)/sizeof(char); ++i)
		{
			if (c == period_names)
			{
				ret += val * period_mul;
				found = true;
				val = false;
			}
		}

		if (!found)
		{
			val *= 10;
			val += c - '0';
		}
	}

	return ret;
}

int to_int(const std::string &subject)
{
	return static_cast<int>(util::variant(subject));
}

std::string to_string(int subject)
{
	return static_cast<std::string>(util::variant(subject));
}

void lowercase(std::string &subject)
{
	std::transform(subject.begin(), subject.end(), subject.begin(), static_cast<int(*)(int)>(std::tolower));
}

void uppercase(std::string &subject)
{
	std::transform(subject.begin(), subject.end(), subject.begin(), static_cast<int(*)(int)>(std::toupper));
}

void ucfirst(std::string &subject)
{
	if (subject[0] > 'a' && subject[0] < 'z')
	{
		subject[0] += 'A' - 'a';
	}
}

int rand(int min, int max)
{
	static bool init = false;
	if (!init)
	{
		init = true;
		std::srand(std::time(0));
	}
	return double(std::rand()) / RAND_MAX * (max - min + 1) + min;
}

}

util.hpp
#ifndef UTIL_HPP_INCLUDED
#define UTIL_HPP_INCLUDED

#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <cstring>
#include <cstddef>
#include <cstdarg>
#include <stdexcept>
#include <algorithm>
#include <iterator>

/**
 * Utility functions to assist with common tasks
 */
namespace util
{

// A gigantic pile of fail
// Uglified it to make it generate standard C++ code

#define UTIL_FOREACH_GENERIC(iterator, start, end, type, as) 	for (int util_i = 0; util_i < 1; ++util_i) 		for (iterator util_start = start; util_i < 1; ++util_i) 			for (iterator util_end = end; util_i < 1; ++util_i) 				for (type as = *util_start; util_i < 1; ++util_i) 					for(iterator util_iter = util_start; util_iter != util_end; as = (++util_iter == util_end)?*util_start:*util_iter)

#define UTIL_IFOREACH_GENERIC(iterator, start, end, type, as) 	for (int util_i = 0; util_i < 1; ++util_i) 		for (iterator util_start = start; util_i < 1; ++util_i) 			for (iterator util_end = end; util_i < 1; ++util_i) 				for (iterator as = util_start; as != util_end; ++as)

#define UTIL_FOREACH_GENERIC2(iterator, iterator2, start, end, type, as) 	for (int util_i = 0; util_i < 1; ++util_i) 		for (iterator,iterator2 util_start = start; util_i < 1; ++util_i) 			for (iterator,iterator2 util_end = end; util_i < 1; ++util_i) 				for (type as = *util_start; util_i < 1; ++util_i) 					for(iterator,iterator2 util_iter = util_start; util_iter != util_end; as = (++util_iter == util_end)?*util_start:*util_iter)

#define UTIL_IFOREACH_GENERIC2(iterator, iterator2, start, end, type, as) 	for (int util_i = 0; util_i < 1; ++util_i) 		for (iterator,iterator2 util_start = container.begin(); util_i < 1; ++util_i) 			for (iterator,iterator2 util_end = contianer.end(); util_i < 1; ++util_i) 				for (iterator,iterator2 as = util_start; as != util_end; ++as)

#define UTIL_ARRAY_FOREACH(start, end, type, type2, as) UTIL_FOREACH_GENERIC2(util::array<type, type2 >::iterator, start, end, type, as)
#define UTIL_DEQUE_FOREACH(start, end, type, as) UTIL_FOREACH_GENERIC(std::deque<type >::iterator, start, end, type, as)
#define UTIL_LIST_FOREACH(start, end, type, as) UTIL_FOREACH_GENERIC(std::list<type >::iterator, start, end, type, as)
#define UTIL_MAP_FOREACH(start, end, type, type2, as) UTIL_FOREACH_GENERIC2(std::map<type >::iterator, start, end, type, as)
#define UTIL_MULTIMAP_FOREACH(start, end, type, type2, as) UTIL_FOREACH_GENERIC2(std::multimap<type >::iterator, start, end, type, as)
#define UTIL_QUEUE_FOREACH(start, end, type, as) UTIL_FOREACH_GENERIC(std::queue<type >::iterator, start, end, type, as)
#define UTIL_PRIORITY_QUEUE_FOREACH(start, end, type, as) UTIL_FOREACH_GENERIC(std::priority_queue<type >::iterator, start, end, type, as)
#define UTIL_SET_FOREACH(start, end, type, as) UTIL_FOREACH_GENERIC(std::set<type >::iterator, start, end, type, as)
#define UTIL_MULTISET_FOREACH(start, end, type, as) UTIL_FOREACH_GENERIC(std::multiset<type >::iterator, start, end, type, as)
#define UTIL_STACK_FOREACH(start, end, type, as) UTIL_FOREACH_GENERIC(std::stack<type >::iterator, start, end, type, as)
#define UTIL_VECTOR_FOREACH(start, end, type, as) UTIL_FOREACH_GENERIC(std::vector<type >::iterator, start, end, type, as)

#define UTIL_ARRAY_IFOREACH(start, end, type, type2, as) UTIL_IFOREACH_GENERIC2(util::array<type, type2 >::iterator, start, end, type, as)
#define UTIL_DEQUE_IFOREACH(start, end, type, as) UTIL_IFOREACH_GENERIC(std::deque<type >::iterator, start, end, type, as)
#define UTIL_LIST_IFOREACH(start, end, type, as) UTIL_IFOREACH_GENERIC(std::list<type >::iterator, start, end, type, as)
#define UTIL_MAP_IFOREACH(start, end, type, type2, as) UTIL_IFOREACH_GENERIC2(std::map<type, type2 >::iterator, start, end, type, as)
#define UTIL_MULTIMAP_IFOREACH(start, end, type, type2, as) UTIL_IFOREACH_GENERIC2(std::multimap<type, type2 >::iterator, start, end, type, as)
#define UTIL_QUEUE_IFOREACH(start, end, type, as) UTIL_IFOREACH_GENERIC(std::queue<type >::iterator, start, end, type, as)
#define UTIL_PRIORITY_QUEUE_IFOREACH(start, end, type, as) UTIL_IFOREACH_GENERIC(std::priority_queue<type >::iterator, start, end, type, as)
#define UTIL_SET_IFOREACH(start, end, type, as) UTIL_IFOREACH_GENERIC(std::set<type >::iterator, start, end, type, as)
#define UTIL_MULTISET_IFOREACH(start, end, type, as) UTIL_IFOREACH_GENERIC(std::multiset<type >::iterator, start, end, type, as)
#define UTIL_STACK_IFOREACH(start, end, type, as) UTIL_IFOREACH_GENERIC(std::stack<type >::iterator, start, end, type, as)
#define UTIL_VECTOR_IFOREACH(start, end, type, as) UTIL_IFOREACH_GENERIC(std::vector<type >::iterator, start, end, type, as)

#define UTIL_ARRAY_FOREACH_ALL(container, type, type2, as) if (!container.empty()) UTIL_ARRAY_FOREACH(container.begin(), container.end(), type, type2, as)
#define UTIL_DEQUE_FOREACH_ALL(container, type, as) if (!container.empty()) UTIL_DEQUE_FOREACH(container.begin(), container.end() type, as)
#define UTIL_LIST_FOREACH_ALL(container, type, as) if (!container.empty()) UTIL_LIST_FOREACH(container.begin(), container.end(), type, as)
#define UTIL_MAP_FOREACH_ALL(container, type, type2, as) if (!container.empty()) UTIL_MAP_FOREACH(container.begin(), container.end(), type, type2, as)
#define UTIL_MULTIMAP_FOREACH_ALL(container, type, type2, as) if (!container.empty()) UTIL_MULTIMAP_FOREACH(container.begin(), container.end(), type, type2, as)
#define UTIL_QUEUE_FOREACH_ALL(container, type, as) if (!container.empty()) UTIL_QUEUE_FOREACH(container.begin(), container.end(), type, as)
#define UTIL_PRIORITY_QUEUE_FOREACH_ALL(container, type, as) if (!container.empty()) UTIL_PRIORITY_QUEUE_FOREACH(container.begin(), container.end(), type, as)
#define UTIL_SET_FOREACH_ALL(container, type, as) if (!container.empty()) UTIL_SET_FOREACH(container.begin(), container.end(), type, as)
#define UTIL_MULTISET_FOREACH_ALL(container, type, as) if (!container.empty()) UTIL_MULTISET_FOREACH(container.begin(), container.end(), type, as)
#define UTIL_STACK_FOREACH_ALL(container, type, as) if (!container.empty()) UTIL_STACK_FOREACH(container.begin(), container.end(), type, as)
#define UTIL_VECTOR_FOREACH_ALL(container, type, as) if (!container.empty()) UTIL_VECTOR_FOREACH(container.begin(), container.end(), type, as)

#define UTIL_ARRAY_IFOREACH_ALL(container, type, type2, as) if (!container.empty()) UTIL_ARRAY_IFOREACH(container.begin(), container.end(), type, type2, as)
#define UTIL_DEQUE_IFOREACH_ALL(container, type, as) if (!container.empty()) UTIL_DEQUE_IFOREACH(container.begin(), container.end(), type, as)
#define UTIL_LIST_IFOREACH_ALL(container, type, as) if (!container.empty()) UTIL_LIST_IFOREACH(container.begin(), container.end(), type, as)
#define UTIL_MAP_IFOREACH_ALL(container, type, type2, as) if (!container.empty()) UTIL_MAP_IFOREACH(container.begin(), container.end(), type, type2, as)
#define UTIL_MULTIMAP_IFOREACH_ALL(container, type, type2, as) if (!container.empty()) UTIL_MULTIMAP_IFOREACH(container.begin(), container.end(), type, type2, as)
#define UTIL_QUEUE_IFOREACH_ALL(container, type, as) if (!container.empty()) UTIL_QUEUE_IFOREACH(container.begin(), container.end(), type, as)
#define UTIL_PRIORITY_QUEUE_IFOREACH_ALL(container, type, as) if (!container.empty()) UTIL_PRIORITY_QUEUE_IFOREACH(container.begin(), container.end(), type, as)
#define UTIL_SET_IFOREACH_ALL(container, type, as) if (!container.empty()) UTIL_SET_IFOREACH(container.begin(), container.end(), type, as)
#define UTIL_MULTISET_IFOREACH_ALL(container, type, as) if (!container.empty()) UTIL_MULTISET_IFOREACH(container.begin(), container.end(), type, as)
#define UTIL_STACK_IFOREACH_ALL(container, type, as) if (!container.empty()) UTIL_STACK_IFOREACH(container.begin(), container.end(), type, as)
#define UTIL_VECTOR_IFOREACH_ALL(container, type, as) if (!container.empty()) UTIL_VECTOR_IFOREACH(container.begin(), container.end(), type, as)

#define UTIL_TPL_ARRAY_FOREACH(start, end, type, type2, as) UTIL_FOREACH_GENERIC2(class util::array<type, type2 >::iterator, start, end, type, as)
#define UTIL_TPL_DEQUE_FOREACH(start, end, type, as) UTIL_FOREACH_GENERIC(class std::deque<type >::iterator, start, end, type, as)
#define UTIL_TPL_LIST_FOREACH(start, end, type, as) UTIL_FOREACH_GENERIC(class std::list<type >::iterator, start, end, type, as)
#define UTIL_TPL_MAP_FOREACH(start, end, type, type2, as) UTIL_FOREACH_GENERIC2(class std::map<type >::iterator, start, end, type, as)
#define UTIL_TPL_MULTIMAP_FOREACH(start, end, type, type2, as) UTIL_FOREACH_GENERIC2(class std::multimap<type >::iterator, start, end, type, as)
#define UTIL_TPL_QUEUE_FOREACH(start, end, type, as) UTIL_FOREACH_GENERIC(class std::queue<type >::iterator, start, end, type, as)
#define UTIL_TPL_PRIORITY_QUEUE_FOREACH(start, end, type, as) UTIL_FOREACH_GENERIC(class std::priority_queue<type >::iterator, start, end, type, as)
#define UTIL_TPL_SET_FOREACH(start, end, type, as) UTIL_FOREACH_GENERIC(class std::set<type >::iterator, start, end, type, as)
#define UTIL_TPL_MULTISET_FOREACH(start, end, type, as) UTIL_FOREACH_GENERIC(class std::multiset<type >::iterator, start, end, type, as)
#define UTIL_TPL_STACK_FOREACH(start, end, type, as) UTIL_FOREACH_GENERIC(class std::stack<type >::iterator, start, end, type, as)
#define UTIL_TPL_VECTOR_FOREACH(start, end, type, as) UTIL_FOREACH_GENERIC(class std::vector<type >::iterator, start, end, type, as)

#define UTIL_TPL_ARRAY_IFOREACH(start, end, type, type2, as) UTIL_IFOREACH_GENERIC2(class util::array<type, type2 >::iterator, start, end, type, as)
#define UTIL_TPL_DEQUE_IFOREACH(start, end, type, as) UTIL_IFOREACH_GENERIC(class std::deque<type >::iterator, start, end, type, as)
#define UTIL_TPL_LIST_IFOREACH(start, end, type, as) UTIL_IFOREACH_GENERIC(class std::list<type >::iterator, start, end, type, as)
#define UTIL_TPL_MAP_IFOREACH(start, end, type, type2, as) UTIL_IFOREACH_GENERIC2(class std::map<type, type2 >::iterator, start, end, type, as)
#define UTIL_TPL_MULTIMAP_IFOREACH(start, end, type, type2, as) UTIL_IFOREACH_GENERIC2(class std::multimap<type, type2 >::iterator, start, end, type, as)
#define UTIL_TPL_QUEUE_IFOREACH(start, end, type, as) UTIL_IFOREACH_GENERIC(class std::queue<type >::iterator, start, end, type, as)
#define UTIL_TPL_PRIORITY_QUEUE_IFOREACH(start, end, type, as) UTIL_IFOREACH_GENERIC(class std::priority_queue<type >::iterator, start, end, type, as)
#define UTIL_TPL_SET_IFOREACH(start, end, type, as) UTIL_IFOREACH_GENERIC(class std::set<type >::iterator, start, end, type, as)
#define UTIL_TPL_MULTISET_IFOREACH(start, end, type, as) UTIL_IFOREACH_GENERIC(class std::multiset<type >::iterator, start, end, type, as)
#define UTIL_TPL_STACK_IFOREACH(start, end, type, as) UTIL_IFOREACH_GENERIC(class std::stack<type >::iterator, start, end, type, as)
#define UTIL_TPL_VECTOR_IFOREACH(start, end, type, as) UTIL_IFOREACH_GENERIC(class std::vector<type >::iterator, start, end, type, as)

#define UTIL_TPL_ARRAY_FOREACH_ALL(container, type, type2, as) if (!container.empty()) UTIL_TPL_ARRAY_FOREACH(container.begin(), container.end(), type, type2, as)
#define UTIL_TPL_DEQUE_FOREACH_ALL(container, type, as) if (!container.empty()) UTIL_TPL_DEQUE_FOREACH(container.begin(), container.end() type, as)
#define UTIL_TPL_LIST_FOREACH_ALL(container, type, as) if (!container.empty()) UTIL_TPL_LIST_FOREACH(container.begin(), container.end(), type, as)
#define UTIL_TPL_MAP_FOREACH_ALL(container, type, type2, as) if (!container.empty()) UTIL_TPL_MAP_FOREACH(container.begin(), container.end(), type, type2, as)
#define UTIL_TPL_MULTIMAP_FOREACH_ALL(container, type, type2, as) if (!container.empty()) UTIL_TPL_MULTIMAP_FOREACH(container.begin(), container.end(), type, type2, as)
#define UTIL_TPL_QUEUE_FOREACH_ALL(container, type, as) if (!container.empty()) UTIL_TPL_QUEUE_FOREACH(container.begin(), container.end(), type, as)
#define UTIL_TPL_PRIORITY_QUEUE_FOREACH_ALL(container, type, as) if (!container.empty()) UTIL_TPL_PRIORITY_QUEUE_FOREACH(container.begin(), container.end(), type, as)
#define UTIL_TPL_SET_FOREACH_ALL(container, type, as) if (!container.empty()) UTIL_TPL_SET_FOREACH(container.begin(), container.end(), type, as)
#define UTIL_TPL_MULTISET_FOREACH_ALL(container, type, as) if (!container.empty()) UTIL_TPL_MULTISET_FOREACH(container.begin(), container.end(), type, as)
#define UTIL_TPL_STACK_FOREACH_ALL(container, type, as) if (!container.empty()) UTIL_TPL_STACK_FOREACH(container.begin(), container.end(), type, as)
#define UTIL_TPL_VECTOR_FOREACH_ALL(container, type, as) if (!container.empty()) UTIL_TPL_VECTOR_FOREACH(container.begin(), container.end(), type, as)

#define UTIL_TPL_ARRAY_IFOREACH_ALL(container, type, type2, as) if (!container.empty()) UTIL_TPL_ARRAY_IFOREACH(container.begin(), container.end(), type, type2, as)
#define UTIL_TPL_DEQUE_IFOREACH_ALL(container, type, as) if (!container.empty()) UTIL_TPL_DEQUE_IFOREACH(container.begin(), container.end(), type, as)
#define UTIL_TPL_LIST_IFOREACH_ALL(container, type, as) if (!container.empty()) UTIL_TPL_LIST_IFOREACH(container.begin(), container.end(), type, as)
#define UTIL_TPL_MAP_IFOREACH_ALL(container, type, type2, as) if (!container.empty()) UTIL_TPL_MAP_IFOREACH(container.begin(), container.end(), type, type2, as)
#define UTIL_TPL_MULTIMAP_IFOREACH_ALL(container, type, type2, as) if (!container.empty()) UTIL_TPL_MULTIMAP_IFOREACH(container.begin(), container.end(), type, type2, as)
#define UTIL_TPL_QUEUE_IFOREACH_ALL(container, type, as) if (!container.empty()) UTIL_TPL_QUEUE_IFOREACH(container.begin(), container.end(), type, as)
#define UTIL_TPL_PRIORITY_QUEUE_IFOREACH_ALL(container, type, as) if (!container.empty()) UTIL_TPL_PRIORITY_QUEUE_IFOREACH(container.begin(), container.end(), type, as)
#define UTIL_TPL_SET_IFOREACH_ALL(container, type, as) if (!container.empty()) UTIL_TPL_SET_IFOREACH(container.begin(), container.end(), type, as)
#define UTIL_TPL_MULTISET_IFOREACH_ALL(container, type, as) if (!container.empty()) UTIL_TPL_MULTISET_IFOREACH(container.begin(), container.end(), type, as)
#define UTIL_TPL_STACK_IFOREACH_ALL(container, type, as) if (!container.empty()) UTIL_TPL_STACK_IFOREACH(container.begin(), container.end(), type, as)
#define UTIL_TPL_VECTOR_IFOREACH_ALL(container, type, as) if (!container.empty()) UTIL_TPL_VECTOR_IFOREACH(container.begin(), container.end(), type, as)

#define UTIL_CARRAY_FOREACH(array, start, end, type, as) 	for (int util_i = 0; util_i < 1; ++util_i) 		for (type as = array[start]; util_i < 1; ++util_i) 			for(std::size_t util_iter = start; util_iter <= end; as = array[++util_iter])

#define UTIL_CARRAY_FOREACH_ALL(array, type, as) 	for (int util_i = 0; util_i < 1; ++util_i) 		for (type as = array[0]; util_i < 1; ++util_i) 			for(std::size_t util_iter = 0; util_iter < sizeof(array)/sizeof(type); as = array[++util_iter])

#define UTIL_REPEAT(amt) 	for (int util_i = 0; util_i < amt; ++util_i)

// DEPRECATED
// Relies on a GCC (typeof) or c++0x (decltype) only feature, do not use
#ifdef __GNUC__
#define UTIL_FOREACH(container, as) if (!container.empty()) for (int util_i = 0; util_i < 1; ++util_i) for (typeof(*(container.begin())) as; util_i < 1; ++util_i) for (typeof(container.begin()) util_it = container.begin(); ((util_it != container.end())?(as = *(util_it)):(as = *container.begin())), util_it != container.end(); as = *(util_it++))
#define UTIL_IFOREACH(container, as) if (!container.empty()) for (int util_i = 0; util_i < 1; ++util_i) for (typeof(container.begin()) as; util_i < 1; ++util_i) for (typeof(container.begin()) util_it = container.begin(); ((util_it != container.end())?(as = util_it):(as = container.begin())), util_it != container.end(); as = util_it++)
#else // __GNUC__
#define UTIL_FOREACH(container, as) if (!container.empty()) for (int util_i = 0; util_i < 1; ++util_i) for (decltype(*(container.begin())) as; util_i < 1; ++util_i) for (decltype(container.begin()) util_it = container.begin(); ((util_it != container.end())?(as = *(util_it)):(as = *container.begin())), util_it != container.end(); as = *(util_it++))
#define UTIL_IFOREACH(container, as) if (!container.empty()) for (int util_i = 0; util_i < 1; ++util_i) for (decltype(container.begin()) as; util_i < 1; ++util_i) for (decltype(container.begin()) util_it = container.begin(); ((util_it != container.end())?(as = util_it):(as = container.begin())), util_it != container.end(); as = util_it++)
#endif // __GNUC__

template <typename T, std::size_t N> class array;
class variant;

/**
 * Generic and simple array class.
 */
template <typename T, std::size_t N> class array
{
	private:
		T elements[N];

	public:
		typedef T value_type;
		typedef T *iterator;
		typedef const T *const_iterator;
		typedef std::reverse_iterator<iterator> reverse_iterator;
		typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
		typedef T &reference;
		typedef const T &const_reference;
		typedef std::size_t size_type;
		typedef std::ptrdiff_t difference_type;

		iterator begin()
		{
			return this->elements;
		}

		const_iterator begin() const
		{
			return this->elements;
		}

		iterator end()
		{
			return this->elements + N;
		}

		const_iterator end() const
		{
			return this->elements + N;
		}

		reverse_iterator rbegin()
		{
			return reverse_iterator(this->end());
		}

		const_reverse_iterator rbegin() const
		{
			return const_reverse_iterator(end());
		}

		reverse_iterator rend()
		{
			return reverse_iterator(begin());
		}

		const_reverse_iterator rend() const
		{
			return const_reverse_iterator(begin());
		}


		array() {}

		array(const_reference value)
		{
			this->assign(value);
		}

		array(T init[N])
		{
			std::memcpy(this->elements, init, sizeof(value_type) * N);
		}

		reference at(size_type index)
		{
			if (index >= N)
			{
				throw std::out_of_range("util::array::at");
			}

			return this->elements[index];
		}

		const_reference at(size_type index) const
		{
			if (index >= N)
			{
				throw std::out_of_range("util::array::at");
			}

			return this->elements[index];
		}

		reference operator[](size_type index)
		{
			return this->at(index);
		}

		const_reference operator[](size_type index) const
		{
			return this->at(index);
		}

		reference front()
		{
			return this->begin();
		}

		const_reference front() const
		{
			return this->begin();
		}

		reference back()
		{
			return this->elements[this->end() - 1];
		}

		const_reference back() const
		{
			return this->elements[this->end() - 1];
		}

		size_type size() const
		{
			return N;
		}

		size_type max_size() const
		{
			return N;
		}

		bool empty() const
		{
			return this->size() == 0;
		}

		void assign(const_reference value)
		{
			std::fill_n(this->begin(), this->size(), value);
		}

		void swap(util::array<T, N> &second)
		{
			std::swap_ranges(this->begin(), this->end(), second.begin());
		}

		const T *data() const
		{
			return this->elements;
		}

		T *data()
		{
			return this->data;
		}
};

/**
 * A type that can store any numeric/string value and convert between them.
 * It takes way too much effort to use, so it's only used by the Config class.
 */
class variant
{
	protected:
		/**
		 * Integer and float values are a union to save on a few bytes of memory.
		 */
		union
		{
			/**
			 * Value stored as an integer.
			 */
			int val_int;

			/**
			 * Value stored as a float.
			 */
			double val_float;
		};

		/**
		 * Value stored as a string.
		 */
		std::string val_string;

		enum var_type
		{
			type_int,
			type_float,
			type_string
		};

		/**
		 * Current type the value is stored as.
		 * Accessing as this type will need no conversion.
		 */
		int type;

		/**
		 * Return the value as an integer, casting if neccessary.
		 */
		int GetInt();

		/**
		 * Return the value as a float, casting if neccessary.
		 */
		double GetFloat();

		/**
		 * Return the value as a string, casting if neccessary.
		 */
		std::string GetString();

		/**
		 * Set the value to an integer.
		 */
		variant &SetInt(int);

		/**
		 * Set the value to a float.
		 */
		variant &SetFloat(double);

		/**
		 * Set the value to a string.
		 */
		variant &SetString(const std::string &);

		/**
		 * Helper function that returns the string length of a number in decimal format.
		 */
		int int_length(int);

	public:
		/**
		 * Initialize the variant to an integer with the value 0.
		 */
		variant();

		/**
		 * Initialize the variant to an integer with the specified value.
		 */
		variant(int);

		/**
		 * Initialize the variant to a float with the specified value.
		 */
		variant(double);

		/**
		 * Initialize the variant to a string with the specified value.
		 */
		variant(const std::string &);

		/**
		 * Set the value to an integer.
		 */
		variant &operator =(int);

		/**
		 * Set the value to a float.
		 */
		variant &operator =(double);

		/**
		 * Set the value to a string.
		 */
		variant &operator =(const std::string &);

		/**
		 * Return the value as an integer, casting if neccessary.
		 */
		operator int();

		/**
		 * Return the value as a float, casting if neccessary.
		 */
		operator double();

		/**
		 * Return the value as a string, casting if neccessary.
		 */
		operator std::string();
};

/**
 * Commonly used array type in EOSERV.
 */
typedef array<unsigned char, 2> pairchar;

/**
 * Commonly used array type in EOSERV.
 */
typedef array<unsigned char, 4> quadchar;

/**
 * Trims whitespace from the left of a string.
 * Whitespace is defined as space, tab, CR and LF.
 */
std::string ltrim(const std::string &);

/**
 * Trims whitespace from the right of a string.
 * Whitespace is defined as space, tab, CR and LF.
 */
std::string rtrim(const std::string &);

/**
 * Trims whitespace from both sides of a string.
 * Whitespace is defined as space, tab, CR and LF.
 */
std::string trim(const std::string &);

/**
 * Split a string in to a vector with a specified delimiter
 */
std::vector<std::string> explode(char delimiter, std::string);

/**
 * Alternate name for variant.
 */
typedef variant var;

/**
 * Parse a string time period to a number
 * @param timestr amount of time in a human readable format (eg. 2h30m)
 * @return number of seconds
 */
double tdparse(std::string timestr);

int to_int(const std::string &);

std::string to_string(int);

void lowercase(std::string &);

void uppercase(std::string &);

void ucfirst(std::string &);

int rand(int min, int max);

}

#endif // UTIL_HPP_INCLUDED

I am calling my config::config class in my reference.h and clientdata.h reference.h

//All my headers....
extern Config client_config;
clientdata.h

//all my headers
Config client_config;
It's telling me that my refernece call is not determined..I can't figure it out any help would be nice :D
Advertisement
Allow me to make this crystal clear: When you have code that produces compiler errors, post the code (which, to be fair, you have done), and copy and paste the actual errors.

Until the errors arrive, I'll take a wild stab and say that you need to read this.
C:\Documents and Settings\Dev\Desktop\Ergo\Client\clienttest\reference.h|7|undefined reference to `Config::Config()'|

As I stated in the above post(I think I posted it anyway if not my bad :P)
It sounds like you never defined the Config default constructor.
Quote:Original post by ARC inc
As I stated in the above post(I think I posted it anyway if not my bad :P)

You did not state it clearly. That was my point. By now, you should know that we are not psychic. We need to have both the source code and the errors most of the time.

I mean, you did include things in your post that pointed at your problem. The title "undetermined Config::Config". Unfortunately undetermined isn't a word with technical meaning in C++, probably no compiler would include that in an error message. You also wrote "It's telling me that my refernece call is not determined", which again... less than useful information.

As SiCrane already said in the thread I linked you, copying and pasting the actual error message into your original post is:

  • Less work for you

  • Easier for us


When you post the code and the errors, everyone wins.

If you fail to post one or the other, then we see threads like many you have started, where the first few replies tend to be reminders to post whatever you forgot. People have limited patience and will only do that a number of times, they expect you to be able to remember this and to do it next time.

You are only losing potential helpers by persistently showing an inability to learn from previous mistakes. Sure it may be a small, almost petty issue. But it points to a person who will not learn from their mistakes. See it from our point of view: why should we reply in this case?

This topic is closed to new replies.

Advertisement