1
0
mirror of https://github.com/Halofreak1990/XFXFramework synced 2024-12-26 13:49:34 +01:00

Added missing TypeInfos in the System namespace

Fixed spacing
Added Stopwatch class
This commit is contained in:
Tom Lint 2013-10-04 22:15:52 +02:00
parent cc43a97149
commit ca63aaa9a5
25 changed files with 339 additions and 71 deletions

View File

@ -232,7 +232,7 @@ namespace System
// Removes the element at the specified index of the List<>. // Removes the element at the specified index of the List<>.
void RemoveAt(const int index) void RemoveAt(const int index)
{ {
memcpy(&_items[index], &_items[index + 1], (size - index) * sizeof(T)): memcpy(&_items[index], &_items[index + 1], (_size - index) * sizeof(T));
_size--; _size--;
_version++; _version++;

View File

@ -7,12 +7,6 @@
#ifndef _SYSTEM_DIAGNOSTICS_DEBUG_ #ifndef _SYSTEM_DIAGNOSTICS_DEBUG_
#define _SYSTEM_DIAGNOSTICS_DEBUG_ #define _SYSTEM_DIAGNOSTICS_DEBUG_
#if _MSC_VER
#define FORMAT
#else
#define FORMAT __attribute__(format(printf, 1, 2));
#endif
namespace System namespace System
{ {
class String; class String;
@ -54,7 +48,7 @@ namespace System
* @param args * @param args
* An object array containing zero or more objects to format. * An object array containing zero or more objects to format.
*/ */
static void WriteLine(const String& format, ...) FORMAT; static void WriteLine(const String& format, ...);
}; };
} }
} }

View File

@ -0,0 +1,42 @@
#ifndef _SYSTEM_DIAGNOSTICS_STOPWATCH_
#define _SYSTEM_DIAGNOSTICS_STOPWATCH_
#include <System/TimeSpan.h>
namespace System
{
namespace Diagnostics
{
/**
*
*/
class Stopwatch
{
private:
bool isRunning;
long long elapsedTicks;
public:
static const long long Frequency;
TimeSpan getElapsed() const;
/**
* Gets the total elapsed time measured by the current instance, in milliseconds.
*/
long long getElapsedMilliseconds() const;
long long getElapsedTicks() const;
bool IsRunning() const;
Stopwatch();
static long long GetTimestamp();
void Reset();
void Restart();
void Start();
static const Stopwatch& StartNew();
void Stop();
};
}
}
#endif //_SYSTEM_DIAGNOSTICS_STOPWATCH_

View File

@ -1,8 +1,8 @@
/***************************************************************************** /*****************************************************************************
* DirectoryInfo.h * * DirectoryInfo.h *
* * * *
* XFX System::IO::DirectoryInfo class definition file * * XFX System::IO::DirectoryInfo class definition file. *
* Copyright (c) XFX Team. All Rights Reserved * * Copyright (c) XFX Team. All Rights Reserved. *
*****************************************************************************/ *****************************************************************************/
#ifndef _SYSTEM_IO_DIRECTORYINFO_ #ifndef _SYSTEM_IO_DIRECTORYINFO_
#define _SYSTEM_IO_DIRECTORYINFO_ #define _SYSTEM_IO_DIRECTORYINFO_
@ -30,20 +30,28 @@ namespace System
public: public:
bool Exists() const; bool Exists() const;
String getName() const; String getName() const;
DirectoryInfo Parent(); DirectoryInfo* getParent() const;
DirectoryInfo Root(); DirectoryInfo* getRoot() const;
DirectoryInfo(); DirectoryInfo();
DirectoryInfo(const String& path); // Initializes a new instance of the System::IO::DirectoryInfo class on the specified path. DirectoryInfo(const String& path); // Initializes a new instance of the System::IO::DirectoryInfo class on the specified path.
// Creates a directory. /**
* Creates a directory.
*/
void Create(); void Create();
// Creates a subdirectory or subdirectories on the specified path. /**
// The specified path can be relative to this instance of the System::IO::DirectoryInfo class. * Creates a subdirectory or subdirectories on the specified path.
* The specified path can be relative to this instance of the System::IO::DirectoryInfo class.
*/
DirectoryInfo CreateSubDirectory(const String& path); DirectoryInfo CreateSubDirectory(const String& path);
// Deletes this System::IO::DirectoryInfo if it is empty. /**
* Deletes this System::IO::DirectoryInfo if it is empty.
*/
void Delete(); void Delete();
// Deletes this instance of a System::IO::DirectoryInfo, specifying whether to delete subdirectories and files. /**
* Deletes this instance of a System::IO::DirectoryInfo, specifying whether to delete subdirectories and files.
*/
void Delete(const bool recursive); void Delete(const bool recursive);
DirectoryInfo* GetDirectories(); // DirectoryInfo* GetDirectories(); //
DirectoryInfo* GetDirectories(const String& searchPattern); DirectoryInfo* GetDirectories(const String& searchPattern);

