D
David
Hello,
I try to store PROLOG_TERMs in a map which is again
stored in another map, to realise this I am using a
composite key of two strings.
The class compiles fine, but when I insert an element,
the "top level" map, i.e. the one accessed via 'key2'
is either not found or the term has not been inserted,
since the iteration does not produce any output nor
does the method return the correct value, i.e. 'FAIL'.
I already tried several alternative implementations with
'find(keyX)' none of which worked. Can anybody help please?
thanks beforehand,
David Kensche
typedef map<char*, PROLOG_TERM> termMap;
typedef map<char*, termMap > clusterMap;
class TermCache {
clusterMap clusters;
public:
/**
* Stores a copy of the PROLOG_TERM 'term' associated to
* double key (key1, key2). Fails with an error if there
* is already a value associated to the double key.
*/
int pc_record(char* key1, char* key2, PROLOG_TERM term) {
int solve = FAIL;
termMap cluster = clusters[key2];
termMap::const_iterator termKeyPair;
for(termKeyPair = cluster.begin(); termKeyPair != cluster.end();
++termKeyPair) {
cout << "current key == " << termKeyPair->first << "\n";
}
if(cluster.find(key1) == cluster.end()) {
cout << "cluster.find(" << key1 << ") == cluster.end(), new key,
thus succeed\n";
cluster.insert(termMap::value_type(key1, term));
solve = SUCCEED;
}
cout << "solve == " << solve << "\n";
return solve;
}
....
I try to store PROLOG_TERMs in a map which is again
stored in another map, to realise this I am using a
composite key of two strings.
The class compiles fine, but when I insert an element,
the "top level" map, i.e. the one accessed via 'key2'
is either not found or the term has not been inserted,
since the iteration does not produce any output nor
does the method return the correct value, i.e. 'FAIL'.
I already tried several alternative implementations with
'find(keyX)' none of which worked. Can anybody help please?
thanks beforehand,
David Kensche
typedef map<char*, PROLOG_TERM> termMap;
typedef map<char*, termMap > clusterMap;
class TermCache {
clusterMap clusters;
public:
/**
* Stores a copy of the PROLOG_TERM 'term' associated to
* double key (key1, key2). Fails with an error if there
* is already a value associated to the double key.
*/
int pc_record(char* key1, char* key2, PROLOG_TERM term) {
int solve = FAIL;
termMap cluster = clusters[key2];
termMap::const_iterator termKeyPair;
for(termKeyPair = cluster.begin(); termKeyPair != cluster.end();
++termKeyPair) {
cout << "current key == " << termKeyPair->first << "\n";
}
if(cluster.find(key1) == cluster.end()) {
cout << "cluster.find(" << key1 << ") == cluster.end(), new key,
thus succeed\n";
cluster.insert(termMap::value_type(key1, term));
solve = SUCCEED;
}
cout << "solve == " << solve << "\n";
return solve;
}
....