• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

language/duchain

indexedstring.h

00001 /***************************************************************************
00002    Copyright 2008 David Nolden <david.nolden.kdevelop@art-master.de>
00003 ***************************************************************************/
00004 
00005 /***************************************************************************
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  ***************************************************************************/
00013 
00014 #ifndef INDEXED_STRING_H
00015 #define INDEXED_STRING_H
00016 
00017 //krazy:excludeall=dpointer,inline
00018 
00019 #include <QtCore/QString>
00020 #include "../languageexport.h"
00021 #include <language/duchain/referencecounting.h>
00022 
00023 class QDataStream;
00024 class KUrl;
00025 
00026 namespace KDevelop {
00027 class IndexedString;
00028 }
00029 
00030 namespace KDevelop {
00031 
00043 class KDEVPLATFORMLANGUAGE_EXPORT IndexedString {
00044  public:
00045   IndexedString();
00049   explicit IndexedString( const char* str, unsigned short length, unsigned int hash = 0 );
00050 
00052   //WARNING There is a UTF8-related issue when attempting to retrieve the string using str from an IndexedString built from this constructor
00053   explicit IndexedString( const char* str );
00054 
00055   explicit IndexedString( char c );
00056   
00058   explicit IndexedString( const QString& str );
00059 
00061   explicit IndexedString( const QByteArray& str );
00062 
00066   static IndexedString fromIndex( unsigned int index ) {
00067     IndexedString ret;
00068     ret.m_index = index;
00069     return ret;
00070   }
00071 
00072   IndexedString( const IndexedString& );
00073 
00074   ~IndexedString();
00075 
00077   explicit IndexedString( const KUrl& url );
00078 
00081   KUrl toUrl() const;
00082 
00083   inline unsigned int hash() const {
00084     return m_index;
00085   }
00086 
00090   inline unsigned int index() const {
00091     return m_index;
00092   }
00093 
00094   bool isEmpty() const {
00095     return m_index == 0;
00096   }
00097 
00098   //This is relatively expensive(needs a mutex lock, hash lookups, and eventual loading), so avoid it when possible.
00099   int length() const;
00100 
00102   QString str() const;
00103 
00105   QByteArray byteArray() const;
00106 
00107   IndexedString& operator=(const IndexedString&);
00108   
00109   bool operator == ( const IndexedString& rhs ) const {
00110     return m_index == rhs.m_index;
00111   }
00112 
00113   bool operator != ( const IndexedString& rhs ) const {
00114     return m_index != rhs.m_index;
00115   }
00116 
00118   bool operator < ( const IndexedString& rhs ) const {
00119     return m_index < rhs.m_index;
00120   }
00121 
00122   //Use this to construct a hash-value on-the-fly
00123   //To read it, just use the hash member, and when a new string is started, call clear(.
00124   //This needs very fast performance(per character operation), so it must stay inlined.
00125   struct RunningHash {
00126     enum {
00127       HashInitialValue = 5381
00128     };
00129 
00130     RunningHash() : hash(HashInitialValue) { //We initialize the hash with zero, because we want empty strings to create a zero hash(invalid)
00131     }
00132     inline void append(const char c) {
00133       hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
00134     }
00135     inline void clear() {
00136       hash = HashInitialValue;
00137     }
00138     unsigned int hash;
00139   };
00140 
00141   static unsigned int hashString(const char* str, unsigned short length);
00142 
00143  private:
00144    explicit IndexedString(bool);
00145    uint m_index;
00146 };
00147 
00148 KDEVPLATFORMLANGUAGE_EXPORT inline uint qHash( const KDevelop::IndexedString& str ) {
00149   return str.index();
00150 }
00151 }
00152 
00153 #endif

language/duchain

Skip menu "language/duchain"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal