bool* arguments can be used by wrappers
[lqt.git] / cpptoxml / parser / symbol.h
blob3048355fa5b2b5a0075eda5a140c050efebd9698
1 /****************************************************************************
2 **
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 ** Copyright (C) 2002-2005 Roberto Raggi <roberto@kdevelop.org>
5 **
6 ** This file is part of the Qt Script Generator project on Trolltech Labs.
7 **
8 ** This file may be used under the terms of the GNU General Public
9 ** License version 2.0 as published by the Free Software Foundation
10 ** and appearing in the file LICENSE.GPL included in the packaging of
11 ** this file. Please review the following information to ensure GNU
12 ** General Public Licensing requirements will be met:
13 ** http://www.trolltech.com/products/qt/opensource.html
15 ** If you are unsure which license is appropriate for your use, please
16 ** review the following information:
17 ** http://www.trolltech.com/products/qt/licensing.html or contact the
18 ** sales department at sales@trolltech.com.
20 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
21 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 ****************************************************************************/
26 #ifndef SYMBOL_H
27 #define SYMBOL_H
29 #include <QtCore/QString>
30 #include <cstring>
32 #include <QtCore/QHash>
33 #include <QtCore/QPair>
35 struct NameSymbol
37 const char *data;
38 std::size_t count;
40 inline QString as_string() const
42 return QString::fromUtf8(data, (int) count);
45 inline bool operator == (const NameSymbol &other) const
47 return count == other.count
48 && std::strncmp(data, other.data, count) == 0;
51 protected:
52 inline NameSymbol() {}
53 inline NameSymbol(const char *d, std::size_t c)
54 : data(d), count(c) {}
56 private:
57 void operator = (const NameSymbol &);
59 friend class NameTable;
62 inline uint qHash(const NameSymbol &r)
64 uint hash_value = 0;
66 for (std::size_t i=0; i<r.count; ++i)
67 hash_value = (hash_value << 5) - hash_value + r.data[i];
69 return hash_value;
72 inline uint qHash(const QPair<const char*, std::size_t> &r)
74 uint hash_value = 0;
76 for (std::size_t i=0; i<r.second; ++i)
77 hash_value = (hash_value << 5) - hash_value + r.first[i];
79 return hash_value;
82 class NameTable
84 public:
85 typedef QPair<const char *, std::size_t> KeyType;
86 typedef QHash<KeyType, NameSymbol*> ContainerType;
88 public:
89 NameTable() {}
91 ~NameTable()
93 qDeleteAll(_M_storage);
96 inline const NameSymbol *findOrInsert(const char *str, std::size_t len)
98 KeyType key(str, len);
100 NameSymbol *name = _M_storage.value(key);
101 if (!name)
103 name = new NameSymbol(str, len);
104 _M_storage.insert(key, name);
107 return name;
110 inline std::size_t count() const
112 return _M_storage.size();
115 private:
116 ContainerType _M_storage;
118 private:
119 NameTable(const NameTable &other);
120 void operator = (const NameTable &other);
123 #endif // SYMBOL_H
125 // kate: space-indent on; indent-width 2; replace-tabs on;