View File

@ -13,7 +13,7 @@
* Differences from C++ auto_ptr: exception-less and supports array notation. * Differences from C++ auto_ptr: exception-less and supports array notation.
*/ */
template <typename T> template <typename T>
class auto_ptr struct auto_ptr
{ {
private: private:
T* ptr; T* ptr;

View File

@ -28,6 +28,10 @@
#include <System/Diagnostics/Debug.h> #include <System/Diagnostics/Debug.h>
#include <System/String.h> #include <System/String.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#if ENABLE_XBOX #if ENABLE_XBOX
#include <xboxkrnl/xboxkrnl.h> #include <xboxkrnl/xboxkrnl.h>
#else #else
@ -76,7 +80,20 @@ namespace System
return; return;
} }
// TODO: implement va_list args;
va_start(args, format);
int count = vsnprintf(NULL, 0, format, args);
char* res = (char*)malloc(count + 1);
vsnprintf(res, count + 1, format, args);
va_end(args);
DbgPrint(res);
free(res);
#endif #endif
} }
} }

View File

@ -0,0 +1,68 @@
#include <System/Diagnostics/Stopwatch.h>
#if ENABLE_XBOX
#include <xboxkrnl/xboxkrnl.h>
#else
#endif
namespace System
{
namespace Diagnostics
{
const long long Stopwatch::Frequency = KeQueryPerformanceFrequency();
TimeSpan Stopwatch::getElapsed() const
{
return TimeSpan::FromTicks(elapsedTicks);
}
long long Stopwatch::getElapsedMilliseconds() const
{
return getElapsed().Milliseconds();
}
long long Stopwatch::getElapsedTicks() const
{
return elapsedTicks;
}
bool Stopwatch::IsRunning() const
{
return isRunning;
}
Stopwatch::Stopwatch()
{
}
long long Stopwatch::GetTimestamp()
{
return KeQueryPerformanceCounter();
}
void Stopwatch::Restart()
{
Reset();
Start();
}
void Stopwatch::Start()
{
isRunning = true;
}
const Stopwatch& Stopwatch::StartNew()
{
Stopwatch sw = Stopwatch();
sw.Start();
return sw;
}
void Stopwatch::Stop()
{
isRunning = false;
}
}
}

View File

@ -77,6 +77,7 @@
<ClCompile Include="Socket.cpp" /> <ClCompile Include="Socket.cpp" />
<ClCompile Include="SocketAsyncEventArgs.cpp" /> <ClCompile Include="SocketAsyncEventArgs.cpp" />
<ClCompile Include="CancelEventArgs.cpp" /> <ClCompile Include="CancelEventArgs.cpp" />
<ClCompile Include="Stopwatch.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\include\System\ComponentModel\CancelEventArgs.h" /> <ClInclude Include="..\..\include\System\ComponentModel\CancelEventArgs.h" />

View File

@ -54,6 +54,9 @@
<ClCompile Include="Debug.cpp"> <ClCompile Include="Debug.cpp">
<Filter>Source Files\Diagnostics</Filter> <Filter>Source Files\Diagnostics</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Stopwatch.cpp">
<Filter>Source Files\Diagnostics</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\include\System\ComponentModel\CancelEventArgs.h"> <ClInclude Include="..\..\include\System\ComponentModel\CancelEventArgs.h">

View File

@ -26,7 +26,7 @@ LD_FLAGS = $(CLINK) $(ALIGN) $(SHARED) $(ENTRYPOINT) $(STRIP)
LD_DIRS = -L$(PREFIX)/i386-pc-xbox/lib -L$(PREFIX)/lib LD_DIRS = -L$(PREFIX)/i386-pc-xbox/lib -L$(PREFIX)/lib
LD_LIBS = $(LD_DIRS) -lmscorlib -lm -lopenxdk -lhal -lc -lusb -lc -lxboxkrnl -lc -lhal -lxboxkrnl -lhal -lopenxdk -lc -lgcc -lstdc++ LD_LIBS = $(LD_DIRS) -lmscorlib -lm -lopenxdk -lhal -lc -lusb -lc -lxboxkrnl -lc -lhal -lxboxkrnl -lhal -lopenxdk -lc -lgcc -lstdc++
OBJS = CancelEventArgs.o Debug.o Socket.o SocketAddress.o SocketAsyncEventArgs.o OBJS = CancelEventArgs.o Debug.o Socket.o SocketAddress.o SocketAsyncEventArgs.o Stopwatch.o
all: libSystem.a all: libSystem.a

View File

@ -27,11 +27,14 @@
#include <System/DateTime.h> #include <System/DateTime.h>
#include <System/Globalization/Calendar.h> #include <System/Globalization/Calendar.h>
#include <System/Type.h>
namespace System namespace System
{ {
namespace Globalization namespace Globalization
{ {
const Type CalendarTypeInfo("Calendar", "System::Globalization::Calendar", TypeCode::Object);
DateTime Calendar::AddDays(DateTime time, int days) DateTime Calendar::AddDays(DateTime time, int days)
{ {
DateTime result(time); DateTime result(time);
@ -67,9 +70,9 @@ namespace System
return result; return result;
} }
int Calendar::GetType() const Type& Calendar::GetType()
{ {
//! TODO: implement return CalendarTypeInfo;
} }
} }
} }

View File

@ -19,9 +19,13 @@ namespace System
void Console::Write(const bool value) void Console::Write(const bool value)
{ {
if (value) if (value)
{
debugPrint("true"); debugPrint("true");
}
else else
{
debugPrint("false"); debugPrint("false");
}
} }
void Console::Write(const char value) void Console::Write(const char value)
@ -41,7 +45,9 @@ namespace System
//sassert(index + count < Array::Length(value), "index + count are out of range of the array."); //sassert(index + count < Array::Length(value), "index + count are out of range of the array.");
for (int i = index; i < (index + count); i++) for (int i = index; i < (index + count); i++)
{
debugPrint("%c", value[i]); debugPrint("%c", value[i]);
}
} }
void Console::Write(const double value) void Console::Write(const double value)

View File

@ -92,15 +92,15 @@ namespace System
DateTime DateTime::Add(double value, int scale) DateTime DateTime::Add(double value, int scale)
{ {
long long num = (long long)((value * scale) + ((value >= 0.0) ? 0.5 : -0.5)); long long num = (long long)((value * scale) + ((value >= 0.0) ? 0.5 : -0.5));
if ((num <= -315537897600000LL) || (num >= 0x11efae44cb400LL)) if ((num <= -315537897600000LL) || (num >= 0x11efae44cb400LL))
{ {
#if DEBUG #if DEBUG
//throw ArgumentOutOfRangeException("value", "ArgumentOutOfRange_AddValue"); //throw ArgumentOutOfRangeException("value", "ArgumentOutOfRange_AddValue");
#endif #endif
return *this; return *this;
} }
return AddTicks(num * 0x2710L); return AddTicks(num * 0x2710L);
} }
DateTime::DateTime(int year, int month, int day) DateTime::DateTime(int year, int month, int day)

View File

@ -41,6 +41,21 @@ namespace System
{ {
namespace IO namespace IO
{ {
DirectoryInfo* DirectoryInfo::getParent() const
{
return new DirectoryInfo(parent);
}
DirectoryInfo* DirectoryInfo::getRoot() const
{
// TODO; implement
return NULL;
}
DirectoryInfo::DirectoryInfo()
{
}
DirectoryInfo::DirectoryInfo(const String& path) DirectoryInfo::DirectoryInfo(const String& path)
{ {
sassert(path != null, FrameworkResources::ArgumentNull_Path); sassert(path != null, FrameworkResources::ArgumentNull_Path);
@ -57,11 +72,12 @@ namespace System
void DirectoryInfo::Create() void DirectoryInfo::Create()
{ {
// TODO: implement
} }
DirectoryInfo DirectoryInfo::CreateSubDirectory(const String& path) DirectoryInfo DirectoryInfo::CreateSubDirectory(const String& path)
{ {
// TODO: implement
} }
void DirectoryInfo::Delete() void DirectoryInfo::Delete()
@ -92,14 +108,12 @@ namespace System
bool DirectoryInfo::operator !=(const DirectoryInfo& right) const bool DirectoryInfo::operator !=(const DirectoryInfo& right) const
{ {
return ((strncmp(current, right.current, strlen(current)) != 0) || return (current != right.current) || (parent != right.parent);
(strncmp(parent, right.parent, strlen(parent)) != 0));
} }
bool DirectoryInfo::operator ==(const DirectoryInfo& right) const bool DirectoryInfo::operator ==(const DirectoryInfo& right) const
{ {
return ((strncmp(current, right.current, strlen(current)) == 0) && return (current == right.current) && (parent == right.parent);
(strncmp(parent, right.parent, strlen(parent)) == 0));
} }
} }
} }

View File

@ -35,6 +35,8 @@
#include <sassert.h> #include <sassert.h>
extern "C" int strcasecmp(const char * s1, const char * s2);
namespace System namespace System
{ {
static unsigned long long rawNaND = 0x7ff8000000000000ULL; static unsigned long long rawNaND = 0x7ff8000000000000ULL;
@ -63,9 +65,15 @@ namespace System
int Double::CompareTo(const Double other) const int Double::CompareTo(const Double other) const
{ {
if (value > other.value) if (value > other.value)
{
return 1; return 1;
}
if (value < other.value) if (value < other.value)
{
return -1; return -1;
}
return 0; return 0;
} }
@ -92,22 +100,32 @@ namespace System
*result = 0; *result = 0;
char sign = 0; char sign = 0;
char *sp = const_cast<char*>((const char *)str.ToString()); char* sp = const_cast<char *>((const char *)str.ToString());
if (*sp == '+' || *sp == '-') if (*sp == '+' || *sp == '-')
{
sign = *sp++; sign = *sp++;
}
if (strcasecmp(sp, "inf") == 0) if (strcasecmp(sp, "inf") == 0)
{ {
if (!sign || sign == '+') if (!sign || sign == '+')
{
*result = PositiveInfinity; *result = PositiveInfinity;
}
else else
{
*result = NegativeInfinity; *result = NegativeInfinity;
}
} }
else if (strcasecmp(sp, "nan") == 0) else if (strcasecmp(sp, "nan") == 0)
{
*result = NaN; *result = NaN;
}
else /* valid number */ else /* valid number */
{
*result = atof(sp); *result = atof(sp);
}
return true; return true;
} }

View File

@ -110,17 +110,17 @@ namespace System
} }
FileStream::FileStream() FileStream::FileStream()
: handle(NULL), _file(NULL) : _file(NULL), handle(NULL)
{ {
} }
FileStream::FileStream(FILE * const file) FileStream::FileStream(FILE * const file)
: handle(NULL), _file(file) : _file(file), handle(NULL)
{ {
} }
FileStream::FileStream(const String& path, const FileMode_t mode) FileStream::FileStream(const String& path, const FileMode_t mode)
: handle(NULL), _file(NULL) : _file(NULL), handle(NULL)
{ {
sassert(!String::IsNullOrEmpty(path), FrameworkResources::ArgumentNull_Path); sassert(!String::IsNullOrEmpty(path), FrameworkResources::ArgumentNull_Path);

View File

@ -98,12 +98,16 @@ namespace System
char* end = NULL; char* end = NULL;
if (String::IsNullOrEmpty(str)) if (String::IsNullOrEmpty(str))
{
return false; return false;
}
long long retval = strtoll(str, &end, 10); long long retval = strtoll(str, &end, 10);
if (end) if (end)
{
return false; return false;
}
*result = retval; *result = retval;
return true; return true;

View File

@ -27,6 +27,7 @@
#include <System/FrameworkResources.h> #include <System/FrameworkResources.h>
#include <System/String.h> #include <System/String.h>
#include <System/Type.h>
#include <ctype.h> #include <ctype.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
@ -39,6 +40,8 @@ namespace System
{ {
const String String::Empty = ""; const String String::Empty = "";
const Type StringTypeInfo("String", "System::String", TypeCode::String);
String::String() String::String()
: Length(0) : Length(0)
{ {
@ -92,7 +95,9 @@ namespace System
String::~String() String::~String()
{ {
if (internalString) if (internalString)
{
free(internalString); free(internalString);
}
} }
String String::Clone() const String String::Clone() const
@ -107,7 +112,7 @@ namespace System
int String::CompareTo(const String other) const int String::CompareTo(const String other) const
{ {
return (Compare(*this, other)); return strcmp(this->internalString, other.internalString);
} }
String String::Concat(const String values[], const int stringCount) String String::Concat(const String values[], const int stringCount)
@ -165,6 +170,8 @@ namespace System
vsnprintf(res, count + 1, format, args); vsnprintf(res, count + 1, format, args);
va_end(args);
return res; return res;
} }
@ -180,9 +187,9 @@ namespace System
return h; return h;
} }
int String::GetType() const Type& String::GetType()
{ {
return 18; return StringTypeInfo;
} }
int String::IndexOf(char value) const int String::IndexOf(char value) const
@ -190,8 +197,11 @@ namespace System
for(int i = 0; i <= Length; i++) for(int i = 0; i <= Length; i++)
{ {
if (internalString[i] == value) if (internalString[i] == value)
{
return i; return i;
}
} }
return -1; return -1;
} }
@ -210,8 +220,11 @@ namespace System
for(int i = startIndex; i < startIndex + count; i++) for(int i = startIndex; i < startIndex + count; i++)
{ {
if(internalString[i] == value) if(internalString[i] == value)
{
return i; return i;
}
} }
return -1; return -1;
} }
@ -233,7 +246,9 @@ namespace System
{ {
indexOf = IndexOf(anyOf[i], startIndex, count); indexOf = IndexOf(anyOf[i], startIndex, count);
if (indexOf != -1) if (indexOf != -1)
{
return indexOf; return indexOf;
}
} }
return indexOf; return indexOf;
@ -279,7 +294,9 @@ namespace System
String String::PadRight(int totalWidth, char paddingChar) String String::PadRight(int totalWidth, char paddingChar)
{ {
if(totalWidth <= Length) if(totalWidth <= Length)
return String(*this); {
return *this;
}
char* newString = (char*)malloc(totalWidth + 1); char* newString = (char*)malloc(totalWidth + 1);
@ -369,7 +386,9 @@ namespace System
String newString = String(*this); String newString = String(*this);
for (int i = 0; i < Length; i++) for (int i = 0; i < Length; i++)
{
newString.internalString[i] = tolower(internalString[i]); newString.internalString[i] = tolower(internalString[i]);
}
return newString; return newString;
} }
@ -379,13 +398,15 @@ namespace System
size_t strLen = strlen(str); size_t strLen = strlen(str);
char* tmp = (char*)malloc(strLen + 1); char* tmp = (char*)malloc(strLen + 1);
for (size_t i = 0; i < strLen; i++) for (size_t i = 0; i < strLen; i++)
{
tmp[i] = tolower(str[i]); tmp[i] = tolower(str[i]);
}
tmp[strLen] = '\0'; tmp[strLen] = '\0';
return tmp; return tmp;
} }
const String& String::ToString() const const String String::ToString() const
{ {
return *this; return *this;
} }
@ -395,7 +416,9 @@ namespace System
String newString = String(*this); String newString = String(*this);
for (int i = 0; i < Length; i++) for (int i = 0; i < Length; i++)
{
newString.internalString[i] = toupper(internalString[i]); newString.internalString[i] = toupper(internalString[i]);
}
return newString; return newString;
} }
@ -404,8 +427,11 @@ namespace System
{ {
size_t strLen = strlen(str); size_t strLen = strlen(str);
char* tmp = (char*)malloc(strLen + 1); char* tmp = (char*)malloc(strLen + 1);
for (size_t i = 0; i < strLen; i++) for (size_t i = 0; i < strLen; i++)
{
tmp[i] = toupper(str[i]); tmp[i] = toupper(str[i]);
}
tmp[strLen] = '\0'; tmp[strLen] = '\0';
return tmp; return tmp;
@ -422,6 +448,7 @@ namespace System
{ {
return !Equals(right); return !Equals(right);
} }
return true; return true;
} }
@ -431,6 +458,7 @@ namespace System
{ {
return (strncmp(internalString, right, Length) != 0); return (strncmp(internalString, right, Length) != 0);
} }
return false; return false;
} }
@ -449,6 +477,7 @@ namespace System
{ {
return (strncmp(internalString, right, Length) == 0); return (strncmp(internalString, right, Length) == 0);
} }
return false; return false;
} }
@ -456,15 +485,11 @@ namespace System
{ {
// check for self-assignment // check for self-assignment
if (*this == right) if (*this == right)
{
return *this; return *this;
}
*(const_cast<int*>(&Length)) = right.Length; return String(right);
free(internalString);
internalString = (char*)malloc(Length + 1);
strncpy(internalString, right.internalString, Length);
internalString[Length] = '\0';
return *this;
} }
String String::operator +(const char *right) const String String::operator +(const char *right) const

View File

@ -27,6 +27,7 @@
#include <System/String.h> #include <System/String.h>
#include <System/TimeSpan.h> #include <System/TimeSpan.h>
#include <System/Type.h>
#include <sassert.h> #include <sassert.h>
@ -41,6 +42,8 @@ namespace System
const long long TimeSpan::TicksPerHour = 36000000000LL; const long long TimeSpan::TicksPerHour = 36000000000LL;
const long long TimeSpan::TicksPerDay = 864000000000LL; const long long TimeSpan::TicksPerDay = 864000000000LL;
const Type TimeSpanTypeInfo("TimeSpan", "System::TimeSpan", TypeCode::Object);
TimeSpan::TimeSpan() TimeSpan::TimeSpan()
{ {
_ticks = 0; _ticks = 0;
@ -141,9 +144,15 @@ namespace System
int TimeSpan::Compare(const TimeSpan t1, const TimeSpan t2) int TimeSpan::Compare(const TimeSpan t1, const TimeSpan t2)
{ {
if (t1._ticks < t2._ticks) if (t1._ticks < t2._ticks)
{
return -1; return -1;
}
if (t1._ticks > t2._ticks) if (t1._ticks > t2._ticks)
{
return 1; return 1;
}
return 0; return 0;
} }
@ -202,9 +211,9 @@ namespace System
return (((int)_ticks) ^ ((int)(_ticks >> 0x20))); return (((int)_ticks) ^ ((int)(_ticks >> 0x20)));
} }
int TimeSpan::GetType() const Type& TimeSpan::GetType()
{ {
//! TODO: implement return TimeSpanTypeInfo;
} }
TimeSpan TimeSpan::Negate() TimeSpan TimeSpan::Negate()
@ -223,7 +232,7 @@ namespace System
return TimeSpan(ticks); return TimeSpan(ticks);
} }
const String& TimeSpan::ToString() const const String TimeSpan::ToString() const
{ {
return String::Format("Ticks: %ll", _ticks); return String::Format("Ticks: %ll", _ticks);
} }

View File

@ -27,6 +27,7 @@
#include <System/UInt16.h> #include <System/UInt16.h>
#include <System/String.h> #include <System/String.h>
#include <System/Type.h>
#include <stdlib.h> #include <stdlib.h>
@ -34,6 +35,7 @@ namespace System
{ {
const ushort UInt16::MaxValue = 0xFFFF; const ushort UInt16::MaxValue = 0xFFFF;
const ushort UInt16::MinValue = 0; const ushort UInt16::MinValue = 0;
const Type UInt16TypeInfo("UInt16", "System::UInt16", TypeCode::UInt16);
UInt16::UInt16() UInt16::UInt16()
: value(0) : value(0)
@ -53,9 +55,15 @@ namespace System
int UInt16::CompareTo(const UInt16 other) const int UInt16::CompareTo(const UInt16 other) const
{ {
if (value < other.value) if (value < other.value)
{
return -1; return -1;
}
if (value > other.value) if (value > other.value)
{
return 1; return 1;
}
return 0; return 0;
} }
@ -74,17 +82,17 @@ namespace System
return value; return value;
} }
int UInt16::GetType() const Type& UInt16::GetType()
{ {
return 8; return UInt16TypeInfo;
} }
const String& UInt16::ToString() const const String UInt16::ToString() const
{ {
return String::Format("%i", value); return String::Format("%i", value);
} }
const String& UInt16::ToString(const ushort value) const String UInt16::ToString(const ushort value)
{ {
return String::Format("%i", value); return String::Format("%i", value);
} }
@ -95,12 +103,16 @@ namespace System
char* end = NULL; char* end = NULL;
if (String::IsNullOrEmpty(str)) if (String::IsNullOrEmpty(str))
{
return false; return false;
}
ushort retval = (ushort)strtoul(str, &end, 10); ushort retval = (ushort)strtoul(str, &end, 10);
if (end) if (end)
{
return false; return false;
}
*result = retval; *result = retval;
return true; return true;

