language/duchain
indexedstring.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef INDEXED_STRING_H
00015 #define INDEXED_STRING_H
00016
00017
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
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
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
00123
00124
00125 struct RunningHash {
00126 enum {
00127 HashInitialValue = 5381
00128 };
00129
00130 RunningHash() : hash(HashInitialValue) {
00131 }
00132 inline void append(const char c) {
00133 hash = ((hash << 5) + hash) + 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