> -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > On Behalf Of Philippe A. Bouchard > Sent: Monday, July 28, 2003 8:13 AM > To: [EMAIL PROTECTED] > Subject: [boost] RE: Re: Re: GUI/GDI template library >
> Yes I know, this could be defined by another property what to do when you > expand a sub-list: > > template <typename T> > struct tree > { > list<T> element; > list<tree> children; > }; > Ok, your tree is the structure (and owns the data). My 'tree control' actually owns and manages the data. The programmer just specifies the layout of the tree. I had a supporting class called n_tree: template <typename Parent, typename ChildList = null_type> struct n_tree { typedef Parent parent; typedef ChildList child; }; typedef boost::mpl::vector<int, double, n_tree<int, std::string> > tree_layout; tree_ctrl<tree_layout> my_tree; This defines a tree with three types of root nodes, int, double, and another int node that has string children. Here is how you would specify how to populate the various node: int list_integers(); double list_doubles(); std::string list_strings_for_parent(int parent); my_tree.first.set_nodes(list_integers); my_tree.second.set_nodes(list_doubles); my_tree.third.set_nodes(list_integers); my_tree.third.first.set_nodes(list_strings_for_parent); It is all statically typed. The control manages when to load all the data for the various nodes. Doing things like setting color is easy too: color even_is_red(int i) { return i % 2 == 0 ? red : default; } my_tree.first.set_color(even_is_red); [...] > struct tree<> is recursive: list<tree> children. Why I like it this way > is > because it is exactly like other containers and can be used for other The only problem is that while tree<> can be as deep as possible, it can't have multiple types of structures, say filessystem and printersystem. > purposes. You could define any element type you want: > > tree<lineedit>, tree<checkbox>, tree<label>, tree<pixmap_label> or tree< > ..._ptr<mytype> > if the design is chosen upon smart pointers for widget > creation. That's really cool. You could have trees in lists in trees. I never thought of it that way. That would be a challenging project! _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost