summaryrefslogtreecommitdiffstats
path: root/src/stringset.h
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 19:17:32 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 19:17:32 +0000
commite38d2351b83fa65c66ccde443777647ef5cb6cff (patch)
tree1897fc20e9f73a81c520a5b9f76f8ed042124883 /src/stringset.h
downloadtellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.tar.gz
tellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.zip
Added KDE3 version of Tellico
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/tellico@1097620 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/stringset.h')
-rw-r--r--src/stringset.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/stringset.h b/src/stringset.h
new file mode 100644
index 0000000..47667a0
--- /dev/null
+++ b/src/stringset.h
@@ -0,0 +1,58 @@
+/***************************************************************************
+ copyright : (C) 2005-2006 by Robby Stephenson
+ email : robby@periapsis.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of version 2 of the GNU General Public License as *
+ * published by the Free Software Foundation; *
+ * *
+ ***************************************************************************/
+
+#ifndef TELLICO_STRINGSET_H
+#define TELLICO_STRINGSET_H
+
+#include <qdict.h>
+#include <qstringlist.h>
+
+namespace Tellico {
+
+/**
+ * @author Robby Stephenson
+ */
+class StringSet {
+
+public:
+ StringSet(int size = 17) : m_dict(size) {}
+
+ // replace instead of insert, to ensure unique keys
+ void add(const QString& val) { if(!val.isEmpty()) m_dict.replace(val, reinterpret_cast<const int *>(1)); }
+ void add(const QStringList& vals) {
+ for(QStringList::ConstIterator it = vals.begin(), end = vals.end(); it != end; ++it) {
+ add(*it);
+ }
+ }
+ bool remove(const QString& val) { return !val.isEmpty() && m_dict.remove(val); }
+ void clear() { m_dict.clear(); }
+ bool has(const QString& val) const { return !val.isEmpty() && (m_dict.find(val) != 0); }
+ bool isEmpty() const { return m_dict.isEmpty(); }
+ uint count() const { return m_dict.count(); }
+
+ QStringList toList() const {
+ QStringList list;
+ for(QDictIterator<int> it(m_dict); it.current(); ++it) {
+ list << it.currentKey();
+ }
+ return list;
+ }
+
+private:
+ // use a dict for fast random access to keep track of the values
+ QDict<int> m_dict;
+};
+
+}
+
+#endif