Advertisement Jump to content
Sign in to follow this  

how to create 1-n relation using boost::multi_index?

This topic is 3818 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

hi all i try to create something like a 1-n relation between 2 structs like this
// some infos for a host
typedef struct SomeHost{
   uint32_t ip;
   uint16_t port;
   std::string hostname;
// operator< ... // here we have some compare functions for our std::set

// many hosts form a group
typedef struct ServerGroup{
   std::string groupid;
   std::string readbuffer;
   std::string writebuffer;
   std::set<SomeHost> groupmembers;

struct ServerGropuID{};

// create an index for the group
typedef boost::multi_index::multi_index_container<
// and some indices ....
// how to create an index for groupmembers? e.g. to query: to which group belongs Host X?
> ServerList;

ServerList groups;

its just an example illustration, but as you can see i try to create a group of servers. using this group i want to query the structures using an index for example, i need to get the group structure for a specific server using its ip (or hostname) since im using multi_index for really simple indices i was asking myself if, and how, its possible to create a relation between 2 structures using boost (multi_index)? so, it would be great if anyone, has a hint on how to create such a relation between a [group of servers] and [the server details] without using another std::map for the mapping between those structures? (which would mean i have to maintain another structure/map, which gets confusing sooner or later) or maybe anyone has an alternative idea? thx@ll

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!