diff --git a/include/System/Array.h b/include/System/Array.h index 4816a19..f7e02ab 100644 --- a/include/System/Array.h +++ b/include/System/Array.h @@ -39,7 +39,11 @@ namespace System public: const int Length; - Array(const int size) : _array(new T[size]), _version(0), Length(size) { } + Array(const int size) : _array(new T[size]), _version(0), Length(size) + { + memset(_array, 0, sizeof(T) * size); + } + Array(const Array &obj) : _array(new T[obj.Length]), _version(obj._version), Length(obj.Length) { @@ -173,7 +177,11 @@ namespace System public: const int Length; - Array(const int size) : _array(new T*[size]), _version(0), Length(size) { } + Array(const int size) : _array(new T*[size]), _version(0), Length(size) + { + memset(_array, 0, sizeof(T *) * size); + } + Array(const Array &obj) : _array(new T*[obj.Length]), _version(obj._version), Length(obj.Length) { @@ -261,7 +269,7 @@ namespace System ArrayEnumerator(Array * const parent) : _array(parent), _position(0), _version(parent->_version) { } ~ArrayEnumerator() { } - T& Current() const + T* Current() const { sassert(_version == _array->_version, ""); diff --git a/include/System/Collections/Generic/List.h b/include/System/Collections/Generic/List.h index f723643..bc7f5f7 100644 --- a/include/System/Collections/Generic/List.h +++ b/include/System/Collections/Generic/List.h @@ -81,6 +81,7 @@ namespace System return index++ < parent->_size; } + void Reset() { sassert(version == parent->_version, ""); @@ -91,32 +92,30 @@ namespace System public: // Gets the number of elements actually contained in the List<>. - int Count() const - { - return _size; - } + inline int Count() const { return _size; } // Gets the total number of elements the internal data structure can hold without resizing. - int getCapacity() const - { - return _actualSize; - } + inline int getCapacity() const { return _actualSize; } // Sets the total number of elements the internal data structure can hold without resizing. void setCapacity(const int value) { if (value < _size) + { return; + } if (value != _actualSize) { if (value > 0) { T* destinationArray = new T[value]; + if (_size > 0) { memcpy(destinationArray, _items, _size * sizeof(T)); } + delete[] _items; _items = destinationArray; } @@ -126,14 +125,12 @@ namespace System _items = new T[0]; } + _actualSize = value; } } - bool IsReadOnly() const - { - return false; - } + inline bool IsReadOnly() const { return false; } // Initializes a new instance of the List<> class that is empty and has the default initial capacity. List() @@ -172,7 +169,8 @@ namespace System { EnsureCapacity(_size + 1); } - _items[_size++] = T(item); + + _items[_size++] = item; _version++; } @@ -199,6 +197,7 @@ namespace System _items = new T[_actualSize]; _size = 0; } + _version++; } @@ -212,6 +211,7 @@ namespace System return true; } } + return false; } @@ -231,6 +231,7 @@ namespace System static const Type& GetType() { static Type ListTypeInfo("List", "System::Collections::Generic::List", TypeCode::Object, true); + return ListTypeInfo; } @@ -240,11 +241,14 @@ namespace System for (int i = 0; i < _size; i++) { if (_items[i] == item) + { return i; + } } + return -1; } - + // Inserts an element into the List<> at the specified index. void Insert(const int index, const T& item) { @@ -254,10 +258,12 @@ namespace System { EnsureCapacity(_size + 1); } + if (index < _size) { memcpy(&_items[index + 1], &_items[index], (_size - index) * sizeof(T)); } + _items[index] = T(item); _size++; _version++; @@ -267,11 +273,13 @@ namespace System bool Remove(const T& item) { int index = IndexOf(item); + if (index >= 0) { RemoveAt(index); return true; } + return false; } @@ -307,10 +315,7 @@ namespace System } } - void Reverse() - { - Reverse(0, _size); - } + inline void Reverse() { Reverse(0, _size); } void Reverse(const int index, const int count) { @@ -333,7 +338,7 @@ namespace System _version++; } - void Sort(int index, int count, IComparer* comparer) + void Sort(int index, int count, IComparer * const comparer) { sassert(comparer != null, String::Format("comparer; %s", FrameworkResources::ArgumentNull_Generic)); @@ -346,6 +351,7 @@ namespace System T key = _items[index]; int i = index + 1; int j = count; + while (i <= j) { while ((i <= count) && (comparer->Compare(_items[i], key) <= 0)) @@ -355,6 +361,7 @@ namespace System if (i < j) swap(&_items[i], &_items[j]); } + // swap two elements swap(&_items[index], &_items[j]); // recursively sort the lesser list @@ -362,7 +369,7 @@ namespace System Sort(j+1, count, comparer); } - void Sort(IComparer* comparer) + void Sort(IComparer * const comparer) { sassert(comparer != null, String::Format("comparer; %s", FrameworkResources::ArgumentNull_Generic)); @@ -386,6 +393,7 @@ namespace System void TrimExcess() { int num = (int)(_actualSize * 0.9); + if(_size < num) { setCapacity(_size); @@ -394,6 +402,17 @@ namespace System T& operator[](const int index) { + sassert(index > 0, FrameworkResources::ArgumentOutOfRange_NeedNonNegNum); + sassert(index < Count(), ""); + + return _items[index]; + } + + const T& operator[](const int index) const + { + sassert(index > 0, FrameworkResources::ArgumentOutOfRange_NeedNonNegNum); + sassert(index < Count(), ""); + return _items[index]; } diff --git a/include/System/DateTime.h b/include/System/DateTime.h index 935e804..5d78516 100644 --- a/include/System/DateTime.h +++ b/include/System/DateTime.h @@ -53,7 +53,7 @@ namespace System TimeSpan TimeOfDay() const; static DateTime Today(); static DateTime UtcNow(); - int Year()const; + int Year() const; static const DateTime MaxValue; static const DateTime MinValue; diff --git a/include/System/Globalization/CultureInfo.h b/include/System/Globalization/CultureInfo.h index 142cef2..1e65b78 100644 --- a/include/System/Globalization/CultureInfo.h +++ b/include/System/Globalization/CultureInfo.h @@ -1,4 +1,9 @@ - +/***************************************************************************** + * CultureInfo.h * + * * + * XFX System::Globalization::CultureInfo class definition file. * + * Copyright (c) XFX Team. All Rights Reserved. * + *****************************************************************************/ #ifndef _SYSTEM_GLOBALIZATION_CULTUREINFO_ #define _SYSTEM_GLOBALIZATION_CULTUREINFO_ @@ -16,7 +21,7 @@ namespace System class CultureInfo : public IFormatProvider, public Object { public: - static const CultureInfo InvariantCulture; + static CultureInfo * const InvariantCulture; CultureInfo(int culture); CultureInfo(int culture, bool useUserOverride); diff --git a/include/System/Net/DnsEndPoint.h b/include/System/Net/DnsEndPoint.h new file mode 100644 index 0000000..1eeadd7 --- /dev/null +++ b/include/System/Net/DnsEndPoint.h @@ -0,0 +1,45 @@ +/***************************************************************************** + * DnsEndPoint.h * + * * + * System::Net::DnsEndPoint class definition file. * + * Copyright (c) XFX Team. All rights reserved. * + *****************************************************************************/ +#ifndef _SYSTEM_NET_DNSENDPOINT_ +#define _SYSTEM_NET_DNSENDPOINT_ + +#include "EndPoint.h" +#include +#include + +using namespace System::Net::Sockets; + +namespace System +{ + namespace Net + { + /** + * Represents a network endpoint as a host name or a string representation of an IP address and a port number. + */ + class DnsEndPoint : public EndPoint + { + private: + AddressFamily_t addressFamily; + int port; + String host; + + public: + AddressFamily_t getAddressFamily() const; + const String getHost() const; + int getPort() const; + + DnsEndPoint(const String& host, const int port); + DnsEndPoint(const String& host, const int port, const AddressFamily_t addressFamily); + + bool Equals(Object const * const obj) const; + int GetHashCode() const; + const String ToString() const; + }; + } +} + +#endif //_SYSTEM_NET_DNSENDPOINT_ diff --git a/include/System/Net/EndPoint.h b/include/System/Net/EndPoint.h index e95ff6d..dd12cc3 100644 --- a/include/System/Net/EndPoint.h +++ b/include/System/Net/EndPoint.h @@ -27,9 +27,12 @@ namespace System EndPoint(); public: - AddressFamily_t getAddressFamily(); + AddressFamily_t getAddressFamily() const; - virtual EndPoint* Create(SocketAddress socketAddress); + virtual ~EndPoint(); + + virtual EndPoint* Create(SocketAddress * const socketAddress); + static const Type& GetType(); virtual SocketAddress* Serialize(); }; } diff --git a/include/System/Net/Enums.h b/include/System/Net/Enums.h new file mode 100644 index 0000000..7d296c6 --- /dev/null +++ b/include/System/Net/Enums.h @@ -0,0 +1,426 @@ +/***************************************************************************** + * Enums.h * + * * + * System::Net enumerations definition file. * + * Copyright (c) XFX Team. All rights reserved. * + *****************************************************************************/ +#ifndef _SYSTEM_NET_ENUMS_ +#define _SYSTEM_NET_ENUMS_ + +namespace System +{ + namespace Net + { + /** + * The HTTP headers that may be specified in a client request. + */ + struct HttpRequestHeader + { + enum type + { + /** + * The Cache-Control header, which specifies directives that must be obeyed by all cache control mechanisms along the request/response chain. + */ + CacheControl, + /** + * The Connection header, which specifies options that are desired for a particular connection. + */ + Connection, + /** + * The Date header, which specifies the date and time at which the request originated. + */ + Date, + /** + * The Keep-Alive header, which specifies a parameter used into order to maintain a persistent connection. + */ + KeepAlive, + /** + * The Pragma header, which specifies implementation-specific directives that might apply to any agent along the request/response chain. + */ + Pragma, + /** + * The Trailer header, which specifies the header fields present in the trailer of a message encoded with chunked transfer-coding. + */ + Trailer, + /** + * The Transfer-Encoding header, which specifies what (if any) type of transformation that has been applied to the message body. + */ + TransferEncoding, + /** + * The Upgrade header, which specifies additional communications protocols that the client supports. + */ + Upgrade, + /** + * The Via header, which specifies intermediate protocols to be used by gateway and proxy agents. + */ + Via, + /** + * The Warning header, which specifies additional information about that status or transformation of a message that might not be reflected in the message. + */ + Warning, + /** + * The Allow header, which specifies the set of HTTP methods supported. + */ + Allow, + /** + * The Content-Length header, which specifies the length, in bytes, of the accompanying body data. + */ + ContentLength, + /** + * The Content-Type header, which specifies the MIME type of the accompanying body data. + */ + ContentType, + /** + * The Content-Encoding header, which specifies the encodings that have been applied to the accompanying body data. + */ + ContentEncoding, + /** + * The Content-Langauge header, which specifies the natural language(s) of the accompanying body data. + */ + ContentLanguage, + /** + * The Content-Location header, which specifies a URI from which the accompanying body may be obtained. + */ + ContentLocation, + /** + * The Content-MD5 header, which specifies the MD5 digest of the accompanying body data, for the purpose of providing an end-to-end message integrity check. + */ + ContentMd5, + /** + * The Content-Range header, which specifies where in the full body the accompanying partial body data should be applied. + */ + ContentRange, + /** + * The Expires header, which specifies the date and time after which the accompanying body data should be considered stale. + */ + Expires, + /** + * The Last-Modified header, which specifies the date and time at which the accompanying body data was last modified. + */ + LastModified, + /** + * The Accept header, which specifies the MIME types that are acceptable for the response. + */ + Accept, + /** + * The Accept-Charset header, which specifies the character sets that are acceptable for the response. + */ + AcceptCharSet, + /** + * The Accept-Encoding header, which specifies the content encodings that are acceptable for the response. + */ + AcceptEncoding, + /** + * The Accept-Language header, which specifies that natural languages that are preferred for the response. + */ + AcceptLanguage, + /** + * The Authorization header, which specifies the credentials that the client presents in order to authenticate itself to the server. + */ + Authorization, + /** + * The Cookie header, which specifies cookie data presented to the server. + */ + Cookie, + /** + * The Expect header, which specifies particular server behaviors that are required by the client. + */ + Expect, + /** + * The From header, which specifies an Internet E-mail address for the human user who controls the requesting user agent. + */ + From, + /** + * The Host header, which specifies the host name and port number of the resource being requested. + */ + Host, + /** + * The If-Match header, which specifies that the requested operation should be performed only if the client's cached copy of the indicated resource is current. + */ + IfMatch, + /** + * The If-Modified-Since header, which specifies that the requested operation should be performed only if the requested resource has been modified since the indicated data and time. + */ + IfModifiedSince, + /** + * The If-None-Match header, which specifies that the requested operation should be performed only if none of client's cached copies of the indicated resources are current. + */ + IfNoneMatch, + /** + * The If-Range header, which specifies that only the specified range of the requested resource should be sent, if the client's cached copy is current. + */ + IfRange, + /** + * The If-Unmodified-Since header, which specifies that the requested operation should be performed only if the requested resource has not been modified since the indicated date and time. + */ + IfUnmodifiedSince, + /** + * The Max-Forwards header, which specifies an integer indicating the remaining number of times that this request may be forwarded. + */ + MaxForwards, + /** + * The Proxy-Authorization header, which specifies the credentials that the client presents in order to authenticate itself to a proxy. + */ + ProxyAuthorization, + /** + * The Referer header, which specifies the URI of the resource from which the request URI was obtained. + */ + Referer, + /** + * The Range header, which specifies the the sub-range(s) of the response that the client requests be returned in lieu of the entire response. + */ + Range, + /** + * The TE header, which specifies the transfer encodings that are acceptable for the response. + */ + Te, + /** + * The Translate header, a Microsoft extension to the HTTP specification used in conjunction with WebDAV functionality. + */ + Translate, + /** + * The User-Agent header, which specifies information about the client agent. + */ + UserAgent + }; + }; + + /** + * Contains the values of status codes defined for HTTP. + */ + struct HttpStatusCode + { + enum type + { + /** + * Equivalent to HTTP status 202. System::Net::HttpStatusCode::Accepted indicates that the request has been accepted for further processing. + */ + Accepted = 202, + /** + * Equivalent to HTTP status 300. System::Net::HttpStatusCode::Ambiguous indicates that the requested information has multiple representations. The default action is to treat this status as a redirect and follow the contents of the Location header associated with this response. + */ + Ambiguous = 300, + /** + * Equivalent to HTTP status 502. System::Net::HttpStatusCode::BadGateway indicates that an intermediate proxy server received a bad response from another proxy or the origin server. + */ + BadGateway = 502, + /** + * Equivalent to HTTP status 400. System::Net::HttpStatusCode::BadRequest indicates that the request could not be understood by the server. System::Net::HttpStatusCode::BadRequest is sent when no other error is applicable, or if the exact error is unknown or does not have its own error code. + */ + BadRequest = 400, + /** + * Equivalent to HTTP status 409. System::Net::HttpStatusCode::Conflict indicates that the request could not be carried out because of a conflict on the server. + */ + Conflict = 409, + /** + * Equivalent to HTTP status 100. System::Net::HttpStatusCode::Continue indicates that the client can continue with its request. + */ + Continue = 100, + /** + * Equivalent to HTTP status 201. System::Net::HttpStatusCode::Created indicates that the request resulted in a new resource created before the response was sent. + */ + Created = 201, + /** + * Equivalent to HTTP status 417. System::Net::HttpStatusCode::ExpectationFailed indicates that an expectation given in an Expect header could not be met by the server. + */ + ExpectationFailed = 417, + /** + * Equivalent to HTTP status 403. System::Net::HttpStatusCode::Forbidden indicates that the server refuses to fulfill the request. + */ + Forbidden = 403, + /** + * Equivalent to HTTP status 302. System::Net::HttpStatusCode::Found indicates that the requested information is located at the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response. When the original request method was POST, the redirected request will use the GET method. + */ + Found = 302, + /** + * Equivalent to HTTP status 504. System::Net::HttpStatusCode::GatewayTimeout indicates that an intermediate proxy server timed out while waiting for a response from another proxy or the origin server. + */ + GatewayTimeout = 504, + /** + * Equivalent to HTTP status 410. System::Net::HttpStatusCode::Gone indicates that the requested resource is no longer available. + */ + Gone = 410, + /** + * Equivalent to HTTP status 505. System::Net::HttpStatusCode::HttpVersionNotSupported indicates that the requested HTTP version is not supported by the server. + */ + HttpVersionNotSupported = 505, + /** + * Equivalent to HTTP status 500. System::Net::HttpStatusCode::InternalServerError indicates that a generic error has occurred on the server. + */ + InternalServerError = 500, + /** + * Equivalent to HTTP status 411. System::Net::HttpStatusCode::LengthRequired indicates that the required Content-length header is missing. + */ + LengthRequired = 411, + /** + * Equivalent to HTTP status 405. System::Net::HttpStatusCode::MethodNotAllowed indicates that the request method (POST or GET) is not allowed on the requested resource. + */ + MethodNotAllowed = 405, + /** + * Equivalent to HTTP status 301. System::Net::HttpStatusCode::Moved indicates that the requested information has been moved to the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response. When the original request method was POST, the redirected request will use the GET method. + */ + Moved = 301, + /** + * Equivalent to HTTP status 301. System::Net::HttpStatusCode::MovedPermanently indicates that the requested information has been moved to the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response. + */ + MovedPermanently = 302, + /** + * Equivalent to HTTP status 300. System::Net::HttpStatusCode::MultipleChoices indicates that the requested information has multiple representations. The default action is to treat this status as a redirect and follow the contents of the Location header associated with this response. + */ + MultipleChoices = 300, + /** + * Equivalent to HTTP status 204. System::Net::HttpStatusCode::NoContent indicates that the request has been successfully processed and that the response is intentionally blank. + */ + NoContent = 204, + /** + * Equivalent to HTTP status 203. System::Net::HttpStatusCode::NonAuthoritativeInformation indicates that the returned metadata information is from a cached copy instead of the origin server and therefore may be incorrect. + */ + NonAuthorativeInformation = 203, + /** + * Equivalent to HTTP status 406. System::Net::HttpStatusCode::NotAcceptable indicates that the client has indicated with Accept headers that it will not accept any of the available representations of the resource. + */ + NotAcceptable = 406, + /** + * Equivalent to HTTP status 404. System::Net::HttpStatusCode::NotFound indicates that the requested resource does not exist on the server. + */ + NotFound = 404, + /** + * Equivalent to HTTP status 501. System::Net::HttpStatusCode::NotImplemented indicates that the server does not support the requested function. + */ + NotImplemented = 501, + /** + * Equivalent to HTTP status 304. System::Net::HttpStatusCode::NotModified indicates that the client's cached copy is up to date. The contents of the resource are not transferred. + */ + NotModified = 304, + /** + * Equivalent to HTTP status 200. System::Net::HttpStatusCode::OK indicates that the request succeeded and that the requested information is in the response. This is the most common status code to receive. + */ + OK = 200, + /** + * Equivalent to HTTP status 206. System::Net::HttpStatusCode::PartialContent indicates that the response is a partial response as requested by a GET request that includes a byte range. + */ + PartialContent = 206, + /** + * Equivalent to HTTP status 402. System::Net::HttpStatusCode::PaymentRequired is reserved for future use. + */ + PaymentRequired = 402, + /** + * Equivalent to HTTP status 412. System::Net::HttpStatusCode::PreconditionFailed indicates that a condition set for this request failed, and the request cannot be carried out. Conditions are set with conditional request headers like If-Match, If-None-Match, or If-Unmodified-Since. + */ + PreconditionFailed = 412, + /** + * Equivalent to HTTP status 407. System::Net::HttpStatusCode::ProxyAuthenticationRequired indicates that the requested proxy requires authentication. The Proxy-authenticate header contains the details of how to perform the authentication. + */ + ProxyAuthenticationRequired = 407, + /** + * Equivalent to HTTP status 302. System::Net::HttpStatusCode::Redirect indicates that the requested information is located at the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response. When the original request method was POST, the redirected request will use the GET method. + */ + Redirect = 302, + /** + * Equivalent to HTTP status 307. System::Net::HttpStatusCode::RedirectKeepVerb indicates that the request information is located at the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response. When the original request method was POST, the redirected request will also use the POST method. + */ + RedirectKeepVerb = 307, + /** + * Equivalent to HTTP status 303. System::Net::HttpStatusCode::RedirectMethod automatically redirects the client to the URI specified in the Location header as the result of a POST. The request to the resource specified by the Location header will be made with a GET. + */ + RedirectMethod = 303, + /** + * Equivalent to HTTP status 416. System::Net::HttpStatusCode::RequestedRangeNotSatisfiable indicates that the range of data requested from the resource cannot be returned, either because the beginning of the range is before the beginning of the resource, or the end of the range is after the end of the resource. + */ + RequestedRangeNotSatisfiable = 416, + /** + * Equivalent to HTTP status 413. System::Net::HttpStatusCode::RequestEntityTooLarge indicates that the request is too large for the server to process. + */ + RequestedEntityTooLarge = 413, + /** + * Equivalent to HTTP status 408. System::Net::HttpStatusCode::RequestTimeout indicates that the client did not send a request within the time the server was expecting the request. + */ + RequestTimeout = 408, + /** + * Equivalent to HTTP status 414. System::Net::HttpStatusCode::RequestUriTooLong indicates that the URI is too long. + */ + RequestUriTooLong = 414, + /** + * Equivalent to HTTP status 205. System::Net::HttpStatusCode::ResetContent indicates that the client should reset (not reload) the current resource. + */ + ResetContent = 205, + /** + * Equivalent to HTTP status 303. System::Net::HttpStatusCode::SeeOther automatically redirects the client to the URI specified in the Location header as the result of a POST. The request to the resource specified by the Location header will be made with a GET. + */ + SeeOther = 303, + /** + * Equivalent to HTTP status 503. System::Net::HttpStatusCode::ServiceUnavailable indicates that the server is temporarily unavailable, usually due to high load or maintenance. + */ + ServiceUnavailable = 503, + /** + * Equivalent to HTTP status 101. System::Net::HttpStatusCode::SwitchingProtocols indicates that the protocol version or protocol is being changed. + */ + SwitchingProtocols = 101, + /** + * Equivalent to HTTP status 307. System::Net::HttpStatusCode::TemporaryRedirect indicates that the request information is located at the URI specified in the Location header. The default action when this status is received is to follow the Location header associated with the response. When the original request method was POST, the redirected request will also use the POST method. + */ + TemporaryRedirect = 307, + /** + * Equivalent to HTTP status 401. System::Net::HttpStatusCode::Unauthorized indicates that the requested resource requires authentication. The WWW-Authenticate header contains the details of how to perform the authentication. + */ + Unauthorized = 401, + /** + * Equivalent to HTTP status 415. System::Net::HttpStatusCode::UnsupportedMediaType indicates that the request is an unsupported type. + */ + UnsupportedMediaType = 415, + /** + * Equivalent to HTTP status 306. System::Net::HttpStatusCode::Unused is a proposed extension to the HTTP/1.1 specification that is not fully specified. + */ + Unused = 306, + /** + * Equivalent to HTTP status 305. System::Net::HttpStatusCode::UseProxy indicates that the request should use the proxy server at the URI specified in the Location header. + */ + UseProxy = 305 + }; + }; + + /** + * Defines status codes for the System::Net::WebException class. + */ + struct WebExceptionStatus + { + enum type + { + /** + * The remote service point could not be contacted at the transport level. + */ + ConnectFailure = 2, + /** + * A message was received that exceeded the specified limit when sending a request or receiving a response from the server. + */ + MessageLengthLimitExceeded = 17, + /** + * An internal asynchronous request is pending. + */ + Pending = 13, + /** + * The request was canceled, the System::Net::WebRequest::Abort method was called, or an unclassifiable error occurred. This is the default value for System::Net::WebException::Status. + */ + RequestCanceled = 6, + /** + * A complete request could not be sent to the remote server. + */ + SendFailure = 4, + /** + * No error was encountered. + */ + Success = 0, + /** + * An exception of unknown type has occurred. + */ + UnknownError = 16 + }; + }; + + typedef HttpRequestHeader::type HttpRequestHeader_t; + typedef HttpStatusCode::type HttpStatusCode_t; + typedef WebExceptionStatus::type WebExceptionStatus_t; + } +} + +#endif //_SYSTEM_NET_ENUMS_ diff --git a/include/System/Net/IPAddress.h b/include/System/Net/IPAddress.h new file mode 100644 index 0000000..8872aa2 --- /dev/null +++ b/include/System/Net/IPAddress.h @@ -0,0 +1,67 @@ +/***************************************************************************** + * IPAddress.h * + * * + * System::Net::IPAddress class definition file. * + * Copyright (c) XFX Team. All rights reserved. * + *****************************************************************************/ +#ifndef _SYSTEM_NET_IPADDRESS_ +#define _SYSTEM_NET_IPADDRESS_ + +#include +#include +#include + +using namespace System::Net::Sockets; + +namespace System +{ + namespace Net + { + /** + * Provides an Internet Protocol (IP) address. + */ + class IPAddress : public Object + { + private: + byte* addressBytes; + AddressFamily_t addressFamily; + + public: + AddressFamily_t getAddressFamily() const; + bool IsIPv6LinkLocal() const; + bool IsIPv6Multicast() const; + bool IsIPv6SiteLocal() const; + long long getScopeId() const; + void setScopeId(long long value); + + static const IPAddress Any; + static const IPAddress Broadcast; + static const IPAddress IPv6Any; + static const IPAddress IPv6Loopback; + static const IPAddress IPv6None; + static const IPAddress Loopback; + static const IPAddress None; + + IPAddress(byte addressBytes[]); + IPAddress(byte address[], long long scopeid); + IPAddress(long long newAddress); + ~IPAddress(); + + bool Equals(Object const * const obj) const; + byte* GetAddressBytes() const; + int GetHashCode() const; + static int HostToNetworkOrder(int host); + static long long HostToNetworkOrder(long long host); + static short HostToNetworkOrder(short host); + static bool IsLoopback(IPAddress const * const address); + static int NetworkToHostOrder(int network); + static long long NetworkToHostOrder(long long network); + static short NetworkToHostOrder(short network); + static IPAddress Parse(const String& ipString); + static bool TryParse(const String& ipString, out IPAddress& address); + const String ToString() const; + }; + } +} + +#endif //_SYSTEM_NET_IPADDRESS_ diff --git a/include/System/Net/IPEndPoint.h b/include/System/Net/IPEndPoint.h new file mode 100644 index 0000000..8a4cb5d --- /dev/null +++ b/include/System/Net/IPEndPoint.h @@ -0,0 +1,48 @@ +/***************************************************************************** + * IPEndPoint.h * + * * + * System::Net::IPEndPoint class definition file. * + * Copyright (c) XFX Team. All rights reserved. * + *****************************************************************************/ +#ifndef _SYSTEM_NET_IPENDPOINT_ +#define _SYSTEM_NET_IPENDPOINT_ + +#include +#include + +namespace System +{ + namespace Net + { + /** + * Represents a network endpoint as an IP address and a port number. + */ + class IPEndPoint : public EndPoint + { + private: + IPAddress address; + int port; + + public: + IPAddress getAddress() const; + void setAddress(IPAddress value); + AddressFamily_t getAddressFamily() const; + int getPort() const; + void setPort(const int value); + + static const int MaxPort = 65535; + static const int MinPort = 0; + + IPEndPoint(const long long address, const int port); + IPEndPoint(IPAddress * const address, const int port); + + EndPoint * Create(SocketAddress socketAddress); + bool Equals(Object const * const obj) const; + int GetHashCode() const; + SocketAddress * Serialize(); + const String ToString() const; + }; + } +} + +#endif diff --git a/include/System/Net/NetworkInformation/NetworkChange.h b/include/System/Net/NetworkInformation/NetworkChange.h new file mode 100644 index 0000000..ba8b81e --- /dev/null +++ b/include/System/Net/NetworkInformation/NetworkChange.h @@ -0,0 +1,39 @@ +/***************************************************************************** + * NetworkInterface.h * + * * + * System::Net::Sockets::NetworkInterface class definition file. * + * Copyright (c) XFX Team. All rights reserved. * + *****************************************************************************/ +#ifndef _SYSTEM_NET_NETWORKINFORMATION_NETWORKCHANGE_ +#define _SYSTEM_NET_NETWORKINFORMATION_NETWORKCHANGE_ + +#include + +namespace System +{ + namespace Net + { + namespace NetworkInformation + { + /** + * Allows applications to receive notification when the Internet Protocol (IP) address of a network interface, also called a network card or adapter, changes. + */ + class NetworkChange + { + protected: + NetworkChange(); + virtual ~NetworkChange(); + + public: + NetworkAddressChangedEventHandler NetworkAddressChanged; + }; + + /** + * References one or more methods to be called when the address of a network interface changes. + */ + typedef Event NetworkAddressChangedEventHandler; + } + } +} + +#endif //_SYSTEM_NET_NETWORKINFORMATION_NETWORKCHANGE_ diff --git a/include/System/Net/NetworkInformation/NetworkInterface.h b/include/System/Net/NetworkInformation/NetworkInterface.h new file mode 100644 index 0000000..99b7b17 --- /dev/null +++ b/include/System/Net/NetworkInformation/NetworkInterface.h @@ -0,0 +1,32 @@ +/***************************************************************************** + * NetworkInterface.h * + * * + * System::Net::Sockets::NetworkInterface class definition file. * + * Copyright (c) XFX Team. All rights reserved. * + *****************************************************************************/ +#ifndef _SYSTEM_NET_NETWORKINFORMATION_NETWORKINTERFACE_ +#define _SYSTEM_NET_NETWORKINFORMATION_NETWORKINTERFACE_ + +namespace System +{ + namespace Net + { + namespace NetworkInformation + { + /** + * Provides availability information for a network interface. + */ + class NetworkInterface + { + protected: + NetworkInterface(); + virtual ~NetworkInterface(); + + public: + static bool GetIsNetworkAvailable(); + }; + } + } +} + +#endif //_SYSTEM_NET_NETWORKINFORMATION_NETWORKINTERFACE_ diff --git a/include/System/Net/SocketAddress.h b/include/System/Net/SocketAddress.h index 73a7202..91b6ae6 100644 --- a/include/System/Net/SocketAddress.h +++ b/include/System/Net/SocketAddress.h @@ -7,9 +7,9 @@ #ifndef _SYSTEM_NET_SOCKETADDRESS_ #define _SYSTEM_NET_SOCKETADDRESS_ -#include "../Object.h" -#include "../Types.h" -#include "Sockets/Enums.h" +#include +#include +#include using namespace System::Net::Sockets; @@ -34,7 +34,9 @@ namespace System SocketAddress(AddressFamily_t family); SocketAddress(AddressFamily_t family, int size); - const Type& GetType(); + bool Equals(Object const * const obj) const; + int GetHashCode() const; + static const Type& GetType(); const String ToString(); }; } diff --git a/include/System/Net/Sockets/Enums.h b/include/System/Net/Sockets/Enums.h index 2af9375..092dd08 100644 --- a/include/System/Net/Sockets/Enums.h +++ b/include/System/Net/Sockets/Enums.h @@ -13,69 +13,330 @@ namespace System { namespace Sockets { + /** + * Specifies the addressing scheme that an instance of the System::Net::Sockets::Socket class can use. + */ struct AddressFamily { enum type { - InterNetwork, - InterNetworkV6, - Unknown, - Unspecified - }; - }; - - struct ProtocolType - { - enum type - { - Tcp = 6, - Udp = 17, + /** + * An address for IP version 4. + */ + InterNetwork = 2, + /** + * An address for IP version 6. + */ + InterNetworkV6 = 23, + /** + * An unknown address family. + */ Unknown = -1, + /** + * An address family has not been specified. + */ Unspecified = 0 }; }; + /** + * Specifies the protocol that the System::Net::Sockets::Socket class supports. + */ + struct ProtocolType + { + enum type + { + /** + * The Transmission Control Protocol (TCP). + */ + Tcp = 6, + /** + * The User Datagram Protocol (UDP). + */ + Udp = 17, + /** + * An unknown protocol type. + */ + Unknown = -1, + /** + * The protocol type is unspecified. + */ + Unspecified = 0 + }; + }; + + /** + * The type of asynchronous socket operation most recently performed with this object. + */ struct SocketAsyncOperation { enum type { + /** + * A socket Connect operation. + */ Connect = 2, + /** + * None of the socket operations. + */ None = 0, + /** + * A socket Receive operation. + */ Receive = 4, + /** + * A socket ReceiveFrom operation. + */ RecieveFrom = 5, + /** + * A socket Send operation. + */ Send = 7, + /** + * A socket SendTo operation. + */ SendTo = 9 }; }; + /** + * Defines error codes for the System::Net::Sockets::Socket class. + */ struct SocketError { enum type { + /** + * An attempt was made to access a System::Net::Sockets::Socket in a way that is forbidden by its access permissions. + */ AccessDenied = 10013, + /** + * Only one use of an address is normally permitted. + */ AddressAlreadyInUse = 10048, + /** + * The address family specified is not supported. This error is returned if the IPv6 address family was specified and the IPv6 stack is not installed on the local machine. This error is returned if the IPv4 address family was specified and the IPv4 stack is not installed on the local machine. + */ AddressFamilyNotSupported = 10047, + /** + * The selected IP address is not valid in this context. + */ AddressNotAvailable = 10049, - + /** + * The nonblocking System::Net::Sockets::Socket already has an operation in progress. + */ + AlreadyInProgress = 10037, + /** + * The connection was aborted by the .NET Framework or the underlying socket provider. + */ + ConnectionAborted = 10053, + /** + * The remote host is actively refusing a connection. + */ + ConnectionRefused = 10061, + /** + * The connection was reset by the remote peer. + */ + ConnectionReset = 10054, + /** + * A required address was omitted from an operation on a System::Net::Sockets::Socket. + */ + DestinationAddressRequired = 10039, + /** + * A graceful shutdown is in progress. + */ + Disconnecting = 10101, + /** + * An invalid pointer address was detected by the underlying socket provider. + */ + Fault = 10014, + /** + * The operation failed because the remote host is down. + */ + HostDown = 10064, + /** + * No such host is known. The name is not an official host name or alias. + */ + HostNotFound = 11001, + /** + * There is no network route to the specified host. + */ + HostUnreachable = 10065, + /** + * A blocking operation is in progress. + */ + InProgress = 10036, + /** + * A blocking System::Net::Sockets::Socket call was canceled. + */ + Interrupted = 10004, + /** + * An invalid argument was supplied to a System::Net::Sockets::Socket member. + */ + InvalidArgument = 10022, + /** + * The application has initiated an overlapped operation that cannot be completed immediately. + */ + IOPending = 997, + /** + * The System::Net::Sockets::Socket is already connected. + */ + IsConnected = 10056, + /** + * The datagram is too long. + */ + MessageSize = 10040, + /** + * The network is not available. + */ + NetworkDown = 10050, + /** + * The application tried to set an option on a connection that has already timed out. + */ + NetworkReset = 10052, + /** + * No route to the remote host exists. + */ + NetworkUnreachable = 10051, + /** + * No free buffer space is available for a System::Net::Sockets::Socket operation. + */ + NoBufferSpaceAvailable = 10055, + /** + * The requested name or IP address was not found on the name server. + */ + NoData = 11004, + /** + * The error is unrecoverable or the requested database cannot be located. + */ + NoRecovery = 11003, + /** + * The application tried to send or receive data, and the System::Net::Sockets::Socket is not connected. + */ + NotConnected = 10057, + /** + * The underlying socket provider has not been initialized. + */ + NotInitialized = 10093, + /** + * A System::Net::Sockets::Socket operation was attempted on a non-socket. + */ + NotSocket = 10038, + /** + * The overlapped operation was aborted due to the closure of the System::Net::Sockets::Socket. + */ + OperationAborted = 995, + /** + * The address family is not supported by the protocol family. + */ + OperationNotSupported = 10045, + /** + * Too many processes are using the underlying socket provider. + */ + ProcessLimit = 10067, + /** + * The protocol family is not implemented or has not been configured. + */ + ProtocolFamilyNotSupported = 10046, + /** + * The protocol is not implemented or has not been configured. + */ + ProtocolNotSupported = 10043, + /** + * An unknown, invalid, or unsupported option or level was used with a System::Net::Sockets::Socket. + */ + ProtocolOption = 10042, + /** + * The protocol type is incorrect for this System::Net::Sockets::Socket. + */ + ProtocolType = 10041, + /** + * A request to send or receive data was disallowed because the System::Net::Sockets::Socket has already been closed. + */ + Shutdown = 10058, + /** + * An unspecified System::Net::Sockets::Socket error has occurred. + */ + SocketError = -1, + /** + * The support for the specified socket type does not exist in this address family. + */ + SocketNotSupported = 10044, + /** + * The System::Net::Sockets::Socket operation succeeded. + */ + Success = 0, + /** + * The network subsystem is unavailable. + */ + SystemNotReady = 10091, + /** + * The connection attempt timed out, or the connected host has failed to respond. + */ + TimedOut = 10060, + /** + * There are too many open sockets in the underlying socket provider. + */ + TooManyOpenSockets = 10024, + /** + * The name of the host could not be resolved. Try again later. + */ + TryAgain = 11002, + /** + * The specified class was not found. + */ + TypeNotFound = 10109, + /** + * The version of the underlying socket provider is out of range. + */ + VersionNotSupported = 10092, + /** + * An operation on a nonblocking socket cannot be completed immediately. + */ + WouldBlock = 10035 }; }; + /** + * Defines constants that are used by the System::Net::Sockets::Socket::Shutdown(System::Net::Sockets::SocketShutdown) method. + */ struct SocketShutdown { enum type { - Both, - Recieve, - Send + /** + * Disables a System::Net::Sockets::Socket for both sending and receiving. + */ + Both = 2, + /** + * Disables a System::Net::Sockets::Socket for receiving. + */ + Recieve = 0, + /** + * Disables a System::Net::Sockets::Socket for sending. + */ + Send = 1 }; }; + /** + * Specifies the type of socket that an instance of the System::Net::Sockets::Socket class represents. + */ struct SocketType { enum type { + /** + * An unknown Socket type. + */ Unknown = -1, + /** + * A socket type that supports reliable, two-way, connection-based byte streams without the duplication of data and without preservation of boundaries. A System::Net::Sockets::Socket of this type communicates with a single peer and requires a remote host connection before communication can begin. This socket type uses the Transmission Control Protocol (System::Net::Sockets::ProtocolType::Tcp) and the System::Net::Sockets::AddressFamily.can be either System::Net::Sockets::AddressFamily::InterNetwork or System::Net::Sockets::AddressFamily::InterNetworkV6. + */ Stream = 1, + /** + * Supports datagrams, which are connectionless, unreliable messages of a fixed (typically small) maximum length. Messages might be lost or duplicated and might arrive out of order. A Socket of type System::Net::Sockets::SocketType::Dgram requires no connection prior to sending and receiving data, and can communicate with multiple peers. System::Net::Sockets::SocketType::Dgram uses the Datagram Protocol (System::Net::Sockets::ProtocolType::Udp) and the System::Net::Sockets::AddressFamily::InterNetwork or System::Net::Sockets::AddressFamily::InterNetworkV6System::Net::Sockets::AddressFamily. + */ Dgram = 2, }; }; @@ -83,11 +344,11 @@ namespace System /** * Specifies the addressing scheme that an instance of the System::Net::Sockets::Socket class can use. */ - typedef AddressFamily::type AddressFamily_t; + typedef AddressFamily::type AddressFamily_t; /** * Specifies the protocols that the System::Net::Sockets::Socket class supports. */ - typedef ProtocolType::type ProtocolType_t; + typedef ProtocolType::type ProtocolType_t; /** * The type of asynchronous socket operation most recently performed with this object. */ diff --git a/include/System/Net/Sockets/Socket.h b/include/System/Net/Sockets/Socket.h index 18a4637..ab5f5d5 100644 --- a/include/System/Net/Sockets/Socket.h +++ b/include/System/Net/Sockets/Socket.h @@ -39,13 +39,13 @@ namespace System void Dispose(bool disposing); public: - AddressFamily_t getAddressFamily(); - int Available(); - bool Connected(); - HANDLE getHandle(); - ProtocolType_t getProtocolType(); + AddressFamily_t getAddressFamily() const; + int Available() const; + bool Connected() const; + HANDLE getHandle() const; + ProtocolType_t getProtocolType() const; int ReceiveBufferSize; - EndPoint* getRemoteEndPoint(); + EndPoint* getRemoteEndPoint() const; int SendBufferSize; short Ttl; diff --git a/include/System/Net/Sockets/SocketAsyncEventArgs.h b/include/System/Net/Sockets/SocketAsyncEventArgs.h index 39dc873..6d844bc 100644 --- a/include/System/Net/Sockets/SocketAsyncEventArgs.h +++ b/include/System/Net/Sockets/SocketAsyncEventArgs.h @@ -1,7 +1,7 @@ /***************************************************************************** * SocketAsyncEventArgs.h * * * - * System::Net::Sockets::SocketAsyncEventArgs definition file. * + * System::Net::Sockets::SocketAsyncEventArgs class definition file. * * Copyright (c) XFX Team. All rights reserved. * *****************************************************************************/ #ifndef _SYSTEM_NET_SOCKETS_SOCKETASYNCEVENTARGS_ @@ -20,18 +20,21 @@ namespace System { namespace Sockets { - class SocketAsyncEventArgs : public EventArgs + class SocketAsyncEventArgs : public EventArgs, public IDisposable { + private: + friend class Socket; + protected: virtual void Oncompleted(SocketAsyncEventArgs* e); virtual ~SocketAsyncEventArgs(); public: - byte* getBuffer(); + byte * getBuffer() const; int getBytesTransferred() const; //Exception* getConnectByNameError() const; - Socket getConnectSocket() const; - int Count(); + Socket * getConnectSocket() const; + int Count() const; SocketAsyncOperation_t getLastOperation() const; int getOffset() const; EndPoint* RemoteEndPoint; diff --git a/include/System/Object.h b/include/System/Object.h index 371fd7a..dc81998 100644 --- a/include/System/Object.h +++ b/include/System/Object.h @@ -7,10 +7,11 @@ #ifndef _SYSTEM_OBJECT_ #define _SYSTEM_OBJECT_ +#include + namespace System { class String; - class Type; // Supports all classes in the .NET Framework class hierarchy and provides low-level services to derived classes. // This is the ultimate base class of all classes in the .NET Framework; it is the root of the type hierarchy. @@ -27,13 +28,19 @@ namespace System virtual ~Object() { } }; + // syntax: as<[target type]>([source instance]) + template + U * as(T * const source) + { + Type typeCode = T::GetType(); // make sure source is an Object + Type destTypeCode = U::GetType(); // same here, but now for U + + return (typeCode == destTypeCode) ? (U *)source : NULL; + } + // returns whether the type of obj1 matches that of obj2 bool is(Object const * const obj1, Object const * const obj2); - // syntax: as<[target type]>([source instance]) - template - U * as(T * const source); - template struct Derived_from { static void constraints(T* p) { B* pb = p; } Derived_from() { void(*p)(T*) = constraints; } diff --git a/include/System/Types.h b/include/System/Types.h index 32cd3a0..fbd12e9 100644 --- a/include/System/Types.h +++ b/include/System/Types.h @@ -33,8 +33,7 @@ namespace System // #define interface class -// Documentation -// +// Hints that the following parameter is an output #define out #if _MSC_VER diff --git a/src/libSystem/DnsEndPoint.cpp b/src/libSystem/DnsEndPoint.cpp new file mode 100644 index 0000000..7ed1cb5 --- /dev/null +++ b/src/libSystem/DnsEndPoint.cpp @@ -0,0 +1,99 @@ +// Copyright (C) XFX Team +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +//* Redistributions of source code must retain the above copyright +//notice, this list of conditions and the following disclaimer. +//* Redistributions in binary form must reproduce the above copyright +//notice, this list of conditions and the following disclaimer in the +//documentation and/or other materials provided with the distribution. +//* Neither the name of the copyright holder nor the names of any +//contributors may be used to endorse or promote products derived from +//this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +#include +#include + +namespace System +{ + namespace Net + { + AddressFamily_t DnsEndPoint::getAddressFamily() const + { + return addressFamily; + } + + const String DnsEndPoint::getHost() const + { + return host; + } + + int DnsEndPoint::getPort() const + { + return port; + } + + DnsEndPoint::DnsEndPoint(const String& host, const int port) + : addressFamily(AddressFamily::Unspecified), host(host), port(port) + { + sassert(host != String::Empty, ""); + sassert(port >= 0 && port <= 65535, ""); + } + + DnsEndPoint::DnsEndPoint(const String& host, const int port, AddressFamily_t addressFamily) + : addressFamily(addressFamily), host(host), port(port) + { + sassert(host != String::Empty, ""); + sassert(port >= 0 && port <= 65535, ""); + sassert(addressFamily != AddressFamily::Unknown, ""); + } + + bool DnsEndPoint::Equals(Object const * const obj) const + { + if (is(this, obj)) + { + DnsEndPoint * other = (DnsEndPoint *)obj; + + return host == other->host && port == other->port && addressFamily == other->addressFamily; + } + + return false; + } + + int DnsEndPoint::GetHashCode() const + { + return host.GetHashCode() + port + (int)addressFamily; + } + + const String DnsEndPoint::ToString() const + { + const char * formatString = "%s/%s:%i"; + + switch (addressFamily) + { + case AddressFamily::InterNetwork: + return String::Format(formatString, (const char *)host, port, "InterNetwork"); + case AddressFamily::InterNetworkV6: + return String::Format(formatString, (const char *)host, port, "InterNetworkV6"); + case AddressFamily::Unknown: + return String::Format(formatString, (const char *)host, port, "Unknown"); + case AddressFamily::Unspecified: + return String::Format(formatString, (const char *)host, port, "Unspecified"); + } + } + } +} diff --git a/src/libSystem/EndPoint.cpp b/src/libSystem/EndPoint.cpp new file mode 100644 index 0000000..608ed85 --- /dev/null +++ b/src/libSystem/EndPoint.cpp @@ -0,0 +1,68 @@ +// Copyright (C) XFX Team +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +//* Redistributions of source code must retain the above copyright +//notice, this list of conditions and the following disclaimer. +//* Redistributions in binary form must reproduce the above copyright +//notice, this list of conditions and the following disclaimer in the +//documentation and/or other materials provided with the distribution. +//* Neither the name of the copyright holder nor the names of any +//contributors may be used to endorse or promote products derived from +//this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +#include +#include + +namespace System +{ + namespace Net + { + const Type EndPointTypeInfo("EndPoint", "System::Net::EndPoint", TypeCode::Object); + + EndPoint::EndPoint() + { + } + + EndPoint::~EndPoint() + { + } + + AddressFamily_t EndPoint::getAddressFamily() const + { + // TODO: implement + return AddressFamily::Unspecified; + } + + EndPoint* EndPoint::Create(SocketAddress * const socketAddress) + { + // TODO: implement + return NULL; + } + + const Type& EndPoint::GetType() + { + return EndPointTypeInfo; + } + + SocketAddress* EndPoint::Serialize() + { + // TODO: implement + return NULL; + } + } +} diff --git a/src/libSystem/IPAddress.cpp b/src/libSystem/IPAddress.cpp new file mode 100644 index 0000000..43df83f --- /dev/null +++ b/src/libSystem/IPAddress.cpp @@ -0,0 +1,63 @@ +// Copyright (C) XFX Team +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +//* Redistributions of source code must retain the above copyright +//notice, this list of conditions and the following disclaimer. +//* Redistributions in binary form must reproduce the above copyright +//notice, this list of conditions and the following disclaimer in the +//documentation and/or other materials provided with the distribution. +//* Neither the name of the copyright holder nor the names of any +//contributors may be used to endorse or promote products derived from +//this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +#include + +namespace System +{ + namespace Net + { + const IPAddress IPAddress::Loopback(0x7F000001); + + int IPAddress::HostToNetworkOrder(int host) + { +#if ENABLE_XBOX + return (((host & 0xFF) << 24) | ((host >> 8) & 0xFF) << 16 | ((host >> 16) & 0xFF) << 8 | (host >> 24) & 0xFF); +#else +#endif + } + + long long IPAddress::HostToNetworkOrder(long long host) + { +#if ENABLE_XBOX + return (((host & 0xFF) << 56) | ((host >> 8) & 0xFF) << 48 | + ((host >> 16) & 0xFF) << 40 | ((host >> 24) & 0xFF) << 32 | + ((host >> 32) & 0xFF) << 24 | ((host >> 40) & 0xFF) << 16 | + ((host >> 48) & 0xFF) << 8 | (host >> 56) & 0xFF); +#else +#endif + } + + short IPAddress::HostToNetworkOrder(short host) + { +#if ENABLE_XBOX + return (((host & 0xFF) << 8) | ((host >> 8) & 0xFF)); +#else +#endif + } + } +} diff --git a/src/libSystem/IPEndPoint.cpp b/src/libSystem/IPEndPoint.cpp new file mode 100644 index 0000000..64f7f37 --- /dev/null +++ b/src/libSystem/IPEndPoint.cpp @@ -0,0 +1,69 @@ +// Copyright (C) XFX Team +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +//* Redistributions of source code must retain the above copyright +//notice, this list of conditions and the following disclaimer. +//* Redistributions in binary form must reproduce the above copyright +//notice, this list of conditions and the following disclaimer in the +//documentation and/or other materials provided with the distribution. +//* Neither the name of the copyright holder nor the names of any +//contributors may be used to endorse or promote products derived from +//this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +#include + +#include + +namespace System +{ + namespace Net + { + IPAddress IPEndPoint::getAddress() const + { + return address; + } + + AddressFamily_t IPEndPoint::getAddressFamily() const + { + // TODO: verify + return address.getAddressFamily(); + } + + int IPEndPoint::getPort() const + { + return port; + } + + void IPEndPoint::setPort(const int value) + { + // TODO: error messages + sassert(value >= MinPort, ""); + sassert(value <= MaxPort, ""); + + port = value; + } + + IPEndPoint::IPEndPoint(const long long address, const int port) + : address(address), port(port) + { + // TODO: error messages + sassert(port >= MinPort, ""); + sassert(port <= MaxPort, ""); + } + } +} diff --git a/src/libSystem/NetworkChange.cpp b/src/libSystem/NetworkChange.cpp new file mode 100644 index 0000000..f6da657 --- /dev/null +++ b/src/libSystem/NetworkChange.cpp @@ -0,0 +1,47 @@ +// Copyright (C) XFX Team +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +//* Redistributions of source code must retain the above copyright +//notice, this list of conditions and the following disclaimer. +//* Redistributions in binary form must reproduce the above copyright +//notice, this list of conditions and the following disclaimer in the +//documentation and/or other materials provided with the distribution. +//* Neither the name of the copyright holder nor the names of any +//contributors may be used to endorse or promote products derived from +//this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +#include + +namespace System +{ + namespace Net + { + namespace NetworkInformation + { + NetworkChange::NetworkChange() + { + // TODO: implement + } + + NetworkChange::~NetworkChange() + { + // TODO: implement + } + } + } +} diff --git a/src/libSystem/NetworkInterface.cpp b/src/libSystem/NetworkInterface.cpp new file mode 100644 index 0000000..fa7ed36 --- /dev/null +++ b/src/libSystem/NetworkInterface.cpp @@ -0,0 +1,52 @@ +// Copyright (C) XFX Team +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +//* Redistributions of source code must retain the above copyright +//notice, this list of conditions and the following disclaimer. +//* Redistributions in binary form must reproduce the above copyright +//notice, this list of conditions and the following disclaimer in the +//documentation and/or other materials provided with the distribution. +//* Neither the name of the copyright holder nor the names of any +//contributors may be used to endorse or promote products derived from +//this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +#include + +namespace System +{ + namespace Net + { + namespace NetworkInformation + { + NetworkInterface::NetworkInterface() + { + // TODO: implement + } + + NetworkInterface::~NetworkInterface() + { + // TODO: implement + } + + bool NetworkInterface::GetIsNetworkAvailable() + { + // TODO: implement + } + } + } +} diff --git a/src/libSystem/Socket.cpp b/src/libSystem/Socket.cpp index b8fae76..6ac5ea3 100644 --- a/src/libSystem/Socket.cpp +++ b/src/libSystem/Socket.cpp @@ -30,6 +30,11 @@ #include #include +#include +#include +#include +#include + using namespace System::Threading; namespace System @@ -40,32 +45,37 @@ namespace System { const Type SocketTypeInfo("Socket","System::Net::Sockets", TypeCode::Object); - AddressFamily_t Socket::getAddressFamily() + AddressFamily_t Socket::getAddressFamily() const { return addressFamily; } - HANDLE Socket::getHandle() + int Socket::Available() const + { + // TODO: implement + } + + bool Socket::Connected() const + { + // TODO: implement + } + + HANDLE Socket::getHandle() const { return handle; } + ProtocolType_t Socket::getProtocolType() const + { + // TODO: implement + } + Socket::Socket(AddressFamily_t addressFamily, SocketType_t socketType, ProtocolType_t protocolType) : addressFamily(addressFamily) { // TODO: implement remainder } - bool Socket::ConnectAsync(SocketType_t socketType, ProtocolType_t protocolType, SocketAsyncEventArgs e) - { - // TODO: implement - } - - bool Socket::ConnectAsync(SocketAsyncEventArgs e) - { - // TODO: implement - } - void Socket::Close() { // TODO: implement @@ -76,6 +86,16 @@ namespace System // TODO: implement } + bool Socket::ConnectAsync(SocketType_t socketType, ProtocolType_t protocolType, SocketAsyncEventArgs e) + { + // TODO: implement + } + + bool Socket::ConnectAsync(SocketAsyncEventArgs e) + { + // TODO: implement + } + void Socket::Dispose() { // TODO: implement @@ -95,6 +115,31 @@ namespace System { return SocketTypeInfo; } + + bool Socket::ReceiveAsync(SocketAsyncEventArgs e) + { + // TODO: implement + } + + bool Socket::ReceiveFromAsync(SocketAsyncEventArgs e) + { + // TODO: implement + } + + bool Socket::SendAsync(SocketAsyncEventArgs e) + { + // TODO: implement + } + + bool Socket::SendToAsync(SocketAsyncEventArgs e) + { + // TODO: implement + } + + void Socket::Shutdown(SocketShutdown_t how) + { + // TODO: implement + } } } } diff --git a/src/libSystem/SocketAsyncEventArgs.cpp b/src/libSystem/SocketAsyncEventArgs.cpp index ca50d04..f85b9d7 100644 --- a/src/libSystem/SocketAsyncEventArgs.cpp +++ b/src/libSystem/SocketAsyncEventArgs.cpp @@ -36,14 +36,49 @@ namespace System { const Type SocketAsyncEventArgsTypeInfo("SocketAsyncEventArgs", "SYstem::Net::Sockets::SocketAsyncEventArgs", TypeCode::Object); + byte * SocketAsyncEventArgs::getBuffer() const + { + // TODO: implement + } + + int SocketAsyncEventArgs::getBytesTransferred() const + { + // TODO: implement + } + + Socket * SocketAsyncEventArgs::getConnectSocket() const + { + // TODO: implement + } + + int SocketAsyncEventArgs::Count() const + { + // TODO: implement + } + + SocketAsyncOperation_t SocketAsyncEventArgs::getLastOperation() const + { + // TODO: implement + } + + int SocketAsyncEventArgs::getOffset() const + { + // TODO: implement + } + SocketAsyncEventArgs::SocketAsyncEventArgs() { - // TODO; implement + // TODO: implement + } + + SocketAsyncEventArgs::SocketAsyncEventArgs() + { + // TODO: implement } void SocketAsyncEventArgs::Dispose() { - // TODO; implement + // TODO: implement } const Type& SocketAsyncEventArgs::GetType() diff --git a/src/libSystem/libSystem.vcxproj b/src/libSystem/libSystem.vcxproj index 7ce272a..d4a505d 100644 --- a/src/libSystem/libSystem.vcxproj +++ b/src/libSystem/libSystem.vcxproj @@ -73,6 +73,12 @@ + + + + + + @@ -82,7 +88,13 @@ + + + + + + diff --git a/src/libSystem/libSystem.vcxproj.filters b/src/libSystem/libSystem.vcxproj.filters index 962c130..075c835 100644 --- a/src/libSystem/libSystem.vcxproj.filters +++ b/src/libSystem/libSystem.vcxproj.filters @@ -37,6 +37,12 @@ {0b37cc7b-fbd5-4d60-8e8d-99f0bde53754} + + {4dd42056-0af1-42e9-a43e-ad43f0b180b5} + + + {6467ba65-207e-4e88-aa08-ce970dd66c90} + @@ -57,6 +63,24 @@ Source Files\Diagnostics + + Source Files\Net + + + Source Files\Net + + + Source Files\Net\NetworkInformation + + + Source Files\Net\NetworkInformation + + + Source Files\Net + + + Source Files\Net + @@ -80,6 +104,24 @@ Header Files\Net\Sockets + + Header Files\Net + + + Header Files\Net + + + Header Files\Net\NetworkInformation + + + Header Files\Net\NetworkInformation + + + Header Files\Net + + + Header Files\Net + diff --git a/src/libSystem/makefile b/src/libSystem/makefile index 9de677e..272fb2f 100644 --- a/src/libSystem/makefile +++ b/src/libSystem/makefile @@ -26,7 +26,7 @@ LD_FLAGS = $(CLINK) $(ALIGN) $(SHARED) $(ENTRYPOINT) $(STRIP) 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++ -OBJS = CancelEventArgs.o Debug.o Socket.o SocketAddress.o SocketAsyncEventArgs.o Stopwatch.o +OBJS = CancelEventArgs.o Debug.o DnsEndPoint.o EndPoint.o IPAddress.o IPEndPoint.o NetworkChange.o NetworkInterface.o Socket.o SocketAddress.o SocketAsyncEventArgs.o Stopwatch.o all: libSystem.a diff --git a/src/libXFX/Curve.cpp b/src/libXFX/Curve.cpp index bdce648..156a14a 100644 --- a/src/libXFX/Curve.cpp +++ b/src/libXFX/Curve.cpp @@ -169,7 +169,7 @@ namespace XFX // start-> end / end -> start cycle = GetNumberOfCycle(position); - if (0 == cycle % 2f)//if pair + if (0 == cycle % 2)//if pair { virtualPos = position - (cycle * (last.getPosition() - first.getPosition())); } diff --git a/src/libXFX/makefile b/src/libXFX/makefile index c12a70b..56cfb2e 100644 --- a/src/libXFX/makefile +++ b/src/libXFX/makefile @@ -30,7 +30,7 @@ OBJS = BoundingBox.o BoundingFrustum.o BoundingSphere.o MathHelper.o Matrix.o Pl AUDIO_OBJS = SoundEffect.o SoundEffectInstance.o #CONTENT_OBJS = ContentManager.o ContentReader.o GAMERSERVICES_OBJS = Guide.o StorageDeviceAsyncResult.o -GRAPHICS_OBJS = BasicEffect.o BlendState.o Color.o DisplayMode.o DisplayModeCollection.o Effect.o GraphicsAdapter.o GraphicsDevice.o GraphicsResource.o IGraphicsDeviceService.o pbKit.o PresentationParameters.o Sprite.o SpriteBatch.o SpriteFont.o StateBlock.o Texture.o Texture2D.o TextureCollection.o VertexElement.o VertexPositionColor.o VertexPositionNormalTexture.o VertexPositionTexture.o Viewport.o +GRAPHICS_OBJS = BasicEffect.o BlendState.o Color.o Curve.o CurveKey.o CurveKeyCollection.o DisplayMode.o DisplayModeCollection.o Effect.o GraphicsAdapter.o GraphicsDevice.o GraphicsResource.o IGraphicsDeviceService.o pbKit.o PresentationParameters.o Sprite.o SpriteBatch.o SpriteFont.o StateBlock.o Texture.o Texture2D.o TextureCollection.o VertexElement.o VertexPositionColor.o VertexPositionNormalTexture.o VertexPositionTexture.o Viewport.o INPUT_OBJS = GamePad.o Keyboard.o Mouse.o MEDIA_OBJS = VideoPlayer.o NET_OBJS = PacketReader.o PacketWriter.o @@ -55,6 +55,5 @@ libXFX.a: $(OBJS1) .s.o: $(CCAS) -c $< $(CCAS_FLAGS) -clean: +clean: rm -f *.o *.exe *.dll *.xbe *.cxbe *.lib *.a - \ No newline at end of file diff --git a/src/libmscorlib/DateTime.cpp b/src/libmscorlib/DateTime.cpp index d66b107..bdfa370 100644 --- a/src/libmscorlib/DateTime.cpp +++ b/src/libmscorlib/DateTime.cpp @@ -40,7 +40,7 @@ namespace System { // Encodes the DateTime in 64 bits, top two bits contain the DateTimeKind, - // the rest contains the 62 bit value for the ticks. This reduces the + // the rest contains the 62 bit value for the ticks. This reduces the // memory usage from 16 to 8 bytes. // const long long DateTime::TicksMask = 0x3fffffffffffffffLL; @@ -77,7 +77,10 @@ namespace System days = (IsLeapYear(year) ? daysmonthleap : daysmonth); while (m < month) + { temp += days[m++]; + } + return ((day-1) + temp + (365* (year-1)) + ((year-1)/4) - ((year-1)/100) + ((year-1)/400)); } @@ -92,6 +95,7 @@ namespace System DateTime DateTime::Add(double value, int scale) { long long num = (long long)((value * scale) + ((value >= 0.0) ? 0.5 : -0.5)); + if ((num <= -315537897600000LL) || (num >= 0x11efae44cb400LL)) { #if DEBUG @@ -134,14 +138,20 @@ namespace System DateTime::DateTime(long long ticks) { if (ticks < 0 || ticks > MAX_VALUE_TICKS) + { InvalidTickValue(ticks); + } + encoded = ticks; } DateTime::DateTime(long long ticks, DateTimeKind_t kind) { if (ticks < 0 || ticks > MAX_VALUE_TICKS) + { InvalidTickValue(ticks); + } + sassert(!(kind < 0 || kind > DateTimeKind::Local), "kind is an invalid DateTimeKind value."); encoded = ((long long)kind << KindShift) | ticks; @@ -190,9 +200,13 @@ namespace System month = month -12; year++; } + maxday = DaysInMonth(year, month); + if (day > maxday) + { day = maxday; + } DateTime temp = DateTime(year, month, day); temp.encoded |= encoded & KindMask; @@ -277,7 +291,9 @@ namespace System sassert(!((d <= OAMinValue) || (d >= OAMaxValue)), ""); DateTime dt = DateTime(ticks18991230); - if (d < 0.0) { + + if (d < 0.0) + { double days = Math::Ceiling(d); // integer part is the number of days (negative) dt = dt.AddMilliseconds(days * 86400000); @@ -285,7 +301,8 @@ namespace System double hours = (days - d); dt = dt.AddMilliseconds(hours * 86400000); } - else { + else + { dt = dt.AddMilliseconds(d * 86400000); } @@ -305,7 +322,10 @@ namespace System bool DateTime::IsDaylighSavingTime() { if ((int)((ulong)encoded >> KindShift) == (int)DateTimeKind::Utc) + { return false; + } + return TimeZone::CurrentTimeZone().IsDaylightSavingTime(*this); } @@ -352,15 +372,22 @@ namespace System double DateTime::ToOADate() { long long t = Ticks(); + // uninitialized DateTime case if (t == 0) + { return 0; + } + // we can't reach minimum value if (t < 31242239136000000LL) + { return OAMinValue + 0.001; + } TimeSpan ts = TimeSpan(Ticks() - ticks18991230); double result = ts.TotalDays(); + // t < 0 (where 599264352000000000 == 0.0d for OA) if (t < 599264352000000000LL) { @@ -372,8 +399,11 @@ namespace System { // we can't reach maximum value if (result >= OAMaxValue) + { result = OAMaxValue - 0.00000001; + } } + return result; } @@ -392,6 +422,7 @@ namespace System DateTime DateTime::operator +(TimeSpan other) { long long res = ((encoded & TicksMask) + other.Ticks()); + if (res < 0 || res > MAX_VALUE_TICKS) { #if DEBUG @@ -399,7 +430,7 @@ namespace System #endif return DateTime(0); } - + return DateTime(res, Kind()); } @@ -441,6 +472,7 @@ namespace System DateTime DateTime::operator -(TimeSpan t) { long long res = ((encoded & TicksMask) - t.Ticks()); + if (res < 0 || res > MAX_VALUE_TICKS) { #if DEBUG diff --git a/src/libmscorlib/Object.cpp b/src/libmscorlib/Object.cpp index 4335a76..4bb4ab7 100644 --- a/src/libmscorlib/Object.cpp +++ b/src/libmscorlib/Object.cpp @@ -54,20 +54,12 @@ namespace System return ObjectTypeInfo; } - bool Object::ReferenceEquals(const Object& objA, const Object& objB) - { - return (&objA == &objB); - } - - const String Object::ToString() const - { - return "Object"; - } - bool is(Object const * const obj1, Object const * const obj2) { if ((obj1 == NULL) && (obj2 == NULL)) + { return true; + } if ((obj1 != NULL) && (obj2 != NULL)) { @@ -77,12 +69,13 @@ namespace System return false; } - template - U * as(T * const source) + bool Object::ReferenceEquals(const Object& objA, const Object& objB) { - int typeCode = T::GetType(); // make sure source is an Object - int destTypeCode = U::GetType(); // same here, but now for U + return (&objA == &objB); + } - return (typeCode == destTypeCode) ? (U *)source : NULL; + const String Object::ToString() const + { + return "Object"; } } diff --git a/src/libmscorlib/Type.cpp b/src/libmscorlib/Type.cpp index b66ac3d..885e637 100644 --- a/src/libmscorlib/Type.cpp +++ b/src/libmscorlib/Type.cpp @@ -1,4 +1,31 @@ -#include +// Copyright (C) XFX Team +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of the copyright holder nor the names of any +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +#include namespace System { @@ -24,6 +51,7 @@ namespace System const String Type::ToString() const { + return FullName; } bool Type::operator ==(const Type& right) const