2013-05-30 21:42:33 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* Object.h *
|
|
|
|
* *
|
|
|
|
* XFX Object definition file *
|
|
|
|
* Copyright (c) XFX Team. All Rights Reserved *
|
|
|
|
*****************************************************************************/
|
2013-05-05 18:18:41 +02:00
|
|
|
#ifndef _SYSTEM_OBJECT_
|
|
|
|
#define _SYSTEM_OBJECT_
|
|
|
|
|
2014-07-14 15:03:46 +02:00
|
|
|
#include <System/Type.h>
|
|
|
|
|
2013-05-05 18:18:41 +02:00
|
|
|
namespace System
|
|
|
|
{
|
2013-06-02 14:32:43 +02:00
|
|
|
class String;
|
|
|
|
|
2013-05-05 18:18:41 +02:00
|
|
|
// 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.
|
|
|
|
class Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool Equals(Object const * const obj) const;
|
2013-05-30 21:42:33 +02:00
|
|
|
static bool Equals(Object const * const objA, Object const * const objB);
|
2013-05-05 18:18:41 +02:00
|
|
|
virtual int GetHashCode() const;
|
2013-07-12 21:30:13 +02:00
|
|
|
static const Type& GetType();
|
2013-05-05 18:18:41 +02:00
|
|
|
static bool ReferenceEquals(const Object& objA, const Object& objB);
|
2013-07-11 20:00:07 +02:00
|
|
|
virtual const String ToString() const;
|
2013-05-05 18:18:41 +02:00
|
|
|
|
|
|
|
virtual ~Object() { }
|
|
|
|
};
|
|
|
|
|
2014-07-14 15:03:46 +02:00
|
|
|
// syntax: as<[target type]>([source instance])
|
|
|
|
template <typename T *, typename U *>
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-05-05 18:18:41 +02:00
|
|
|
// returns whether the type of obj1 matches that of obj2
|
|
|
|
bool is(Object const * const obj1, Object const * const obj2);
|
2013-05-31 15:58:00 +02:00
|
|
|
|
|
|
|
template<class T, class B> struct Derived_from {
|
|
|
|
static void constraints(T* p) { B* pb = p; }
|
|
|
|
Derived_from() { void(*p)(T*) = constraints; }
|
|
|
|
};
|
2013-05-05 18:18:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif //_SYSTEM_OBJECT_
|