blob: 19c672a515031efc9dbca3b1be26b5012eb20145 [file] [log] [blame]
Carl Shapiro69759ea2011-07-21 18:13:35 -07001// Copyright 2011 Google Inc. All Rights Reserved.
Carl Shapiro69759ea2011-07-21 18:13:35 -07002
3#ifndef ART_SRC_OFFSETS_H_
4#define ART_SRC_OFFSETS_H_
5
6#include <iostream> // NOLINT
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07007#include "globals.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -07008
9namespace art {
10
11// Allow the meaning of offsets to be strongly typed
12class 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};
24std::ostream& operator<<(std::ostream& os, const Offset& offs);
25
26// Offsets relative to the current frame
27class 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
35class ThreadOffset : public Offset {
36 public:
37 explicit ThreadOffset(size_t val) : Offset(val) {}
38};
39
40// Offsets relative to an object
41class 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_