FixedWidthPointer: Fix ==/!= operators, remove OtherType casts
* FixedWidthPointer:
- operators ==/!=: Change second operand type from void* to const
Type*. Also add non-const version to resolve ambiguity warning when
comparing with non-const pointer.
- Add Pointer() getter.
- Remove templatized cast operators. They are nice for casting the
pointer directly to another pointer type, but result in ambiguity.
* Make preloaded_image::debug_string_table non-const. Avoids clashes of
the const and non-coast FixedWidthPointer comparison operators. A
cleaner (but more verbose) solution would be to spezialize
FixedWidthPointer for const types.
This commit is contained in:
committed by
Alex Smith
parent
ccadfaeeb5
commit
69a8b95491
@@ -20,30 +20,29 @@
|
||||
template<typename Type>
|
||||
class FixedWidthPointer {
|
||||
public:
|
||||
operator Type*() const
|
||||
Type * Pointer() const
|
||||
{
|
||||
return (Type*)(addr_t)fValue;
|
||||
}
|
||||
|
||||
template<typename OtherType>
|
||||
operator OtherType*() const
|
||||
operator Type*() const
|
||||
{
|
||||
return static_cast<OtherType*>((Type*)(addr_t)fValue);
|
||||
return Pointer();
|
||||
}
|
||||
|
||||
Type& operator*() const
|
||||
{
|
||||
return *((Type*)(addr_t)fValue);
|
||||
return *Pointer();
|
||||
}
|
||||
|
||||
Type* operator->() const
|
||||
{
|
||||
return (Type*)(addr_t)fValue;
|
||||
return Pointer();
|
||||
}
|
||||
|
||||
Type& operator[](size_t i) const
|
||||
{
|
||||
return ((Type*)(addr_t)fValue)[i];
|
||||
return Pointer()[i];
|
||||
}
|
||||
|
||||
FixedWidthPointer& operator=(const FixedWidthPointer& p)
|
||||
@@ -85,15 +84,14 @@ private:
|
||||
template<>
|
||||
class FixedWidthPointer<void> {
|
||||
public:
|
||||
operator void*() const
|
||||
void * Pointer() const
|
||||
{
|
||||
return (void*)(addr_t)fValue;
|
||||
}
|
||||
|
||||
template<typename OtherType>
|
||||
operator OtherType*() const
|
||||
operator void*() const
|
||||
{
|
||||
return (OtherType*)(addr_t)fValue;
|
||||
return Pointer();
|
||||
}
|
||||
|
||||
FixedWidthPointer& operator=(const FixedWidthPointer& p)
|
||||
@@ -122,16 +120,34 @@ private:
|
||||
uint64 fValue;
|
||||
} _PACKED;
|
||||
|
||||
|
||||
template<typename Type>
|
||||
inline bool
|
||||
operator==(const FixedWidthPointer<Type>& a, void* b)
|
||||
operator==(const FixedWidthPointer<Type>& a, const Type* b)
|
||||
{
|
||||
return a.Get() == (addr_t)b;
|
||||
}
|
||||
|
||||
|
||||
template<typename Type>
|
||||
inline bool
|
||||
operator!=(const FixedWidthPointer<Type>& a, void* b)
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user