diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-06-30 06:10:56 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-06-30 06:10:56 +0000 |
commit | 769e63d24adf5c844137484f06a972fcce732d6a (patch) | |
tree | 5185797dcb3ff4b1b3cb71d367123bf89eb2410f /src/triestring.cpp | |
parent | 0a8af92185eac74d48da1225e6053a0d66c078f5 (diff) | |
download | kmplayer-769e63d24adf5c844137484f06a972fcce732d6a.tar.gz kmplayer-769e63d24adf5c844137484f06a972fcce732d6a.zip |
TQt4 port kmplayer
This enables compilation under both Qt3 and Qt4
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kmplayer@1238840 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/triestring.cpp')
-rw-r--r-- | src/triestring.cpp | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/src/triestring.cpp b/src/triestring.cpp index bf41506..3c74fb5 100644 --- a/src/triestring.cpp +++ b/src/triestring.cpp @@ -40,13 +40,13 @@ struct KMPLAYER_NO_EXPORT TrieNode { void unref (); void removeChild (TrieNode *); void dump (int lvl) { - QString indent (QString ().fill (QChar ('.'), lvl)); + TQString indent (TQString ().fill (TQChar ('.'), lvl)); printf("%s%s len:%4d rc:%4d\n", indent.ascii(), str, length, ref_count); } char * str; unsigned short length; unsigned short ref_count; - TrieNode * parent; + TrieNode * tqparent; TrieNode * first_child; TrieNode * next_sibling; }; @@ -70,7 +70,7 @@ KDE_NO_CDTOR_EXPORT TrieNode::TrieNode (const char * s) : str (s ? strdup (s) : 0L), length (s ? strlen (s) : 0), ref_count (1), - parent (0L), + tqparent (0L), first_child (0L), next_sibling (0L) {} @@ -81,7 +81,7 @@ KDE_NO_CDTOR_EXPORT TrieNode::~TrieNode () { KDE_NO_EXPORT void TrieNode::unref () { if (--ref_count <= 0 && !first_child) - parent->removeChild (this); + tqparent->removeChild (this); } KDE_NO_EXPORT void TrieNode::removeChild (TrieNode * node) { @@ -95,10 +95,10 @@ KDE_NO_EXPORT void TrieNode::removeChild (TrieNode * node) { } } delete node; - if (!parent) + if (!tqparent) return; if (!ref_count && !first_child) - parent->removeChild (this); // can this happen ? + tqparent->removeChild (this); // can this happen ? else if (!ref_count && !first_child->next_sibling) { // merge with child char * tmp = first_child->str; first_child->length = first_child->length + length; @@ -106,12 +106,12 @@ KDE_NO_EXPORT void TrieNode::removeChild (TrieNode * node) { strcpy (first_child->str, str); strcat (first_child->str, tmp); free (tmp); - first_child->parent = parent; + first_child->tqparent = tqparent; first_child->next_sibling = next_sibling; - if (parent->first_child == this) { - parent->first_child = first_child; + if (tqparent->first_child == this) { + tqparent->first_child = first_child; } else { - for (TrieNode *n = parent->first_child; n; n = n->next_sibling) + for (TrieNode *n = tqparent->first_child; n; n = n->next_sibling) if (n->next_sibling == this) { n->next_sibling = first_child; break; @@ -123,9 +123,9 @@ KDE_NO_EXPORT void TrieNode::removeChild (TrieNode * node) { static char * trieRetrieveString (TrieNode * node, int &len) { char *buf; - if (node->parent) { + if (node->tqparent) { len += node->length; - buf = trieRetrieveString (node->parent, len); + buf = trieRetrieveString (node->tqparent, len); strcat (buf, node->str); } else { buf = (char *) malloc (len + 1); @@ -138,8 +138,8 @@ static int trieStringCompare (TrieNode * node, const char * s, int &len) { int cmp = 0; if (!node) return !!s; - if (node->parent && node->parent != root_trie) - cmp = trieStringCompare (node->parent, s, len); + if (node->tqparent && node->tqparent != root_trie) + cmp = trieStringCompare (node->tqparent, s, len); if (!cmp) { #ifdef TEST_TRIE printf( "compare %s %s %d\n", node->str, s + len, node->length); @@ -153,8 +153,8 @@ static int trieStringCompare (TrieNode * node, const char * s, int &len) { static int trieStringCompare (TrieNode * n1, TrieNode * n2) { // pre n1 && n2 on same depth and not NIL int cmp = 0; - if (n1->parent && n1->parent != root_trie) - cmp = trieStringCompare (n1->parent, n2->parent); + if (n1->tqparent && n1->tqparent != root_trie) + cmp = trieStringCompare (n1->tqparent, n2->tqparent); if (!cmp && n1 != n2) { #ifdef TEST_TRIE printf( "compare %s %s", n1->str, n2->str); @@ -174,8 +174,8 @@ static int trieStringCompare (TrieNode * n1, TrieNode * n2) { static int trieStringStarts (TrieNode * node, const char * s, int & pos) { int cmp = -1; // -1 still matches, 0 no, 1 yes - if (node->parent && node->parent != root_trie) - cmp = trieStringStarts (node->parent, s, pos); + if (node->tqparent && node->tqparent != root_trie) + cmp = trieStringStarts (node->tqparent, s, pos); if (cmp == -1) { for (int i = 0; i < node->length; i++) if (node->str[i] != s[pos + i]) @@ -190,8 +190,8 @@ static TrieNode * trieInsert (const char * s) { root_trie = new TrieNode (0L); //printf("trieInsert %s\n", s); //dumpTrie(); - TrieNode * parent = root_trie; - for (TrieNode * c = parent->first_child; c; c = c->first_child) { + TrieNode * tqparent = root_trie; + for (TrieNode * c = tqparent->first_child; c; c = c->first_child) { TrieNode * prev = c; for (TrieNode * n = prev; n; n = n->next_sibling) { if (n->str[0] == s[0]) { // insert here @@ -206,13 +206,13 @@ static TrieNode * trieInsert (const char * s) { tmp[i] = 0; TrieNode * node = new TrieNode (tmp); free (tmp); - node->parent = parent; + node->tqparent = tqparent; node->next_sibling = n->next_sibling; if (prev != n) prev->next_sibling = node; else - parent->first_child = node; - n->parent = node; + tqparent->first_child = node; + n->tqparent = node; TrieNode * snode; if (!s[i]) { node->first_child = n; @@ -220,7 +220,7 @@ static TrieNode * trieInsert (const char * s) { snode = node; // s is complete in node } else { snode = new TrieNode (s+i); - snode->parent = node; + snode->tqparent = node; if (bigger) { // set n before snode node->first_child = n; n->next_sibling = snode; @@ -244,32 +244,32 @@ static TrieNode * trieInsert (const char * s) { return n; } else if (n->str[0] > s[0]) { // insert before TrieNode * node = new TrieNode (s); - node->parent = parent; + node->tqparent = tqparent; node->next_sibling = n; if (prev != n) prev->next_sibling = node; else - parent->first_child = node; + tqparent->first_child = node; return node; } prev = n; } if (prev) { // insert after TrieNode * node = new TrieNode (s); - node->parent = parent; + node->tqparent = tqparent; prev->next_sibling = node; return node; } - parent = c; + tqparent = c; } // hit an empty first_child, add s as first_child TrieNode * node = new TrieNode (s); - parent->first_child = node; - node->parent = parent; + tqparent->first_child = node; + node->tqparent = tqparent; return node; } -TrieString::TrieString (const QString & s) +TrieString::TrieString (const TQString & s) : node (s.isEmpty () ? 0L : trieInsert (s.utf8 ().data ())) {} @@ -288,7 +288,7 @@ TrieString::~TrieString () { } bool TrieString::startsWith (const TrieString & s) const { - for (TrieNode * n = node; n; n = n->parent) + for (TrieNode * n = node; n; n = n->tqparent) if (n == s.node) return true; return s.node ? false : true; @@ -327,12 +327,12 @@ TrieString & TrieString::operator = (const char * utf8) { return *this; } -QString TrieString::toString () const { - QString s; +TQString TrieString::toString () const { + TQString s; if (node) { int len = 0; char *utf8 = trieRetrieveString (node, len); - s = QString::fromUtf8 (utf8); + s = TQString::fromUtf8 (utf8); free (utf8); } return s; @@ -342,11 +342,11 @@ bool TrieString::operator < (const TrieString & s) const { if (node == s.node) return false; int depth1 = 0, depth2 = 0; - for (TrieNode * n = node; n; n = n->parent) + for (TrieNode * n = node; n; n = n->tqparent) depth1++; if (!depth1) return s.node ? true : false; - for (TrieNode * n = s.node; n; n = n->parent) + for (TrieNode * n = s.node; n; n = n->tqparent) depth2++; if (!depth2) return false; @@ -355,13 +355,13 @@ bool TrieString::operator < (const TrieString & s) const { while (depth1 > depth2) { if (n1 == n2) return false; - n1 = n1->parent; + n1 = n1->tqparent; depth1--; } while (depth2 > depth1) { if (n1 == n2) return true; - n2 = n2->parent; + n2 = n2->tqparent; depth2--; } int cmp = trieStringCompare (n1, n2); @@ -455,37 +455,37 @@ void KMPlayer::dumpTrie () { } #ifdef TEST_TRIE -// g++ triestring.cpp -o triestring -I$QTDIR/include -L$QTDIR/lib -lqt-mt -g -DTEST_TRIE +// g++ triestring.cpp -o triestring -I$TQTDIR/include -L$TQTDIR/lib -lqt-mt -g -DTEST_TRIE int main (int, char **) { StringPool::init(); { TrieString s1; - TrieString s1_1(QString ("region")); + TrieString s1_1(TQString ("region")); s1 = s1_1; - TrieString s2 (QString ("regionName")); - TrieString s3 (QString ("regPoint")); - TrieString s4 (QString ("regAlign")); - TrieString s6 (QString ("freeze")); - TrieString s7 (QString ("fit")); + TrieString s2 (TQString ("regionName")); + TrieString s3 (TQString ("regPoint")); + TrieString s4 (TQString ("regAlign")); + TrieString s6 (TQString ("freeze")); + TrieString s7 (TQString ("fit")); { - TrieString s7_1 (QString ("fit")); - TrieString s5 (QString ("fill")); + TrieString s7_1 (TQString ("fit")); + TrieString s5 (TQString ("fill")); dump (root_trie, 0); } dump (root_trie, 0); - TrieString s5 (QString ("fill")); - TrieString s8 (QString ("fontPtSize")); - TrieString s9 (QString ("fontSize")); - TrieString s10 (QString ("fontFace")); - TrieString s11 (QString ("fontColor")); - TrieString s12 (QString ("hAlign")); - TrieString s13 (QString ("region")); - TrieString s14 (QString ("ref")); - TrieString s15 (QString ("head")); + TrieString s5 (TQString ("fill")); + TrieString s8 (TQString ("fontPtSize")); + TrieString s9 (TQString ("fontSize")); + TrieString s10 (TQString ("fontFace")); + TrieString s11 (TQString ("fontColor")); + TrieString s12 (TQString ("hAlign")); + TrieString s13 (TQString ("region")); + TrieString s14 (TQString ("ref")); + TrieString s15 (TQString ("head")); dump (root_trie, 0); - QString qs1 = s1.toString (); - QString qs2 = s2.toString (); + TQString qs1 = s1.toString (); + TQString qs2 = s2.toString (); printf ("%s\n%s\n", qs1.ascii(), qs2.ascii()); printf("equal %s %s %d\n", qs2.ascii(), "regionName", s2 == "regionName"); printf("equal %s %s %d\n", qs2.ascii(), "zegionName", s2 == "zegionName"); |