Removed some XNA 3.1 code paths; cleaned up constant usage in platform-specific code sections

git-svn-id: file:///srv/devel/repo-conversion/nusu@211 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2010-12-24 01:02:56 +00:00
parent 645148a751
commit 46cbc920b1
16 changed files with 75 additions and 110 deletions

View File

@ -19,7 +19,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\net-4.0\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;UNITTEST</DefineConstants>
<DefineConstants>TRACE;DEBUG;UNITTEST;WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\net-4.0\Debug\Nuclex.Support.xml</DocumentationFile>
@ -28,7 +28,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\net-4.0\Release\</OutputPath>
<DefineConstants>TRACE;UNITTEST</DefineConstants>
<DefineConstants>TRACE;UNITTEST;WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\net-4.0\Release\Nuclex.Support.xml</DocumentationFile>

View File

@ -197,7 +197,7 @@ namespace Nuclex.Support {
// explicitly move it to that core. MSDN states that SetProcessorAffinity() should
// be called from the thread whose affinity is being changed.
Thread.CurrentThread.SetProcessorAffinity(new int[] { hardwareThreadIndex });
#elif !WINDOWS_PHONE
#elif WINDOWS
if(Environment.OSVersion.Platform == PlatformID.Win32NT) {
// Prevent this managed thread from impersonating another system thread.
// In .NET, managed threads can supposedly be moved to different system threads
@ -237,7 +237,7 @@ namespace Nuclex.Support {
}
}
#if !XBOX360 && !WINDOWS_PHONE
#if WINDOWS
/// <summary>Retrieves the ProcessThread for the calling thread</summary>
/// <returns>The ProcessThread for the calling thread</returns>
internal static ProcessThread GetProcessThread(int threadId) {
@ -282,7 +282,7 @@ namespace Nuclex.Support {
/// <summary>Delegate used to handle assertion checks in the code</summary>
public static volatile ExceptionDelegate ExceptionHandler = DefaultExceptionHandler;
#if !XBOX360 // Only called if platform is Win32NT
#if WINDOWS
/// <summary>Retrieves the calling thread's thread id</summary>
/// <returns>The thread is of the calling thread</returns>
[DllImport("kernel32.dll")]

View File

@ -68,7 +68,7 @@ namespace Nuclex.Support.Collections {
#if DEBUG
checkVersion();
#endif
if(this.currentBlock == null) {
if (this.currentBlock == null) {
throw new InvalidOperationException("Enumerator is not on a valid position");
}
@ -85,15 +85,15 @@ namespace Nuclex.Support.Collections {
#endif
// If we haven't reached the last block yet
if(this.currentBlockIndex < this.lastBlock) {
if (this.currentBlockIndex < this.lastBlock) {
// Advance to the next item. If the end of the current block is reached,
// go to the next block's first item
++this.subIndex;
if(this.subIndex >= this.blockSize) {
if (this.subIndex >= this.blockSize) {
++this.currentBlockIndex;
this.currentBlock = this.deque.blocks[this.currentBlockIndex];
if(this.currentBlockIndex == 0) {
if (this.currentBlockIndex == 0) {
this.subIndex = this.deque.firstBlockStartIndex;
} else {
this.subIndex = 0;
@ -107,7 +107,7 @@ namespace Nuclex.Support.Collections {
} else { // We in or beyond the last block
// Are there any items left to advance to?
if(this.subIndex < this.lastBlockEndIndex) {
if (this.subIndex < this.lastBlockEndIndex) {
++this.subIndex;
return true;
} else { // Nope, we've reached the end of the deque
@ -203,7 +203,7 @@ namespace Nuclex.Support.Collections {
/// <summary>The first item in the double-ended queue</summary>
public ItemType First {
get {
if(this.count == 0) {
if (this.count == 0) {
throw new InvalidOperationException("The deque is empty");
}
return this.blocks[0][this.firstBlockStartIndex];
@ -213,7 +213,7 @@ namespace Nuclex.Support.Collections {
/// <summary>The last item in the double-ended queue</summary>
public ItemType Last {
get {
if(this.count == 0) {
if (this.count == 0) {
throw new InvalidOperationException("The deque is empty");
}
return this.blocks[this.blocks.Count - 1][this.lastBlockEndIndex - 1];
@ -231,13 +231,13 @@ namespace Nuclex.Support.Collections {
/// <param name="array">Array the contents of the deque will be copied into</param>
/// <param name="arrayIndex">Array index the deque contents will begin at</param>
public void CopyTo(ItemType[] array, int arrayIndex) {
if(this.count > (array.Length - arrayIndex)) {
if (this.count > (array.Length - arrayIndex)) {
throw new ArgumentException(
"Array too small to hold the collection items starting at the specified index"
);
}
if(this.blocks.Count == 1) { // Does only one block exist?
if (this.blocks.Count == 1) { // Does only one block exist?
// Copy the one and only block there is
Array.Copy(
@ -259,7 +259,7 @@ namespace Nuclex.Support.Collections {
// Copy all intermediate blocks (if there are any). These are completely filled
int lastBlock = this.blocks.Count - 1;
for(int index = 1; index < lastBlock; ++index) {
for (int index = 1; index < lastBlock; ++index) {
Array.Copy(
this.blocks[index], 0,
array, arrayIndex,
@ -289,16 +289,16 @@ namespace Nuclex.Support.Collections {
/// <param name="blockIndex">Index of the block the entry is contained in</param>
/// <param name="subIndex">Local sub index of the entry within the block</param>
private void findIndex(int index, out int blockIndex, out int subIndex) {
if((index < 0) || (index >= this.count)) {
if ((index < 0) || (index >= this.count)) {
throw new ArgumentOutOfRangeException("Index out of range", "index");
}
index += this.firstBlockStartIndex;
#if XBOX360 || WINDOWS_PHONE
#if WINDOWS
blockIndex = Math.DivRem(index, this.blockSize, out subIndex);
#else
blockIndex = index / this.blockSize;
subIndex = index % this.blockSize;
#else
blockIndex = Math.DivRem(index, this.blockSize, out subIndex);
#endif
}
@ -314,7 +314,7 @@ namespace Nuclex.Support.Collections {
/// <summary>Verifies that the provided object matches the deque's type</summary>
/// <param name="value">Value that will be checked for compatibility</param>
private static void verifyCompatibleObject(object value) {
if(!isCompatibleObject(value)) {
if (!isCompatibleObject(value)) {
throw new ArgumentException("Value does not match the deque's type", "value");
}
}

View File

@ -28,8 +28,6 @@ using NUnit.Framework;
namespace Nuclex.Support.Plugins {
#if XBOX360
/// <summary>Unit Test for the assembly load event argument container</summary>
[TestFixture]
public class AssemblyLoadEventArgsTest {
@ -48,8 +46,6 @@ namespace Nuclex.Support.Plugins {
}
#endif // XBOX360
} // namespace Nuclex.Support.Plugins
#endif // UNITTEST

View File

@ -52,6 +52,6 @@ namespace Nuclex.Support.Plugins {
}
#endif // XBOX360
#endif // XBOX360 || WINDOWS_PHONE
} // namespace Nuclex.Support.Plugins

View File

@ -121,7 +121,7 @@ namespace Nuclex.Support.Plugins {
/// <summary>Reports an error to the debugging console</summary>
/// <param name="error">Error message that will be reported</param>
private static void reportError(string error) {
#if !XBOX360 && !WINDOWS_PHONE
#if WINDOWS
Trace.WriteLine(error);
#endif
}

View File

@ -66,7 +66,7 @@ namespace Nuclex.Support.Plugins {
loadedAssembly = LoadAssemblyFromFile(path);
return true;
}
#if !XBOX360
#if WINDOWS
// File not found - Most likely a missing dependency of the assembly we
// attempted to load since the assembly itself has been found by the GetFiles() method
catch(DllNotFoundException) {
@ -178,7 +178,7 @@ namespace Nuclex.Support.Plugins {
/// <summary>Reports an error to the debugging console</summary>
/// <param name="error">Error message that will be reported</param>
private static void reportError(string error) {
#if !XBOX360 && !WINDOWS_PHONE
#if WINDOWS
Trace.WriteLine(error);
#endif
}

View File

@ -92,13 +92,8 @@ namespace Nuclex.Support.Scheduling {
// Force a timeout at least each second so the caller can check the system time
// since we're not able to provide the DateTimeAdjusted notification
int milliseconds = (int)(ticks / TicksPerMillisecond);
#if XNA_3
bool signalled = waitHandle.WaitOne(Math.Min(1000, milliseconds), false);
#elif XBOX360 || WINDOWS_PHONE
bool signalled = waitHandle.WaitOne(Math.Min(1000, milliseconds));
#else
bool signalled = waitHandle.WaitOne(Math.Min(1000, milliseconds), false);
#endif
// See whether the system date/time have been adjusted while we were asleep.
checkForTimeAdjustment();

View File

@ -128,9 +128,7 @@ namespace Nuclex.Support.Scheduling {
this.timerThread = new Thread(new ThreadStart(runTimerThread));
this.timerThread.Name = "Nuclex.Support.Scheduling.Scheduler";
#if XNA_3
this.timerThread.Priority = ThreadPriority.Highest;
#elif !XBOX360 && !WINDOWS_PHONE
#if WINDOWS
this.timerThread.Priority = ThreadPriority.Highest;
#endif
this.timerThread.IsBackground = true;
@ -147,7 +145,7 @@ namespace Nuclex.Support.Scheduling {
// a lot of time given that it doesn't do any real work), forcefully abort
// the thread. This may risk some leaks, but it's the only thing we can do.
bool success = this.timerThread.Join(2500);
#if !XBOX360 && !WINDOWS_PHONE
#if WINDOWS
Trace.Assert(success, "Scheduler timer thread did not exit in time");
#endif
// Unsubscribe from the time source to avoid surprise events during or

View File

@ -20,7 +20,7 @@ License along with this library
#if UNITTEST
#if !XBOX360
#if WINDOWS
using System;
using System.Collections.Generic;
@ -159,6 +159,6 @@ namespace Nuclex.Support.Scheduling {
} // namespace Nuclex.Support.Scheduling
#endif // !XBOX360
#endif // WINDOWS
#endif // UNITTEST

View File

@ -65,13 +65,7 @@ namespace Nuclex.Support.Scheduling {
/// True if the WaitHandle was signalled, false if the timeout was reached
/// </returns>
public override bool WaitOne(AutoResetEvent waitHandle, long ticks) {
#if XNA_3
return waitHandle.WaitOne((int)(ticks / TicksPerMillisecond), false);
#elif XBOX360 || WINDOWS_PHONE
return waitHandle.WaitOne((int)(ticks / TicksPerMillisecond));
#else
return waitHandle.WaitOne((int)(ticks / TicksPerMillisecond), false);
#endif
}
/// <summary>
@ -86,7 +80,7 @@ namespace Nuclex.Support.Scheduling {
/// <summary>Delegate for the timeChanged() callback method</summary>
private EventHandler onDateTimeAdjustedDelegate;
#endif // !XBOX360
#endif // !NO_SYSTEMEVENTS
}

View File

@ -97,11 +97,7 @@ namespace Nuclex.Support {
/// </param>
protected override void Dispose(bool explicitDisposing) {
if(this.manualResetEvent != null) {
#if XBOX360 && XNA_3
base.Handle = IntPtr.Zero;
#else
base.SafeWaitHandle = null;
#endif
this.manualResetEvent.Close();
this.manualResetEvent = null;
@ -180,8 +176,6 @@ namespace Nuclex.Support {
#endif
}
#if !(XNA_3 && XBOX360)
/// <summary>
/// Waits for the resource to become available and locks it
/// </summary>
@ -215,8 +209,6 @@ namespace Nuclex.Support {
#endif
}
#endif // !(XNA_3 && XBOX360)
/// <summary>
/// Releases a lock on the resource. Note that for a reverse counting semaphore,
/// it is legal to Release() the resource before locking it.
@ -234,11 +226,7 @@ namespace Nuclex.Support {
/// <summary>Creates the event used to make threads wait for the resource</summary>
private void createEvent() {
this.manualResetEvent = new ManualResetEvent(false);
#if XBOX360 && XNA_3
base.Handle = this.manualResetEvent.Handle;
#else
base.SafeWaitHandle = this.manualResetEvent.SafeWaitHandle;
#endif
}
/// <summary>Event used to make threads wait if the semaphore is full</summary>

View File

@ -26,7 +26,7 @@ using System.Reflection;
namespace Nuclex.Support.Services {
#if !XBOX360
#if WINDOWS
/// <summary>Lists the types of all assemblies in an application domain</summary>
public class AppDomainTypeLister : MultiAssemblyTypeLister {
@ -56,7 +56,7 @@ namespace Nuclex.Support.Services {
}
#endif // !XBOX360
#endif // WINDOWS
} // namespace Nuclex.Support.Services

View File

@ -144,7 +144,7 @@ namespace Nuclex.Support.Services {
#endregion // class Contract
#if !XBOX360
#if WINDOWS
/// <summary>Initializes a new service manager</summary>
/// <remarks>
@ -154,7 +154,7 @@ namespace Nuclex.Support.Services {
/// </remarks>
public ServiceManager() : this(new AppDomainTypeLister()) { }
#endif // !XBOX360
#endif // WINDOWS
/// <summary>Initializes a new service manager</summary>
/// <param name="typeLister">

View File

@ -25,12 +25,12 @@ using System.Text;
namespace Nuclex.Support {
/*
/*
public enum Garbage {
Avoid,
Accept
}
*/
*/
/// <summary>Contains helper methods for the string builder class</summary>
public static class StringBuilderHelper {
@ -70,7 +70,7 @@ namespace Nuclex.Support {
/// with a small performance impact compared to the built-in method.
/// </remarks>
public static void Append(StringBuilder builder, int value) {
if(value < 0) {
if (value < 0) {
builder.Append('-');
recursiveAppend(builder, -value);
} else {
@ -89,7 +89,7 @@ namespace Nuclex.Support {
/// with a small performance impact compared to the built-in method.
/// </remarks>
public static void Append(StringBuilder builder, long value) {
if(value < 0) {
if (value < 0) {
builder.Append('-');
recursiveAppend(builder, -value);
} else {
@ -142,9 +142,9 @@ namespace Nuclex.Support {
int integral;
int fractional;
if(exponent >= 0) {
if(exponent >= FractionalBitCount) {
if(exponent >= NumericBitCount) {
if (exponent >= 0) {
if (exponent >= FractionalBitCount) {
if (exponent >= NumericBitCount) {
return false;
}
integral = mantissa << (exponent - FractionalBitCount);
@ -154,7 +154,7 @@ namespace Nuclex.Support {
fractional = (mantissa << (exponent + 1)) & FractionalBits;
}
} else {
if(exponent < -FractionalBitCount) {
if (exponent < -FractionalBitCount) {
return false;
}
integral = 0;
@ -162,30 +162,30 @@ namespace Nuclex.Support {
}
// Build the integral part
if(intValue < 0) {
if (intValue < 0) {
builder.Append('-');
}
if(integral == 0) {
if (integral == 0) {
builder.Append('0');
} else {
recursiveAppend(builder, integral);
}
if(decimalPlaces > 0) {
if (decimalPlaces > 0) {
builder.Append('.');
// Build the fractional part
if(fractional == 0) {
if (fractional == 0) {
builder.Append('0');
} else {
while(fractional != 0) {
while (fractional != 0) {
fractional *= 10;
int digit = (fractional >> FractionalBitCountPlusOne);
builder.Append(numbers[digit]);
fractional &= FractionalBits;
--decimalPlaces;
if(decimalPlaces == 0) {
if (decimalPlaces == 0) {
break;
}
}
@ -242,9 +242,9 @@ namespace Nuclex.Support {
long integral;
long fractional;
if(exponent >= 0) {
if(exponent >= FractionalBitCount) {
if(exponent >= NumericBitCount) {
if (exponent >= 0) {
if (exponent >= FractionalBitCount) {
if (exponent >= NumericBitCount) {
return false;
}
integral = mantissa << (int)(exponent - FractionalBitCount);
@ -254,7 +254,7 @@ namespace Nuclex.Support {
fractional = (mantissa << (int)(exponent + 1)) & FractionalBits;
}
} else {
if(exponent < -FractionalBitCount) {
if (exponent < -FractionalBitCount) {
return false;
}
integral = 0;
@ -262,30 +262,30 @@ namespace Nuclex.Support {
}
// Build the integral part
if(longValue < 0) {
if (longValue < 0) {
builder.Append('-');
}
if(integral == 0) {
if (integral == 0) {
builder.Append('0');
} else {
recursiveAppend(builder, integral);
}
if(decimalPlaces > 0) {
if (decimalPlaces > 0) {
builder.Append('.');
// Build the fractional part
if(fractional == 0) {
if (fractional == 0) {
builder.Append('0');
} else {
while(fractional != 0) {
while (fractional != 0) {
fractional *= 10;
long digit = (fractional >> FractionalBitCountPlusOne);
builder.Append(numbers[digit]);
fractional &= FractionalBits;
--decimalPlaces;
if(decimalPlaces == 0) {
if (decimalPlaces == 0) {
break;
}
}
@ -299,15 +299,15 @@ namespace Nuclex.Support {
/// <param name="builder">String builder the number will be appended to</param>
/// <param name="remaining">Remaining digits that will be recursively processed</param>
private static void recursiveAppend(StringBuilder builder, int remaining) {
#if XBOX360 || WINDOWS_PHONE
int digit = remaining % 10;
int tenth = remaining / 10;
#else
#if WINDOWS
int digit;
int tenth = Math.DivRem(remaining, 10, out digit);
#else
int digit = remaining % 10;
int tenth = remaining / 10;
#endif
if(tenth > 0) {
if (tenth > 0) {
recursiveAppend(builder, tenth);
}
@ -318,15 +318,15 @@ namespace Nuclex.Support {
/// <param name="builder">String builder the number will be appended to</param>
/// <param name="remaining">Remaining digits that will be recursively processed</param>
private static void recursiveAppend(StringBuilder builder, long remaining) {
#if XBOX360 || WINDOWS_PHONE
long digit = remaining % 10;
long tenth = remaining / 10;
#else
#if WINDOWS
long digit;
long tenth = Math.DivRem(remaining, 10, out digit);
#else
long digit = remaining % 10;
long tenth = remaining / 10;
#endif
if(tenth > 0) {
if (tenth > 0) {
recursiveAppend(builder, tenth);
}

View File

@ -133,7 +133,7 @@ namespace Nuclex.Support.Tracking {
}
}
#if !XBOX360 && !WINDOWS_PHONE
#if WINDOWS
/// <summary>Waits until the background process finishes or a timeout occurs</summary>
/// <param name="timeout">
@ -150,7 +150,7 @@ namespace Nuclex.Support.Tracking {
return WaitHandle.WaitOne(timeout, false);
}
#endif // !XBOX360
#endif // WINDOWS
/// <summary>Waits until the background process finishes or a timeout occurs</summary>
/// <param name="timeoutMilliseconds">
@ -164,13 +164,7 @@ namespace Nuclex.Support.Tracking {
return true;
}
#if XNA_3
return WaitHandle.WaitOne(timeoutMilliseconds, false);
#elif XBOX360 || WINDOWS_PHONE
return WaitHandle.WaitOne(timeoutMilliseconds);
#else
return WaitHandle.WaitOne(timeoutMilliseconds, false);
#endif
}
/// <summary>Whether the transaction has ended already</summary>