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