start 380 project5

changes to 380 project 4
changes to 350 project 2

Signed-off-by: Amrit Panesar <apanesar@4195tech.com>
This commit is contained in:
Amrit Panesar committed 2015-05-06 10:18:39 -07:00
1 parent 40ac78074b
commit 39ee821f54
174 files changed
+13356 -80

No files matched your search

@@ -0,0 +1,110 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma once
#include "..\GkDefinitions.h"
#include "..\OSSpecific\GkOSUtils.h"
template <class GKDLLCLASS T> class GKDLLCLASS GkList
{
public:
static const int ListIndex_NotFound = -1;
int size, capacity;
T *values;
T& operator [](int index)
{
return this->values[index];
};
GkList::GkList(int capacity = 8)
{
this->capacity = 0;
this->size = 0;
this->values = 0;
this->Resize(capacity);
};
GkList::~GkList(void)
{
delete this->values;
};
void GkList::Resize(int newCapacity)
{
T *newValues = new T[newCapacity];
if (this->size > 0)
GkOSUtils::CopyMem(newValues, values, this->size * sizeof(T));
if (this->values != 0)
delete this->values;
this->values = newValues;
this->capacity = newCapacity;
};
T GkList::Add(T value)
{
if (this->size >= this->capacity)
this->Resize(this->capacity * 2);
this->values[this->size++] = value;
return value;
};
T GkList::Insert(T value, int index)
{
if (this->size >= this->capacity)
this->Resize(this->capacity * 2);
for (int i = this->size; i > index; i--)
this->values[i] = this->values[i - 1];
this->values[index] = value;
this->size++;
};
bool GkList::Remove(T value)
{
int index = this->IndexOf(value);
if (index != GkList::ListIndex_NotFound)
{
this->RemoveIndex(index);
return true;
}
return false;
};
void GkList::RemoveIndex(int index)
{
for (int i = index; i < this->size -1; i++)
this[i] = this[i + 1];
this->size--;
};
int GkList::IndexOf(T value)
{
for (int i = 0; i < this->size; i++)
if (this->values[i] == value)
return i;
return GkList::ListIndex_NotFound;
};
};
@@ -0,0 +1,71 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma once
#include "..\GkDefinitions.h"
#include "GkStrings.h"
#include <fstream>
template <class GKDLLCLASS T> class GKDLLCLASS GkLogFile
{
public:
wchar_t *fileName;
int numRecords;
GkLogFile(const wchar_t *fileName)
{
this->fileName = GkStrings::Copy(fileName);
std::fstream file(this->fileName, std::ios::in | std::ios::out | std::ios::binary | std::ios::ate);
this->numRecords = (int)file.tellp() / (int)sizeof(T);
file.close();
};
~GkLogFile(void)
{
if (this->fileName != 0)
delete[] this->fileName;
};
void Write(T &record)
{
std::fstream file(this->fileName, std::ios::in | std::ios::out | std::ios::binary | std::ios::ate);
file.write((char*)&record, sizeof(T));
file.close();
this->numRecords++;
};
bool Read(int recordIndex, T &record)
{
if (recordIndex >= this->numRecords)
return false;
std::fstream file(this->fileName, std::ios::in | std::ios::binary);
file.seekg(recordIndex * sizeof(T));
file.read((char*)&record, sizeof(T));
file.close();
return true;
};
void Clear()
{
std::fstream file(this->fileName, std::ios::out | std::ios::trunc);
file.close();
this->numRecords = 0;
};
};
@@ -0,0 +1,92 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkMaths.h"
#include <stdlib.h>
#include <time.h>
#include <cmath>
GkMaths::GkMaths(void)
{
}
GkMaths::~GkMaths(void)
{
}
int GkMaths::Min(int a, int b)
{
if (a < b)
return a;
return b;
}
int GkMaths::Max(int a, int b)
{
if (a > b)
return a;
return b;
}
float GkMaths::Max(float a, float b)
{
if (a > b)
return a;
return b;
}
int GkMaths::Trim(int x, int min, int max)
{
if (x < min)
return min;
if (x > max)
return max;
return x;
}
int GkMaths::Sign(int x)
{
return x > 0 ? 1 : x < 0 ? -1 : 0;
}
float GkMaths::Sign(float x)
{
return x > 0 ? 1.0f : x < 0 ? -1.0f : 0.0f;
}
float GkMaths::Abs(float x)
{
return x >= 0 ? x : -x;
}
int GkMaths::Abs(int x)
{
return x >= 0 ? x : -x;
}
int GkMaths::Random(int range)
{
return rand() % range;
}
void GkMaths::Randomize()
{
srand((unsigned int)time(NULL));
}
@@ -0,0 +1,23 @@
#pragma once
#include "..\GkDefinitions.h"
class GKDLLCLASS GkMaths
{
public:
GkMaths(void);
~GkMaths(void);
static int GkMaths::Trim(int x, int min, int max);
static int GkMaths::Min(int a, int b);
static int GkMaths::Max(int a, int b);
static float GkMaths::Max(float a, float b);
static int GkMaths::Sign(int x);
static float GkMaths::Sign(float x);
static float GkMaths::Abs(float x);
static int GkMaths::Abs(int x);
static int GkMaths::Random(int n);
static void GkMaths::Randomize();
};
@@ -0,0 +1,283 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkStrings.h"
#include <vector>
#include "..\OSSpecific\GkOSUtils.h"
GkStrings::GkStrings(void)
{
}
GkStrings::~GkStrings(void)
{
}
struct FormatStringChunk
{
bool isFormatter;
int start, length;
};
struct FormatStringChunks
{
std::vector<FormatStringChunk> chunks;
int numFormatterChunks;
};
FormatStringChunks GetFormatStringChunks(const wchar_t *formatString)
{
FormatStringChunks result;
result.numFormatterChunks = 0;
FormatStringChunk chunk;
chunk.isFormatter = false;
chunk.start = 0;
for (int i = 0; ; i++)
{
if (formatString[i] == L'{')
{
chunk.length = i - chunk.start;
if (chunk.length > 0)
result.chunks.push_back(chunk);
chunk.isFormatter = true;
chunk.start = i + 1;
}
else if (formatString[i] == L'}')
{
chunk.length = i - chunk.start;
if (chunk.length > 0)
{
result.chunks.push_back(chunk);
if (chunk.isFormatter)
result.numFormatterChunks++;
}
chunk.isFormatter = false;
chunk.start = i + 1;
}
else if (formatString[i] == 0)
{
chunk.length = i - chunk.start;
if (chunk.length > 0)
result.chunks.push_back(chunk);
break;
}
}
return result;
}
std::wstring GkStrings::Format(const wchar_t *formatString, ...)
{
wchar_t **parameters = (wchar_t**)((int)&formatString + 4);
return GkStrings::FormatArray(formatString, parameters);
}
std::wstring GkStrings::FormatArray(const wchar_t *formatString, wchar_t **parameters)
{
FormatStringChunks chunks = GetFormatStringChunks(formatString);
std::wstring result;
int numChunks = chunks.chunks.size();
for (int i = 0; i < numChunks; i++)
{
FormatStringChunk chunk = chunks.chunks[i];
if (chunk.isFormatter)
{
result.append(parameters[GkStrings::StringToInt(std::wstring(&formatString[chunk.start], chunk.length).c_str())]);
}
else
{
result.append(std::wstring(&formatString[chunk.start], chunk.length));
}
}
return result;
}
std::wstring GkStrings::IntToString(int value, int base, int digits, const wchar_t defaultDigit)
{
wchar_t s[256], result[256];
_itow_s(value, s, base);
int intLength = wcslen(s);
int extraDigits = digits > intLength ? digits - intLength : 0;
int resultLength = extraDigits > 0 ? digits : intLength;
for (int i = 0; i < resultLength; i++)
{
if (i < extraDigits)
result[i] = defaultDigit;
else
result[i] = s[i - extraDigits];
}
result[resultLength] = L'\0';
return std::wstring(result);
}
std::wstring GkStrings::FloatToString(float value, int fracDigits, int intDigits, const wchar_t defaultDigit)
{
int intPart = (int)value;
int fracPart = (int)((value - intPart) * pow(10.0f, fracDigits));
return GkStrings::Format(L"{0}.{1}", GkStrings::IntToString(intPart, 10, intDigits, defaultDigit).c_str(), GkStrings::IntToString(fracPart, 10, fracDigits, L'0').c_str());
}
int GkStrings::StringToInt(const wchar_t *string)
{
return _wtoi(string);
}
wchar_t *GkStrings::Copy(const wchar_t *string)
{
if (string == 0)
return 0;
int length = wcslen(string);
wchar_t *result = new wchar_t[length + 1];
memcpy(result, string, (length + 1) * 2);
return result;
}
char *GkStrings::Copy(const char *string)
{
if (string == 0)
return 0;
int length = strlen(string);
char *result = new char[length + 1];
memcpy(result, string, (length + 1));
return result;
}
void GkStrings::Dispose(wchar_t **string)
{
if (*string != 0)
{
delete[] *string;
string = 0;
}
}
int GkStrings::GetLength(const wchar_t *string)
{
return wcslen(string);
}
int GkStrings::GetLength(const char *string)
{
return strlen(string);
}
int GkStrings::SubChar(const wchar_t *string, const wchar_t subChar)
{
if (string == 0)
return -1;
for (int i = 0; *string != 0; i++)
{
if (*string++ == subChar)
{
return i;
}
}
return -1;
}
int GkStrings::Compare(const char *string1, const char *string2)
{
return strcmp(string1, string2);
}
int GkStrings::Compare(const wchar_t *string1, const wchar_t *string2)
{
return wcscmp(string1, string2);
}
std::wstring GkStrings::FormatDateTime(const wchar_t *formatString, DateTime &dateTime)
{
return std::wstring(GkStrings::Format(formatString, GkStrings::IntToString(dateTime.day, 10, 2).c_str(), GkStrings::IntToString(dateTime.month, 10, 2).c_str(), GkStrings::IntToString(dateTime.year, 10, 4).c_str(), GkStrings::IntToString(dateTime.hour, 10, 2).c_str(), GkStrings::IntToString(dateTime.minute, 10, 2).c_str(), GkStrings::IntToString(dateTime.second, 10, 2).c_str()));
}
std::wstring GkStrings::IntToDecimalString(int value, int numFractionDigits)
{
int fractionalFactor = 1;
for (int i = 0; i < numFractionDigits; i++)
fractionalFactor *= 10;
return GkStrings::Format(L"{0}.{1}", GkStrings::IntToString(value / fractionalFactor).c_str(), GkStrings::IntToString(value % fractionalFactor, 10, numFractionDigits).c_str());
}
std::wstring GkStrings::FromShort(const char *chars)
{
int length = GkStrings::GetLength(chars);
wchar_t *wide = new wchar_t[length + 1];
for (int i = 0; i < length; i++)
wide[i] = chars[i];
wide[length] = 0;
std::wstring result(wide);
delete[] wide;
return result;
}
std::wstring GkStrings::FromShort(const char *chars, int start, int length)
{
wchar_t *wide = new wchar_t[length + 1];
for (int i = 0; i < length; i++)
wide[i] = chars[start + i];
wide[length] = 0;
std::wstring result(wide);
delete[] wide;
return result;
}
std::string GkStrings::ToShort(const wchar_t *string)
{
int length = GkStrings::GetLength(string);
char *shortString = new char[length + 1];
for (int i = 0; i < length; i++)
shortString[i] = (char)string[i];
shortString[length] = 0;
std::string result(shortString);
delete[] shortString;
return result;
}
@@ -0,0 +1,35 @@
#pragma once
#include "..\GkDefinitions.h"
#include <string>
struct DateTime;
class GKDLLCLASS GkStrings
{
public:
GkStrings::GkStrings(void);
GkStrings::~GkStrings(void);
static std::wstring GkStrings::FromShort(const char *chars);
static std::wstring GkStrings::FromShort(const char *chars, int start, int length);
static std::string GkStrings::ToShort(const wchar_t *string);
static std::wstring GkStrings::Format(const wchar_t *formatString, ...);
static std::wstring GkStrings::FormatArray(const wchar_t *formatString, wchar_t **parameters);
static std::wstring GkStrings::IntToString(int value, int base = 10, int digits = 0, const wchar_t defaultDigit = L'0');
static int GkStrings::StringToInt(const wchar_t *string);
static std::wstring GkStrings::FloatToString(float value, int fracDigits, int intDigits = 0, const wchar_t defaultDigit = L'0');
static wchar_t *GkStrings::Copy(const wchar_t *string);
static char *GkStrings::Copy(const char *string);
static void GkStrings::Dispose(wchar_t **string);
static int GkStrings::GetLength(const wchar_t *string);
static int GkStrings::GetLength(const char *string);
static int GkStrings::SubChar(const wchar_t *string, const wchar_t subChar);
static int GkStrings::Compare(const char *string1, const char *string2);
static int GkStrings::Compare(const wchar_t *string1, const wchar_t *string2);
static std::wstring GkStrings::FormatDateTime(const wchar_t *formatString, DateTime &dateTime);
static std::wstring GkStrings::IntToDecimalString(int value, int numFractionDigits = 2);
};