6 template<class T> // big endian pointer
10 typedef be_ptr<T> my_type;
12 typedef T* pointer_type;
18 unsigned long *lp = (unsigned long *)((void *) &ptr);
19 printf ("%08lx", *lp);
25 // constructor element template: constructs be_ptr from any other be_ptr
26 // Bug: too few warnings when incompatible be_ptrs are assigned
28 explicit be_ptr (const be_ptr<C> &p) : ptr (p.ptr) {}
30 // explicit: this constructor is not used
31 // for automatic type promotion
32 // reinterpret_cast: required to cast pointer_type to uae_ptr,
33 // which is actually a long.
34 explicit be_ptr (const pointer_type p) : ptr (reinterpret_cast<uae_ptr> (p)) {}
36 // reinterpret_cast: required to cast void * to uae_ptr,
37 // which is actually a long.
38 be_ptr (void *p) : ptr (reinterpret_cast<uae_ptr> (p)) {}
40 // static_cast returns a native endian uae_ptr (long) and
41 // reinterpret_cast is required to cast it into a void *.
42 inline operator void * ()
44 return reinterpret_cast<void *> (static_cast<uae_ptr> (ptr));
47 // same as above for C*
48 // Bug: too few warnings when incompatible be_ptrs are assigned
52 return reinterpret_cast<C*> (static_cast<uae_ptr> (ptr));
55 // same as above for const C*
56 // Bug: too few warnings when incompatible be_ptrs are assigned
58 operator const C* () const
60 return reinterpret_cast<const C*> (static_cast<uae_ptr> (ptr));
63 // cast the object itself into a native endian pointer
64 // using the pointer_type method above.
65 value_type& operator* ()
67 return *(static_cast<pointer_type> (*this));
70 // same as above but without indirection
71 pointer_type operator-> ()
73 return static_cast<pointer_type> (*this);
76 // assigns a native endian pointer (of pointer_type)
78 const my_type& operator= (const pointer_type p)
84 // assigns another big endian pointer of any type
87 const my_type& operator= (const be_ptr<C>& other)
93 value_type& operator[] (size_t dist) // index operator
95 return *(*this + dist);
98 const my_type& operator++ () // pre increment operator
103 const my_type operator++ (int) // post increment operator
109 const my_type& operator-- () // pre increment operator
114 const my_type operator-- (int) // post increment operator
120 const my_type& operator+= (const size_t dist)
124 const my_type& operator-= (const size_t dist)
128 my_type operator+ (const size_t dist)
134 my_type operator- (const size_t dist)
144 // required for the constructor element template
149 template<> // specialization for void pointer
153 typedef be_ptr<void> my_type;
154 typedef void* pointer_type;
155 typedef const void* const_pointer_type;
161 unsigned long *lp = (unsigned long *)((void *) &ptr);
162 printf ("%08lx", *lp);
168 be_ptr (const pointer_type p) : ptr (reinterpret_cast<uae_ptr> (p)) {}
170 operator const_pointer_type () const
172 return reinterpret_cast<pointer_type> (static_cast<uae_ptr> (ptr));
174 operator pointer_type ()
176 return reinterpret_cast<pointer_type> (static_cast<uae_ptr> (ptr));
178 const my_type& operator= (const pointer_type p)
189 inline size_t operator- (const be_ptr<T>& a, const be_ptr<T>& b)
191 return static_cast<T*> (a) - static_cast<T*> (b);