#ifndef KERNEL_UTIL_FIXED_WIDTH_POINTER_H
#define KERNEL_UTIL_FIXED_WIDTH_POINTER_H
#include <SupportDefs.h>
template<typename Type>
class FixedWidthPointer {
public:
Type * Pointer() const
{
return (Type*)(addr_t)fValue;
}
operator Type*() const
{
return Pointer();
}
Type& operator*() const
{
return *Pointer();
}
Type* operator->() const
{
return Pointer();
}
Type& operator[](size_t i) const
{
return Pointer()[i];
}
FixedWidthPointer& operator=(const FixedWidthPointer& p)
{
fValue = p.fValue;
return *this;
}
FixedWidthPointer& operator=(Type* p)
{
fValue = (addr_t)p;
return *this;
}
uint64 Get() const
{
return fValue;
}
void SetTo(uint64 addr)
{
fValue = addr;
}
private:
uint64 fValue;
} _PACKED;
template<>
class FixedWidthPointer<void> {
public:
void * Pointer() const
{
return (void*)(addr_t)fValue;
}
operator void*() const
{
return Pointer();
}
FixedWidthPointer& operator=(const FixedWidthPointer& p)
{
fValue = p.fValue;
return *this;
}
FixedWidthPointer& operator=(void* p)
{
fValue = (addr_t)p;
return *this;
}
uint64 Get() const
{
return fValue;
}
void SetTo(uint64 addr)
{
fValue = addr;
}
private:
uint64 fValue;
} _PACKED;
template<typename Type>
inline bool
operator==(const FixedWidthPointer<Type>& a, const Type* b)
{
return a.Get() == (addr_t)b;
}
template<typename Type>
inline bool
operator!=(const FixedWidthPointer<Type>& a, const Type* b)
{
return a.Get() != (addr_t)b;
}
template<typename Type>
inline bool
operator==(const FixedWidthPointer<Type>& a, Type* b)
{
return a.Get() == (addr_t)b;
}
template<typename Type>
inline bool
operator!=(const FixedWidthPointer<Type>& a, Type* b)
{
return a.Get() != (addr_t)b;
}
#endif