I’m trying to build a contact manager. I have a datastructure in mind that has a couple of properties:
-
it is tree like, meaning that each piece of information can be split up into subpieces (each node has children). For example a field called
addressmay consist out ofstreet,town,postal code, etc subfields. -
nodes do not have to be unique, for instance several nodes of the
emailfield should be able to coexist next to each other (at the same level)
I would like to be able to explore the tree using a path-like manner, e.g. access nodes by path: address.street or name.first. Accessing nodes whose key is present more than once could be done like email[2].
so a tree could look like:
contact
↳ name
↳ first "foo"
↳ last "von bar"
↳ email "foo@bar.com"
↳ email "baz@foo.de"
↳ address
↳ street "foostreet 42"
↳ town "barstadt"
↳ zip "04229"
↳ country "footopia"
↳ address
↳ street "barton alley 11"
↳ town "foostadt"
↳ zip "998877"
↳ country "alcabaz"
what kind of tree is this? I’ve tried using the Boost’s property_tree but found it hard to implement the fact that address should be split at high level (Boost’s standard method would put the street, town, … nodes in one address).
Any ideas are welcome.
It’s a tree 😉
You can use JSON and the Jackson Lib for modelise your tree :
http://www.mkyong.com/java/jackson-tree-model-example/