Boost logo

Boost :

From: Malcolm Smith (mjfreelancing_at_[hidden])
Date: 2004-08-12 08:55:01


Hi everyone,

Can someone either assist me or point me to a relevant site / newsgroup to
post this question.

I want to determine if traits can be used to choose a container type at
compile time based on the nature of hierarchial data to be stored. By this
I mean:

        * Is the data in a 1:1 or 1:Many relationship ?

        * Can there be more than one item in the container ?

        * Are the contained items be unique or not ?

These questions help decide which container to use such as std::deque,
std::map or even std::pair. I have tried to give an example below for a
typical usage in my work which occurs all the time (for creating config
files).

*** I'm new to all this, so don't yell if I'm writing absolute garbage below
***

Example:

Imagine data to be stored in a hierarchy fashion given the information:

  (i) IP Address = Site ID ( 1 : 1 ). There are many (unique) items to
be stored.

  (ii) Site ID has a collection of mapped items ( Code1 = Code2 ) where
Code1 is unique

        Such as:

                192.168.0.1 = ID1
                192.168.0.2 = ID2
                192.168.0.3 = ID3

        For ID1 the linked information might be something like

                ABCD = 1234
                EFGH = 5678

        For ID2 the linked information might be something like

                IJKL = 1010
                MNOP = 2020

        For ID3, the data might be the same as for ID1

                ABCD = 1234
                EFGH = 5678

  From (i) std::map< IP, ID > can be used.

  From (ii) std::pair< ID, std::map< Code1, Code2 > > can be used.

  Which can be combined into

        std::map< IP, std::pair< ID, std::map< Code1, Code2 > > >

So, is it possible using traits (or something else) to determine which
container to use and the appropriate nesting of objects.

I'm reading "Modern C++ Design" for the second time.....but that's the limit
of my experience with this type of development.

Thanks in advance for any suggestions.

Malcolm Smith
MJ Freelancing
http://www.mjfreelancing.com
Borland Technology Partner

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.736 / Virus Database: 490 - Release Date: 09/08/2004

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk