Data Structure for a Menu Tree - c++
This is a discussion on Data Structure for a Menu Tree - c++ ; Is there a community accepted best way to store a menu tree for an
interface in a data structure. Ideally I would like something that
searches fast so given a menu structure like this
File
/ | \
/ | ...
-
Data Structure for a Menu Tree
Is there a community accepted best way to store a menu tree for an
interface in a data structure. Ideally I would like something that
searches fast so given a menu structure like this
File
/ | \
/ | \
Print Exit Edit
/ \
Copy Paste
as an example, I could easily get a pointer to the "Edit" node.
-
Re: Data Structure for a Menu Tree
On 5 Jun, 16:58, Travis <travis.bow...@> wrote:
> Is there a community accepted best way to store a menu tree for an
> interface in a data structure. Ideally I would like something that
> searches fast so given a menu structure like this
>
> File
> / | \
> / | \
> Print Exit Edit
> / \
> Copy Paste
>
> as an example, I could easily get a pointer to the "Edit" node.
Its basically a directory tree e.g like a disc file system. Use a path
string to identify/return the required node etc ( and can add similar
complexities e.g absolute relative) but there is no standard library
way. AFAIK speed is not critical even for large menus though.
regards
Andy Little
-
Re: Data Structure for a Menu Tree
On 2007-06-05 17:58, Travis wrote:
> Is there a community accepted best way to store a menu tree for an
> interface in a data structure. Ideally I would like something that
> searches fast so given a menu structure like this
>
> File
> / | \
> / | \
> Print Exit Edit
> / \
> Copy Paste
>
> as an example, I could easily get a pointer to the "Edit" node.
Don't know what hardware or other constraints you are working under but
in a normal program on a normal computer any structure will be fast
enough (unless you have a menu-system like none I've ever seen). Go with
whatever is the easiest to use.
--
Erik Wikström
-
Re: Data Structure for a Menu Tree
On Jun 5, 10:35 am, kwikius <a...@servocomm.freeserve.co.uk> wrote:
> On 5 Jun, 16:58, Travis <travis.bow...@> wrote:
>
> > Is there a community accepted best way to store a menu tree for an
> > interface in a data structure. Ideally I would like something that
> > searches fast so given a menu structure like this
>
> > File
> > / | \
> > / | \
> > Print Exit Edit
> > / \
> > Copy Paste
>
> > as an example, I could easily get a pointer to the "Edit" node.
>
> Its basically a directory tree e.g like a disc file system. Use a path
> string to identify/return the required node etc ( and can add similar
> complexities e.g absolute relative) but there is no standard library
> way. AFAIK speed is not critical even for large menus though.
>
> regards
> Andy Little
Could you elaborate a litlte more on the string path setup? I assume
you mean something like "File\Edit\Paste". Which sounds good but how
do I store these all together? And how does "File\Edit" know that "File
\Edit\Paste" and "..\Copy" are its children?
-
Re: Data Structure for a Menu Tree
On 5 Jun., 20:26, Travis <travis.bow...@> wrote:
> On Jun 5, 10:35 am, kwikius <a...@servocomm.freeserve.co.uk> wrote:
>
>
>
> > On 5 Jun, 16:58, Travis <travis.bow...@> wrote:
>
> > > Is there a community accepted best way to store a menu tree for an
> > > interface in a data structure. Ideally I would like something that
> > > searches fast so given a menu structure like this
>
> > > File
> > > / | \
> > > / | \
> > > Print Exit Edit
> > > / \
> > > Copy Paste
>
> > > as an example, I could easily get a pointer to the "Edit" node.
>
> > Its basically a directory tree e.g like a disc file system. Use a path
> > string to identify/return the required node etc ( and can add similar
> > complexities e.g absolute relative) but there is no standard library
> > way. AFAIK speed is not critical even for large menus though.
>
> > regards
> > Andy Little
>
> Could you elaborate a litlte more on the string path setup? I assume
> you mean something like "File\Edit\Paste". Which sounds good but how
> do I store these all together? And how does "File\Edit" know that "File
> \Edit\Paste" and "..\Copy" are its children?
What he meant is using the path string to access the elements in an
easy way.
You'll still have to use an internal tree structure.
Here is a very basic example of how you could implement the tree (Many
stuff like destructors, getters, setters, ... missing):
class MenuEntry {
public:
vector<MenuEntry*> childs;
string name;
MenuEntry(string name) {
this->name = name;
}
};
To create a menu tree:
MenuEntry* root = new MenuEntry("<root>");
MenuEntry* file = new MenuEntry("File");
MenuEntry* edit = new MenuEntry("Edit");
file->childs.push_back(new MenuEntry("Print");
file->childs.push_back(new MenuEntry("Exit");
edit->childs.push_back(new MenuEntry("Copy");
edit->childs.push_back(new MenuEntry("Paste");
root.childs.push_back(file);
root.childs.push_back(edit);
-
Re: Data Structure for a Menu Tree
On 5 Jun, 19:26, Travis <travis.bow...@> wrote:
> On Jun 5, 10:35 am, kwikius <a...@servocomm.freeserve.co.uk> wrote:
>
>
>
>
>
> > On 5 Jun, 16:58, Travis <travis.bow...@> wrote:
>
> > > Is there a community accepted best way to store a menu tree for an
> > > interface in a data structure. Ideally I would like something that
> > > searches fast so given a menu structure like this
>
> > > File
> > > / | \
> > > / | \
> > > Print Exit Edit
> > > / \
> > > Copy Paste
>
> > > as an example, I could easily get a pointer to the "Edit" node.
>
> > Its basically a directory tree e.g like a disc file system. Use a path
> > string to identify/return the required node etc ( and can add similar
> > complexities e.g absolute relative) but there is no standard library
> > way. AFAIK speed is not critical even for large menus though.
>
> > regards
> > Andy Little
>
> Could you elaborate a litlte more on the string path setup? I assume
> you mean something like "File\Edit\Paste".
Yep.
Which sounds good but how
> do I store these all together?
simply as a string:
std::string my_path = "File\Edit\Paste";
This is the higher level abstraction concisely representing a node in
a tree.
And how does "File\Edit" know that "File
> \Edit\Paste" and "..\Copy" are its children?
It has to go looking. You only need a particular node when you need it
as it were. You need to provide mechanisms to detect and report
errors, if a node doesnt exist that you thought did.
As a start it may be worth working on a function to parse a text
path("File/Edit/Paste") into a list of strings(say):
std::list<std::string> make_internal_path( std:string const &
user_path);
The returned list would then contain "File", "Edit", "Paste" as
separate strings
Once you have implemented that then you could implement something like
Alexanders tree and see how you can use the list of strings to try to
find a node in the tree (and what to do if you cant find it).
regards
Andy Little
-
Re: Data Structure for a Menu Tree
On 6 Jun, 12:27, kwikius <a...@servocomm.freeserve.co.uk> wrote:
> On 5 Jun, 19:26, Travis <travis.bow...@> wrote:
> And how does "File\Edit" know that "File
>
> > \Edit\Paste" and "..\Copy" are its children?
<...>
> As a start it may be worth working on a function to parse a text
> path("File/Edit/Paste") into a list of strings(say):
BTW . Its probably best not to use "\" as a separator as its used for
escape characters ( e.g.( "\n") ). Not very pretty. probably best
avoided.
regards
Andy Little
Similar Threads
-
By Application Development in forum lisp
Replies: 7
Last Post: 12-17-2007, 06:56 PM
-
By Application Development in forum C
Replies: 2
Last Post: 10-30-2007, 09:58 PM
-
By Application Development in forum C
Replies: 1
Last Post: 10-30-2007, 06:01 PM
-
By Application Development in forum C
Replies: 4
Last Post: 10-30-2007, 03:21 PM
-
By Application Development in forum XML SOAP
Replies: 2
Last Post: 11-15-2005, 12:52 AM