Guest User

Untitled

a guest
Apr 1st, 2013
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #ifndef PTR32_H
  2. #define PTR32_H
  3.  
  4. #include <stdint.h>
  5.  
  6. #include "assert.h"
  7.  
  8. template <typename T>
  9. class ptr32
  10. {
  11. private:
  12.     uint32_t raw;
  13.  
  14. public:
  15.     ptr32() { }
  16.    
  17.     ptr32(uintptr_t v) {
  18.         if (sizeof(v) > sizeof(uint32_t))
  19.             assert(v <= 0xffffffff);
  20.         raw = v;
  21.     }
  22.  
  23.     ptr32<T> operator= (T* v) {
  24.         if (sizeof(v) > sizeof(uint32_t))
  25.             assert(v <= (T*)0xffffffff);
  26.         raw = (uint32_t)(uintptr_t)v;
  27.         return *this;
  28.     }
  29.    
  30.     operator T* () { return (T*)(uintptr_t)raw; }
  31.    
  32.     template <typename U>
  33.     U cast() { return (U)(uintptr_t)raw; }
  34. };
  35.  
  36. #endif /* PTR32_H */
Advertisement
Add Comment
Please, Sign In to add comment