• Advertisement
Sign in to follow this  

Container Arguement Theory?

This topic is 3877 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to create a database of characters, listing names, stats, etc... like (championship manager or an RPG), that will be added to & deduced from over the program. But not sure about how to do it. I'm thinking a container of pointers? but which one? a vector? a list? anyone got any ideas what they think would work.

Share this post


Link to post
Share on other sites
Advertisement

struct Character
{
std::string first_name;
std:;string last_name;
CharacterStats statistics;
};
typedef Character * CharacterPtr;
typedef std::vector< CharacterPtr > CharacterDB;



Simple, and if you use smart pointers, you won't even need to worry about deleting the objects when they are removed.

The question that remains unanswered is how you search such database.

What kind of queries will you perform? By name? By some unique ID? By more than one key?

If you'll be using a single key, then use std::map< Key, CharacterPtr > instead of vector.

Another suitable container would be a std::set. That one is naturally suited for a bag of objects, where you don't necessarily care about order, and you're merely interested into whether a player exists or not. Custom comparators would solve the problem of looking up players by various stats.

Share this post


Link to post
Share on other sites
I'm thinking of a simple display, that shows these stats...

Name Health Morale Location

...then by clicking the header for the stat, the lists can be alphabetically/numerically arranged. Like a window folder on detail view.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement