File indexing completed on 2024-05-05 05:44:21
0001 /* 0002 This file is part of KCachegrind. 0003 0004 SPDX-FileCopyrightText: 2002-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> 0005 0006 SPDX-License-Identifier: GPL-2.0-only 0007 */ 0008 0009 #ifndef ADDR_H 0010 #define ADDR_H 0011 0012 #include <QString> 0013 0014 #include "utils.h" 0015 0016 /** 0017 * Addresses are 64bit values like costs to be able 0018 * to always load profile data produced on 64bit 0019 * architectures. 0020 */ 0021 class Addr 0022 { 0023 public: 0024 Addr() { _v=0; } 0025 // no "explicit": we want implicit conversion 0026 Addr(uint64 v) { _v = v; } 0027 0028 // Interprets char data at s as hex (without "0x" prefix) 0029 // and return number of interpreted chars. 0030 int set(const char *s); 0031 bool set(FixString& s); 0032 QString toString() const; 0033 // similar to toString(), but adds a space every 4 digits 0034 QString pretty() const; 0035 0036 // returns true if this address is in [a-distance;a+distance] 0037 bool isInRange(Addr a, int distance); 0038 0039 bool operator==(const Addr& a) const { return (_v == a._v); } 0040 bool operator!=(const Addr& a) const { return (_v != a._v); } 0041 bool operator>(const Addr& a) const { return _v > a._v; } 0042 bool operator>=(const Addr& a) const { return _v >= a._v; } 0043 bool operator<(const Addr& a) const { return _v < a._v; } 0044 bool operator<=(const Addr& a) const { return _v <= a._v; } 0045 0046 Addr operator+(int d) const { return Addr(_v + d); } 0047 Addr operator-(int d) const { return Addr(_v - d); } 0048 0049 // return decremented address until it is a multiple of <a>, a power of 2 0050 Addr alignedDown(int a) { return Addr(_v & ~( ((uint64)a) -1)); } 0051 0052 private: 0053 uint64 _v; 0054 }; 0055 0056 #endif // ADDR_H