• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

kcachegrind

  • sources
  • kde-4.14
  • kdesdk
  • kcachegrind
  • libcore
utils.h
Go to the documentation of this file.
1 /* This file is part of KCachegrind.
2  Copyright (C) 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
3 
4  KCachegrind is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public
6  License as published by the Free Software Foundation, version 2.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; see the file COPYING. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 /*
20  * Utility classes for KCachegrind
21  */
22 
23 #ifndef UTILS_H
24 #define UTILS_H
25 
26 #include <qstring.h>
27 
28 class QIODevice;
29 
30 typedef unsigned long long uint64;
31 typedef long long int64;
32 
38 class FixString {
39 
40  public:
41  // constructor for an invalid string
42  FixString() { _len = 0; _str = 0; }
43 
49  FixString(const char*, int len);
50 
51  int len() { return _len; }
52  const char* ascii() { return _str; }
53  bool isEmpty() { return _len == 0; }
54  bool isValid() { return _str != 0; }
55 
56  // sets <c> to first character and returns true if length >0
57  bool first(char& c)
58  { if (_len==0) return false; c=_str[0]; return true; }
59 
60  void set(const char* s, int l) { _str=s; _len=l; }
61  bool stripFirst(char&);
62  bool stripPrefix(const char*);
63 
67  void stripSurroundingSpaces();
68 
72  void stripSpaces();
73 
77  bool stripName(FixString&);
78 
82  FixString stripUntil(char);
83 
84  bool stripUInt(uint&, bool stripSpaces = true);
85  bool stripUInt64(uint64&, bool stripSpaces = true);
86  bool stripInt64(int64&, bool stripSpaces = true);
87 
88  operator QString() const
89  { return QString::fromLocal8Bit(_str,_len); }
90 
91  private:
92  const char* _str;
93  int _len;
94 };
95 
96 
100 class FixFile {
101 
102  public:
103  FixFile(QIODevice*, const QString&);
104  ~FixFile();
105 
109  bool nextLine(FixString& str);
110  bool exists() { return !_openError; }
111  unsigned len() { return _len; }
112  unsigned current() { return _current - _base; }
113  bool setCurrent(unsigned pos);
114  void rewind() { setCurrent(0); }
115 
116  private:
117  char *_base, *_current;
118  QByteArray _data;
119  unsigned _len, _currentLeft;
120  bool _used_mmap, _openError;
121  QIODevice* _file;
122  QString _filename;
123 };
124 
125 
130 template<class type>
131 class AppendList {
132 
133  public:
134  AppendList();
135  ~AppendList() { clear(); }
136 
137  void setAutoDelete(bool);
138  void clear();
139  void append(const type*);
140 
141  unsigned count() const { return _count; }
142  unsigned containsRef(const type*) const;
143 
144  type* current();
145  type* first();
146  type* next();
147 
148  private:
149  static const int firstLen = 8;
150  static const int maxLen = 256;
151 
152  struct AppendListChunk {
153  int size;
154  struct AppendListChunk* next;
155  type* data[1];
156  };
157 
158  struct AppendListChunk *_next, *_current, *_last;
159  int _count, _currentIndex, _lastIndex;
160  bool _autoDelete;
161  type* _first[firstLen];
162 };
163 
164 
165 #endif
QIODevice
AppendList::count
unsigned count() const
Definition: utils.h:141
FixString::isValid
bool isValid()
Definition: utils.h:54
FixString::stripSpaces
void stripSpaces()
Strip leading spaces.
Definition: utils.cpp:155
AppendList::first
type * first()
FixString::stripUInt
bool stripUInt(uint &, bool stripSpaces=true)
Definition: utils.cpp:75
QByteArray
AppendList::~AppendList
~AppendList()
Definition: utils.h:135
AppendList::append
void append(const type *)
FixFile::setCurrent
bool setCurrent(unsigned pos)
Definition: utils.cpp:449
uint64
unsigned long long uint64
Definition: subcost.h:27
FixFile::~FixFile
~FixFile()
Definition: utils.cpp:396
FixFile::rewind
void rewind()
Definition: utils.h:114
FixFile
A class for fast line by line reading of a read-only ASCII file.
Definition: utils.h:100
FixString::stripSurroundingSpaces
void stripSurroundingSpaces()
Strip leading and trailing spaces.
Definition: utils.cpp:139
AppendList::setAutoDelete
void setAutoDelete(bool)
QString::fromLocal8Bit
QString fromLocal8Bit(const char *str, int size)
FixFile::exists
bool exists()
Definition: utils.h:110
FixString::stripInt64
bool stripInt64(int64 &, bool stripSpaces=true)
Definition: utils.cpp:273
FixString::FixString
FixString()
Definition: utils.h:42
FixString::stripFirst
bool stripFirst(char &)
Definition: utils.cpp:40
AppendList
A list of pointers, only able to append items.
Definition: utils.h:131
FixString::first
bool first(char &c)
Definition: utils.h:57
QString
FixString
A simple, constant string class.
Definition: utils.h:38
AppendList::containsRef
unsigned containsRef(const type *) const
FixFile::len
unsigned len()
Definition: utils.h:111
FixFile::FixFile
FixFile(QIODevice *, const QString &)
Definition: utils.cpp:340
FixString::len
int len()
Definition: utils.h:51
AppendList::AppendList
AppendList()
FixString::stripName
bool stripName(FixString &)
Strip name: [A-Za-z_][0-9A_Za-z_]*.
Definition: utils.cpp:163
FixString::stripPrefix
bool stripPrefix(const char *)
Definition: utils.cpp:53
FixString::isEmpty
bool isEmpty()
Definition: utils.h:53
FixString::set
void set(const char *s, int l)
Definition: utils.h:60
uint64
unsigned long long uint64
Definition: utils.h:28
FixString::stripUntil
FixString stripUntil(char)
Strip string until char appears or end.
Definition: utils.cpp:189
int64
long long int64
Definition: utils.h:31
AppendList::clear
void clear()
FixFile::nextLine
bool nextLine(FixString &str)
Read next line into .
Definition: utils.cpp:411
AppendList::current
type * current()
FixString::stripUInt64
bool stripUInt64(uint64 &, bool stripSpaces=true)
Definition: utils.cpp:210
FixString::ascii
const char * ascii()
Definition: utils.h:52
FixFile::current
unsigned current()
Definition: utils.h:112
AppendList::next
type * next()
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:39:50 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kcachegrind

Skip menu "kcachegrind"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal