~ubuntu-branches/ubuntu/quantal/kdevplatform/quantal-proposed

« back to all changes in this revision

Viewing changes to language/editor/hashedstring.h

  • Committer: Bazaar Package Importer
  • Author(s): Bhargav Mangipudi
  • Date: 2010-12-16 19:31:23 UTC
  • mfrom: (0.3.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20101216193123-xe2keh5754zwsn1t
Tags: 1.1.80-0ubuntu1
* New upstream release
  - kdevplatform2-libs is now kdevplatform3-libs due to ABI changes
  - Update kdevplatform3-libs.install to include l10n files
  - Update kdevplatform-dev.install
* Removed localization packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
   Copyright 2007 David Nolden <david.nolden.kdevelop@art-master.de>
3
 
***************************************************************************/
4
 
 
5
 
/***************************************************************************
6
 
 *                                                                         *
7
 
 *   This program is free software; you can redistribute it and/or modify  *
8
 
 *   it under the terms of the GNU General Public License as published by  *
9
 
 *   the Free Software Foundation; either version 2 of the License, or     *
10
 
 *   (at your option) any later version.                                   *
11
 
 *                                                                         *
12
 
 ***************************************************************************/
13
 
 
14
 
#ifndef HASHED_STRING_H
15
 
#define HASHED_STRING_H
16
 
 
17
 
//krazy:excludeall=dpointer,inline
18
 
 
19
 
#include <QtCore/QString>
20
 
#include "../languageexport.h"
21
 
 
22
 
class QDataStream;
23
 
 
24
 
namespace KDevelop {
25
 
class HashedString;
26
 
}
27
 
 
28
 
KDEVPLATFORMLANGUAGE_EXPORT QDataStream& operator << ( QDataStream& stream, const KDevelop::HashedString& str );
29
 
 
30
 
KDEVPLATFORMLANGUAGE_EXPORT QDataStream& operator >> ( QDataStream& stream, KDevelop::HashedString& str );
31
 
 
32
 
namespace KDevelop {
33
 
 
34
 
typedef uint HashType; ///@todo use at least 64 bit hash
35
 
 
36
 
/**
37
 
 * A simple class that stores a string together with it's appropriate hash-key
38
 
 *
39
 
 * The difference to a normal QString is that the hash is stored, used for sorting, and for equality-comparison.
40
 
 *
41
 
 * Since most of the member-functions boil down to a simply integer-comparison in the most common case, they are inlined for performance-reasons.
42
 
 * */
43
 
class KDEVPLATFORMLANGUAGE_EXPORT HashedString {
44
 
 public:
45
 
  HashedString();
46
 
 
47
 
  HashedString( const QString& str );
48
 
 
49
 
  HashedString( const char* str );
50
 
 
51
 
  inline HashType hash() const {
52
 
    return m_hash;
53
 
  }
54
 
 
55
 
  QString str() const;
56
 
 
57
 
  HashedString& operator= ( const QString& str );
58
 
 
59
 
  HashedString& operator +=( const QString& str );
60
 
 
61
 
  HashedString& operator +=( const char* str );
62
 
 
63
 
  bool operator == ( const HashedString& rhs ) const;
64
 
 
65
 
  bool operator != ( const HashedString& rhs ) const;
66
 
  
67
 
  ///Does not compare alphabetically, uses the hash-key for ordering.
68
 
  bool operator < ( const HashedString& rhs ) const;
69
 
 
70
 
  static HashType hashString( const QString& str );
71
 
 
72
 
 private:
73
 
  void initHash();
74
 
 
75
 
  QString m_str;
76
 
  HashType m_hash;
77
 
 
78
 
  friend QDataStream& ::operator << ( QDataStream& stream, const HashedString& str );
79
 
  friend QDataStream& ::operator >> ( QDataStream& stream, HashedString& str );
80
 
};
81
 
 
82
 
KDEVPLATFORMLANGUAGE_EXPORT inline uint qHash( const KDevelop::HashedString& str ) {
83
 
  return str.hash();
84
 
}
85
 
}
86
 
 
87
 
#endif