Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 2 | |
| 3 | #ifndef ART_SRC_OFFSETS_H_ |
| 4 | #define ART_SRC_OFFSETS_H_ |
| 5 | |
| 6 | #include <iostream> // NOLINT |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 7 | #include "globals.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 8 | |
| 9 | namespace art { |
| 10 | |
| 11 | // Allow the meaning of offsets to be strongly typed |
| 12 | class Offset { |
| 13 | public: |
| 14 | explicit Offset(size_t val) : val_(val) {} |
| 15 | int32_t Int32Value() const { |
| 16 | return static_cast<int32_t>(val_); |
| 17 | } |
| 18 | uint32_t Uint32Value() const { |
| 19 | return static_cast<uint32_t>(val_); |
| 20 | } |
| 21 | protected: |
| 22 | size_t val_; |
| 23 | }; |
| 24 | std::ostream& operator<<(std::ostream& os, const Offset& offs); |
| 25 | |
| 26 | // Offsets relative to the current frame |
| 27 | class FrameOffset : public Offset { |
| 28 | public: |
| 29 | explicit FrameOffset(size_t val) : Offset(val) {} |
| 30 | bool operator>(FrameOffset other) const { return val_ > other.val_; } |
| 31 | bool operator<(FrameOffset other) const { return val_ < other.val_; } |
| 32 | }; |
| 33 | |
| 34 | // Offsets relative to the current running thread |
| 35 | class ThreadOffset : public Offset { |
| 36 | public: |
| 37 | explicit ThreadOffset(size_t val) : Offset(val) {} |
| 38 | }; |
| 39 | |
| 40 | // Offsets relative to an object |
| 41 | class MemberOffset : public Offset { |
| 42 | public: |
| 43 | explicit MemberOffset(size_t val) : Offset(val) {} |
| 44 | }; |
| 45 | |
| 46 | } // namespace art |
| 47 | |
| 48 | #endif // ART_SRC_OFFSETS_H_ |