View File

@ -27,6 +27,7 @@
#include <System/UInt32.h> #include <System/UInt32.h>
#include <System/String.h> #include <System/String.h>
#include <System/Type.h>
#include <stdlib.h> #include <stdlib.h>
@ -34,6 +35,7 @@ namespace System
{ {
const uint UInt32::MaxValue = 0xFFFFFFFF; const uint UInt32::MaxValue = 0xFFFFFFFF;
const uint UInt32::MinValue = 0; const uint UInt32::MinValue = 0;
const Type UInt32TypeInfo("UInt32", "System::UInt32", TypeCode::UInt32);
UInt32::UInt32(const UInt32 &obj) UInt32::UInt32(const UInt32 &obj)
: value(obj.value) : value(obj.value)
@ -69,17 +71,17 @@ namespace System
return (int)value; return (int)value;
} }
int UInt32::GetType() const Type& UInt32::GetType()
{ {
return 10; return UInt32TypeInfo;
} }
const String& UInt32::ToString() const const String UInt32::ToString() const
{ {
return String::Format("%i", value); return String::Format("%i", value);
} }
const String& UInt32::ToString(const uint value) const String UInt32::ToString(const uint value)
{ {
return String::Format("%i", value); return String::Format("%i", value);
} }
@ -90,12 +92,16 @@ namespace System
char* end = NULL; char* end = NULL;
if (String::IsNullOrEmpty(str)) if (String::IsNullOrEmpty(str))
{
return false; return false;
}
uint retval = strtoul(str, &end, 10); uint retval = strtoul(str, &end, 10);
if (*end) if (*end)
{
return false; return false;
}
*result = retval; *result = retval;
return true; return true;

View File

@ -27,6 +27,7 @@
#include <System/UInt64.h> #include <System/UInt64.h>
#include <System/String.h> #include <System/String.h>
#include <System/Type.h>
#include <stdlib.h> #include <stdlib.h>
@ -34,6 +35,7 @@ namespace System
{ {
const ulong UInt64::MaxValue = 0xFFFFFFFFFFFFFFFFULL; const ulong UInt64::MaxValue = 0xFFFFFFFFFFFFFFFFULL;
const ulong UInt64::MinValue = 0; const ulong UInt64::MinValue = 0;
const Type UInt64TypeInfo("UInt64", "System::UInt64", TypeCode::UInt64);
UInt64::UInt64(const UInt64 &obj) UInt64::UInt64(const UInt64 &obj)
: value(obj.value) : value(obj.value)
@ -48,9 +50,15 @@ namespace System
int UInt64::CompareTo(const UInt64 other) const int UInt64::CompareTo(const UInt64 other) const
{ {
if (value > other.value) if (value > other.value)
{
return 1; return 1;
}
if (value < other.value) if (value < other.value)
{
return -1; return -1;
}
return 0; return 0;
} }
@ -69,9 +77,9 @@ namespace System
return (int)value; return (int)value;
} }
int UInt64::GetType() const Type& UInt64::GetType()
{ {
return 12; return UInt64TypeInfo;
} }
const String UInt64::ToString() const const String UInt64::ToString() const
@ -90,12 +98,16 @@ namespace System
char* end = NULL; char* end = NULL;
if (String::IsNullOrEmpty(str)) if (String::IsNullOrEmpty(str))
{
return false; return false;
}
ulong retval = strtoull(str, &end, 10); ulong retval = strtoull(str, &end, 10);
if (end) if (end)
{
return false; return false;
}
*result = retval; *result = retval;
return true; return true;

View File

@ -26,12 +26,15 @@
// POSSIBILITY OF SUCH DAMAGE. // POSSIBILITY OF SUCH DAMAGE.
#include <System/String.h> #include <System/String.h>
#include <System/Type.h>
#include <System/Version.h> #include <System/Version.h>
#include <sassert.h> #include <sassert.h>
namespace System namespace System
{ {
const Type VersionTypeInfo("Version", "System::Version", TypeCode::Object);
Version::Version(int major, int minor) Version::Version(int major, int minor)
: Build(0), Major(major), Minor(minor), Revision(0) : Build(0), Major(major), Minor(minor), Revision(0)
{ {
@ -60,9 +63,15 @@ namespace System
int Version::CompareTo(const Version value) const int Version::CompareTo(const Version value) const
{ {
if (*this < value) if (*this < value)
{
return -1; return -1;
}
if (*this > value) if (*this > value)
{
return 1; return 1;
}
return 0; return 0;
} }
@ -82,22 +91,22 @@ namespace System
return (Build ^ Major ^ Minor ^ Revision); return (Build ^ Major ^ Minor ^ Revision);
} }
int Version::GetType() const Type& Version::GetType()
{ {
// TODO: implement return VersionTypeInfo;
} }
const String& Version::ToString() const const String Version::ToString() const
{ {
return String::Format("%i.%i.%i.%i", Major, Minor, Build, Revision); return String::Format("%i.%i.%i.%i", Major, Minor, Build, Revision);
} }
const String& Version::ToString(int fieldCount) const const String Version::ToString(int fieldCount) const
{ {
switch(fieldCount) switch(fieldCount)
{ {
case 0: case 0:
return ""; return String::Empty;
break; break;
case 1: case 1:
return String::Format("%i", Major); return String::Format("%i", Major);

View File

@ -4,15 +4,15 @@
######################################################################### #########################################################################
PREFIX = /openxdk PREFIX = /openxdk
CC = xbox-gcc CC = gcc
CCAS = xbox-gcc CCAS = gcc
CPP = xbox-g++ CPP = g++
AR = xbox-ar rcu AR = ar rcu
RANLIB = xbox-ranlib RANLIB = ranlib
CXBE = $(PREFIX)/bin/cxbe CXBE = $(PREFIX)/bin/cxbe
SDLFLAGS = -DENABLE_XBOX -DDEBUG SDLFLAGS = -DENABLE_XBOX -DDEBUG
CC_FLAGS = -c -g -O2 -std=gnu99 -ffreestanding -nostdlib -fno-builtin -fno-exceptions -march=i686 -mmmx -msse -mfpmath=sse $(SDLFLAGS) CC_FLAGS = -c -g -O2 -std=C99 -ffreestanding -nostdlib -fno-builtin -fno-exceptions -march=i686 -mmmx -msse -mfpmath=sse $(SDLFLAGS)
CCAS_FLAGS = --32 -march=pentiumiii, mmx, sse -mtune=pentiumiii -msse-check=error CCAS_FLAGS = --32 -march=pentiumiii, mmx, sse -mtune=pentiumiii -msse-check=error
CPP_FLAGS = -c -O2 -std=c++03 -Wall -nostdlib -fno-builtin -fno-exceptions -fno-rtti -march=i686 -mmmx -msse -mfpmath=sse $(SDLFLAGS) CPP_FLAGS = -c -O2 -std=c++03 -Wall -nostdlib -fno-builtin -fno-exceptions -fno-rtti -march=i686 -mmmx -msse -mfpmath=sse $(SDLFLAGS)
INCLUDE = -I$(PREFIX)/i386-pc-xbox/include -I$(PREFIX)/include -I$(PREFIX)/include/SDL -I../../include INCLUDE = -I$(PREFIX)/i386-pc-xbox/include -I$(PREFIX)/include -I$(PREFIX)/include/SDL -I../../include

View File

@ -8,6 +8,7 @@
#include <System/misc.h> #include <System/misc.h>
#include <xboxkrnl/xboxkrnl.h> #include <xboxkrnl/xboxkrnl.h>
#include <ctype.h>
/******************************************************************************/ /******************************************************************************/
@ -135,3 +136,19 @@ void *memset(void *s, char c, size_t count)
:"memory"); :"memory");
return s; return s;
} }
int strcasecmp(const char * s1, const char * s2)
{
const unsigned char *us1 = (const unsigned char *)s1,
*us2 = (const unsigned char *)s2;
while (tolower(*us1) == tolower(*us2++))
{
if (*us1++ == '\0')
{
return (0);
}
}
return (tolower(*us1) - tolower(*--us2));
}