Created
April 15, 2017 00:45
-
-
Save exjam/f92fc17122f3541b74f3d354e6e74e24 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <cstdint> | |
namespace cpu | |
{ | |
template<class Type> | |
class Address | |
{ | |
public: | |
using StorageType = uint32_t; | |
constexpr Address() = default; | |
constexpr explicit Address(StorageType address) : | |
mAddress(address) | |
{ | |
} | |
constexpr bool operator == (const Address &other) const | |
{ | |
return mAddress == other.mAddress; | |
} | |
constexpr bool operator != (const Address &other) const | |
{ | |
return mAddress != other.mAddress; | |
} | |
constexpr bool operator >= (const Address &other) const | |
{ | |
return mAddress >= other.mAddress; | |
} | |
constexpr bool operator <= (const Address &other) const | |
{ | |
return mAddress <= other.mAddress; | |
} | |
constexpr bool operator > (const Address &other) const | |
{ | |
return mAddress > other.mAddress; | |
} | |
constexpr bool operator < (const Address &other) const | |
{ | |
return mAddress < other.mAddress; | |
} | |
constexpr Address &operator += (ptrdiff_t value) | |
{ | |
mAddress = static_cast<StorageType>(mAddress + value); | |
return *this; | |
} | |
constexpr Address &operator -= (ptrdiff_t value) | |
{ | |
mAddress = static_cast<StorageType>(mAddress - value); | |
return *this; | |
} | |
constexpr Address operator + (ptrdiff_t value) const | |
{ | |
return Address { static_cast<StorageType>(mAddress + value) }; | |
} | |
constexpr ptrdiff_t operator -(const Address &other) const | |
{ | |
return mAddress - other.mAddress; | |
} | |
constexpr ptrdiff_t operator -(ptrdiff_t value) const | |
{ | |
return mAddress - value; | |
} | |
constexpr StorageType getAddress() const | |
{ | |
return mAddress; | |
} | |
private: | |
StorageType mAddress = 0; | |
}; | |
class Physical; | |
class Virtual; | |
using PhysicalAddress = Address<Physical>; | |
using VirtualAddress = Address<Virtual>; | |
} // namespace cpu |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment