|
|
|
|
|
|
|
|
|
|
|
|
SGT_FW
by Aku_Aku. 05/31/26 11:05
|
|
|
|
|
5 registered members (alx, TipmyPip, AndrewAMD, Quad, 1 invisible),
3,180
guests, and 3
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: c++ Collections
[Re: Lukas]
#337851
08/13/10 22:07
08/13/10 22:07
|
Joined: Jul 2010
Posts: 283 Germany
jenGs
OP
Member
|
OP
Member
Joined: Jul 2010
Posts: 283
Germany
|
Thank you for your reply. No, the problem is:
DLLFUNC void* createHashMap()
{
hash_map<int, void*> *m = new hash_map<int, void*>();
return(m);
}
//Here start's my problem
DLLFUNC void putValue(void *map, int key, void *value)
{
hash_map<int, void*> *m = (hash_map<int, void*>*)map;
//until now it works fine. I can do every Operation with my hash_map
//But I want to use the operators of the hash_map. That means
//access the map by m[key] = value
//my code:
m[key] = value;
//But this doesn't work because I can't get access to the operators through a hash_map pointer
}
If I think it through I want to now how to "depointer" a pointer  I don't think it is called like that. AAnd is it possible to pass a var or blank type like that to my DLL:
DLLFUNC void createHashMap(type key, type value)
{
chash_map<key, value> *m = ...
}
|
|
|
Re: c++ Collections
[Re: pegamode]
#337853
08/13/10 22:10
08/13/10 22:10
|
Joined: Jul 2010
Posts: 283 Germany
jenGs
OP
Member
|
OP
Member
Joined: Jul 2010
Posts: 283
Germany
|
Oh, thank you pegamode. I was a bit to early with my previous reply. It is usefull, and will use it. But I want to know how things work, so it would be nice, if someone can answer my question 
|
|
|
Re: c++ Collections
[Re: jenGs]
#337908
08/14/10 11:26
08/14/10 11:26
|
Joined: Feb 2006
Posts: 1,011 Germany
pegamode
Serious User
|
Serious User
Joined: Feb 2006
Posts: 1,011
Germany
|
I do it this way:
typedef std::map<std::string, var, __lesscasecmp> container;
container con;
DLLFUNC container* createDynamicGSHashmap()
{
container *cont = new container;
return cont;
}
DLLFUNC void destroyDynamicGSHashmap(container* cont)
{
delete cont;
}
DLLFUNC void addToDynamicGSHashmap(container &cont, char* key, var value)
{
std::string tmpKey = "";
tmpKey.append(key);
cont[tmpKey] = value;
}
The rest of the functions look very similiar. I store an arbitrary pointer into the hashmap and when getting it back I just cast it back to its type like this: USEABLE_OBJECT* microwave_obj = ((USEABLE_OBJECT*)getFromDynamicGSHashmap(objectsMap, microwave_obj_ent.string1)); USEABLE_OBJECT is a struct I use. I hope this helps. Regards, Pegamode.
|
|
|
|