summaryrefslogtreecommitdiffstats
path: root/kcachegrind/kcachegrind/stackbrowser.h
blob: 7e7677fe9a0bc7f840b3302c196edbb2f0485dea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* This file is part of KCachegrind.
   Copyright (C) 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>

   KCachegrind is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation, version 2.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef STACKBROWSER_H
#define STACKBROWSER_H

#include "tracedata.h"

// A history of selected functions within stacks

class Stack
{
public:
  Stack(TraceFunction*);

  // extend the stack at top/bottom if possible
  bool tqcontains(TraceFunction*);

  void extendBottom();
  void extendTop();

  // search for a function on stack calling specified function.
  // if found, return upper part with new function call
  Stack* split(TraceFunction*);

  // increment reference count
  void ref() { _refCount++; }
  // decrement reference count
  bool deref() { return --_refCount; }
  int refCount() { return _refCount; }

  TraceFunction* top() { return _top; }
  TraceCallList calls() { return _calls; }
  TraceFunction* caller(TraceFunction*, bool extend);
  TraceFunction* called(TraceFunction*, bool extend);

  TQString toString();

private:
  Stack(TraceFunction* top, TraceCallList list);

  // at the top of the stack we have a function...
  TraceFunction* _top;
  // list ordered from top to bottom
  TraceCallList _calls;
  int _refCount;
};

class HistoryItem
{
public:
  HistoryItem(Stack*, TraceFunction*);
  ~HistoryItem();

  Stack* stack() { return _stack; }
  TraceFunction* function() { return _function; }
  HistoryItem* last() { return _last; }
  HistoryItem* next() { return _next; }
  void setLast(HistoryItem* h) { _last = h; }
  void setNext(HistoryItem* h) { _next = h; }

private:

  HistoryItem *_last, *_next;
  Stack* _stack;
  TraceFunction* _function;
};


class StackBrowser
{
public:
  StackBrowser();
  ~StackBrowser();

  // A function was selected. This creates a new history entry
  HistoryItem* select(TraceFunction*);

  HistoryItem* current() { return _current; }
  bool canGoBack();
  bool canGoForward();
  bool canGoUp();
  bool canGoDown();
  HistoryItem* goBack();
  HistoryItem* goForward();
  HistoryItem* goUp();
  HistoryItem* goDown();

private:
  HistoryItem* _current;
};


#endif