is an associative wxArray possible?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Brad Carter
In need of some credit
In need of some credit
Posts: 9
Joined: Mon Oct 11, 2004 5:39 am

is an associative wxArray possible?

Post by Brad Carter »

I am looking to do an associative wxArray, though it is not looking possible from my searchs (google, docks and here)

Let me explain what I am trying to do, since I am very new at this and trying to teach myself I could be barking up the wrong tree.

I am grabbing info from a database, and trying to load it into a wxTreeCtrl organized with the parents, children, sub-children sub-sub-children etc

Each record has an id that shows its realtion (you can see the parent from the id). The id looks something like an ip address for example:
1
1.1
1.1.1
1.2
1.2.1
1.2.1.1

1 has the children 1.1 and 1.2, 1.1 has the child 1.1.1 same goes for 1.2
Each record will have some data associated with it I am guessing another array since it will be holding some of the fields from the record.

My plan was to create a wxArray, which would have the key as the id record with the value being the corasponding wxTreeItemId. That way I could grab the wxTreeItemId for each record easily. since dropping the last portion of the id will tell me the parent I can know for example to append 1.2.1.1 to 1.2.1 and I can know the wxTreeItemId from the array.

I hope that makes sence, as I said I could be barking up the wrong tree with the array.

Thank you very much for your time
arkanes
Experienced Solver
Experienced Solver
Posts: 59
Joined: Sun Oct 17, 2004 12:05 am

Post by arkanes »

wxHashMap (see http://wxwidgets.org/manuals/2.5.2/wx_w ... #wxhashmap) is what you want. This allows "arrays" that are indexed with abitrary keys.

Code: Select all

/*Declare a hash map with wxStrings for keys, and wxTreeItemId's for 
   values. The class name will be TreeItemHash
*/
WX_DECLARE_STRING_HASH_MAP( wxTreeItemId, TreeItemHash);

TreeItemHash h;

wxTreeItemId id; //pretend this is an actual ID from a real tree control

//use hash key to set a value
h["1.1"] = id;

//use hash key to retrieve a value
id = h["1.1"]
Brad Carter
In need of some credit
In need of some credit
Posts: 9
Joined: Mon Oct 11, 2004 5:39 am

Post by Brad Carter »

I think that is exactly what I am looking for thank you :)
Post Reply