Mercurial > ~dholland > hg > ag > index.cgi
view anagram/support/agdict.cpp @ 6:607e3be6bad8
Adjust to the moving target called the C++ standard.
Apparently nowadays it's not allowed to define an explicit copy
constructor but not an assignment operator. Consequently, defining the
explicit copy constructor in terms of the implicit/automatic
assignment operator for general convenience no longer works.
Add assignment operators.
Caution: not tested with the IBM compiler, but there's no particular
reason it shouldn't work.
author | David A. Holland |
---|---|
date | Mon, 30 May 2022 23:46:22 -0400 |
parents | 13d2b8934445 |
children |
line wrap: on
line source
/* * AnaGram, A System for Syntax Directed Programming * Copyright 1997-2002 Parsifal Software. All Rights Reserved. * See the file COPYING for license and usage terms. * * agdict.cpp - new string dictionary */ #include "agstring.h" #include "agdict.h" #include "assert.h" //#define INCLUDE_LOGGING #include "log.h" int AgStringDictionary::Tree::compare(const int &x, const int &y) const { LOGSECTION("AgStringDictionary::Tree::compare"); LOGV(x) LCV(stringStore[x]); LOGV(y) LCV(stringStore[y]); LOGV(stringStore[x] < stringStore[y]); LOGV(stringStore[y] < stringStore[x]); if (stringStore[x] < stringStore[y]) { return -1; } return (stringStore[y] < stringStore[x]); } void AgStringDictionary::Tree::reset() { LOGSECTION("AgStringDictionary::Tree::reset"); AgBalancedTree<int>::reset(); stringStore.reset(); stringStore.push(AgString()).push(AgString()); insert(0); LOGV(size()) LCV(stringStore.size()); }; int AgStringDictionary::operator << (const AgString s) { LOGSECTION("AgStringDictionary::operator <<"); int newIndex = tree.size(); tree.stringStore.top() = s; LOGV(newIndex) LCV(tree.stringStore.size()) LCV(tree.stringStore.top()) LCV(s); if (!tree.identify(newIndex)) { tree.stringStore.push(AgString()); } LOGV(newIndex); return newIndex; } int AgStringDictionary::operator [] (const AgString s) { int n = tree.stringStore.size() - 1; int actualIndex = n; tree.stringStore.top() = s; if (tree.lookup(actualIndex)) { return actualIndex; } return 0; } AgString AgStringDictionary::operator [] (const unsigned x) { LOGSECTION("AgStringDictionary::operator []"); assert(x < tree.size()); LOGV(x) LCV(tree.stringStore[x]); return tree.stringStore[x]; }