Gamestudio Links
Zorro Links
Newest Posts
Stooq now requires an API key
by k_ivan. 06/10/26 14:39
Z9 getting Error 058
by k_ivan. 06/10/26 14:38
ZorroGPT
by TipmyPip. 06/10/26 13:07
Z12 live performance
by alx. 06/09/26 20:42
Lapsa's very own thread
by Lapsa. 06/08/26 22:41
Zorro 3.01 recoded MMI function issue
by TipmyPip. 06/04/26 05:44
SGT_FW
by Aku_Aku. 05/31/26 11:05
Issues resuming trades on Demo account
by Martin_HH. 05/22/26 13:31
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
5 registered members (alx, TipmyPip, AndrewAMD, Quad, 1 invisible), 3,180 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Seraphinang, Koti, curry, DeepxKalsi, Samed
19219 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
c++ Collections #337727
08/12/10 21:19
08/12/10 21:19
Joined: Jul 2010
Posts: 283
Germany
J
jenGs Offline OP
Member
jenGs  Offline OP
Member
J

Joined: Jul 2010
Posts: 283
Germany
Hi,
I have written some collection plugins for Vectors and Lists.
They working fine. Each of them gives a void* pointer to the list/vector and can store pointers.

So, I've tried that with an key = integer has_map too.
The problem is if I do it like in the other plugins, I cant't get access to the [] index of the hash_map, because it is a pointer to a hash_map. And I don't realy understand the find functions. (It worked somehow, but not with gstudio).
How can I get access to the oparators of a collection Pointer?
MfG,
Ich

Re: c++ Collections [Re: jenGs] #337736
08/12/10 21:49
08/12/10 21:49
Joined: Jul 2010
Posts: 283
Germany
J
jenGs Offline OP
Member
jenGs  Offline OP
Member
J

Joined: Jul 2010
Posts: 283
Germany
And another question:
Is it possible to send a type/typedef to my plugin function, so the function can use this type to create the hash_map?

Hehe, I don't think so, but I hope.

Re: c++ Collections [Re: jenGs] #337846
08/13/10 21:47
08/13/10 21:47
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
If I understood your problem correctly, you just need a cast:

((yourtype*)(yourarray))[yourindex] = ...
OR (with a C++ cast):
reinterpret_cast<yourtype>(yourarray)[yourindex] = ...

Re: c++ Collections [Re: Lukas] #337849
08/13/10 22:00
08/13/10 22:00
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline
Serious User
pegamode  Offline
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Maybe my dll's GSHashmap and GSVector are for your interest:

http://www.opserver.de/wiki/index.php/Plugins#GSHashmap_DLL_.2A.2A.2A_new_Version_1.0_.2A.2A.2A

Regards,
Pegamode.

Re: c++ Collections [Re: Lukas] #337851
08/13/10 22:07
08/13/10 22:07
Joined: Jul 2010
Posts: 283
Germany
J
jenGs Offline OP
Member
jenGs  Offline OP
Member
J

Joined: Jul 2010
Posts: 283
Germany
Thank you for your reply.
No, the problem is:
Code:
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 laugh laugh 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:

Code:
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
J
jenGs Offline OP
Member
jenGs  Offline OP
Member
J

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 laugh

Re: c++ Collections [Re: jenGs] #337908
08/14/10 11:26
08/14/10 11:26
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline
Serious User
pegamode  Offline
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
I do it this way:

Code:
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.

Re: c++ Collections [Re: pegamode] #337947
08/14/10 18:38
08/14/10 18:38
Joined: Jul 2010
Posts: 283
Germany
J
jenGs Offline OP
Member
jenGs  Offline OP
Member
J

Joined: Jul 2010
Posts: 283
Germany
Thank you, that was usefull input laugh


Moderated by  TWO 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1