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

kdevelop/kdevplatform/serialization

  • extragear
  • kdevelop
  • kdevelop
  • kdevplatform
  • serialization
indexedstring.h
Go to the documentation of this file.
1 /* This file is part of KDevelop
2 
3  Copyright 2008 David Nolden <[email protected]>
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License as
7  published by the Free Software Foundation; either version 2 of
8  the License, or (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef KDEVPLATFORM_INDEXED_STRING_H
20 #define KDEVPLATFORM_INDEXED_STRING_H
21 
22 //krazy:excludeall=dpointer,inline
23 
24 #include <QMetaType>
25 #include <QUrl>
26 
27 #include "referencecounting.h"
28 
29 #include "serializationexport.h"
30 
31 namespace KDevelop {
52 class KDEVPLATFORMSERIALIZATION_EXPORT IndexedString
53 {
54 public:
55  IndexedString();
62  explicit IndexedString(const char* str, unsigned short length, unsigned int hash = 0);
63 
71  explicit IndexedString(const char* str);
72 
73  explicit IndexedString(char c);
74 
80  explicit IndexedString(const QString& str);
81 
87  explicit IndexedString(const QByteArray& str);
88 
89  IndexedString(IndexedString&& o) Q_DECL_NOEXCEPT
90  : m_index(o.m_index)
91  {
92  o.m_index = 0;
93  }
94 
101  static IndexedString fromIndex(unsigned int index)
102  {
103  IndexedString ret;
104  ret.m_index = index;
105  return ret;
106  }
107 
112  static int lengthFromIndex(unsigned int index);
113 
114  IndexedString(const IndexedString&);
115 
116  ~IndexedString();
117 
121  explicit IndexedString(const QUrl& url);
122 
129  QUrl toUrl() const;
130 
131  inline unsigned int hash() const
132  {
133  return m_index;
134  }
135 
142  inline unsigned int index() const
143  {
144  return m_index;
145  }
146 
147  bool isEmpty() const
148  {
149  return m_index == 0;
150  }
151 
156  int length() const;
157 
163  const char* c_str() const;
164 
168  QString str() const;
169 
173  QByteArray byteArray() const;
174 
175  IndexedString& operator=(const IndexedString&);
176 
177  IndexedString& operator=(IndexedString&& o) Q_DECL_NOEXCEPT
178  {
179  m_index = o.m_index;
180  o.m_index = 0;
181  return *this;
182  }
183 
187  bool operator ==(const IndexedString& rhs) const
188  {
189  return m_index == rhs.m_index;
190  }
191 
195  bool operator !=(const IndexedString& rhs) const
196  {
197  return m_index != rhs.m_index;
198  }
199 
203  bool operator <(const IndexedString& rhs) const
204  {
205  return m_index < rhs.m_index;
206  }
207 
215  struct RunningHash
216  {
217  enum {
218  HashInitialValue = 5381
219  };
220 
221  RunningHash()
222  {
223  }
224  inline void append(const char c)
225  {
226  hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
227  }
228  inline void clear()
229  {
230  hash = HashInitialValue;
231  }
232 
234  unsigned int hash = HashInitialValue;
235  };
236 
237  static unsigned int hashString(const char* str, unsigned short length);
238 
243  static uint indexForString(const char* str, unsigned short length, uint hash = 0);
244  static uint indexForString(const QString& str, uint hash = 0);
245 
246 private:
247  explicit IndexedString(bool);
248  uint m_index = 0;
249 };
250 
251 // the following function would need to be exported in case you'd remove the inline keyword.
252 inline uint qHash(const KDevelop::IndexedString& str)
253 {
254  return str.index();
255 }
256 }
257 
261 KDEVPLATFORMSERIALIZATION_EXPORT QDebug operator<<(QDebug s, const KDevelop::IndexedString& string);
262 
263 Q_DECLARE_METATYPE(KDevelop::IndexedString)
264 Q_DECLARE_TYPEINFO(KDevelop::IndexedString, Q_MOVABLE_TYPE);
265 
266 #endif
KDevelop::IndexedString::fromIndex
static IndexedString fromIndex(unsigned int index)
Returns a not reference-counted IndexedString that represents the given index.
Definition: indexedstring.h:101
QByteArray
Q_DECLARE_TYPEINFO
Q_DECLARE_TYPEINFO(KDevelop::IndexedString, Q_MOVABLE_TYPE)
KDevelop::IndexedString::index
unsigned int index() const
The string is uniquely identified by this index.
Definition: indexedstring.h:142
KDevelop::IndexedString::RunningHash::RunningHash
RunningHash()
Definition: indexedstring.h:221
KDevelop::IndexedString::isEmpty
bool isEmpty() const
Definition: indexedstring.h:147
KDevelop::IndexedString::hash
unsigned int hash() const
Definition: indexedstring.h:131
QString
KDevelop::IndexedString::RunningHash::clear
void clear()
Definition: indexedstring.h:228
QUrl
QDebug
referencecounting.h
operator<<
KDEVPLATFORMSERIALIZATION_EXPORT QDebug operator<<(QDebug s, const KDevelop::IndexedString &string)
qDebug() stream operator.
Definition: indexedstring.cpp:404
KDevelop::IndexedString::RunningHash
Use this to construct a hash-value on-the-fly.
Definition: indexedstring.h:215
KDevelop::IndexedString
This string does "disk reference-counting", which means that reference-counts are maintainted...
Definition: indexedstring.h:52
KDevelop::IndexedString::IndexedString
IndexedString(IndexedString &&o) Q_DECL_NOEXCEPT
Definition: indexedstring.h:89
KDevelop::qHash
uint qHash(const KDevelop::IndexedString &str)
Definition: indexedstring.h:252
KDevelop::IndexedString::operator=
IndexedString & operator=(IndexedString &&o) Q_DECL_NOEXCEPT
Definition: indexedstring.h:177
KDevelop::IndexedString::RunningHash::append
void append(const char c)
Definition: indexedstring.h:224
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Sat Dec 14 2019 02:58:04 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdevelop/kdevplatform/serialization

Skip menu "kdevelop/kdevplatform/serialization"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdevelop API Reference

Skip menu "kdevelop API Reference"
  •   kdevplatform
  •     debugger
  •     documentation
  •     interfaces
  •     language
  •       assistant
  •       backgroundparser
  •       checks
  •       classmodel
  •       codecompletion
  •       codegen
  •       duchain
  •       editor
  •       highlighting
  •       interfaces
  •       util
  •     outputview
  •     project
  •     serialization
  •     shell
  •     sublime
  •     tests
  •     util
  •     vcs

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