473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.

Jun 5 '07 #1
6 6121
On 5 Jun, 16:58, Travis <travis.bow...@gmail.comwrote:
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


Jun 5 '07 #2
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
Jun 5 '07 #3
On Jun 5, 10:35 am, kwikius <a...@servocomm.freeserve.co.ukwrote:
On 5 Jun, 16:58, Travis <travis.bow...@gmail.comwrote:
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?

Jun 5 '07 #4
On 5 Jun., 20:26, Travis <travis.bow...@gmail.comwrote:
On Jun 5, 10:35 am, kwikius <a...@servocomm.freeserve.co.ukwrote:
On 5 Jun, 16:58, Travis <travis.bow...@gmail.comwrote:
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);

Jun 5 '07 #5
On 5 Jun, 19:26, Travis <travis.bow...@gmail.comwrote:
On Jun 5, 10:35 am, kwikius <a...@servocomm.freeserve.co.ukwrote:


On 5 Jun, 16:58, Travis <travis.bow...@gmail.comwrote:
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::stringmake_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

Jun 6 '07 #6
On 6 Jun, 12:27, kwikius <a...@servocomm.freeserve.co.ukwrote:
On 5 Jun, 19:26, Travis <travis.bow...@gmail.comwrote:
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


Jun 6 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: clintonG | last post by:
I need a tree control and seek referrals to your preferred solution(s) that will support mapping XML data structures to the tree. <%= Clinton Gallagher
4
by: Marek Mänd | last post by:
var criterions = { subconds:{ tree: } } // MUSIC , {condID:17, strrep:'Music', subconds:{ tree:
4
by: Sasha | last post by:
Hi everyone, I would like to hear your opinions about a design solution I am contemplating. The problem I am following: Write an editor for a data structure that is recursive in nature. In...
4
by: Stephan Tobies | last post by:
Hi everyone, I am looking for a good data structure that could be used to represent families of trees with shared sub-trees and copy-on-write semantics. On a very abstract level, I would like...
1
by: mondenkind | last post by:
Hi folks, I have the following problem and maybe someone give me a hint how to solve it: I have an .xml file that contains a menu / tree structure which i transform with XSLT and JavaScript to a...
4
by: Alexander Adam | last post by:
Hello folks, I got a few question on some basic data structure stuff. Sorry if those questions might sound too easy or such but after googling a lot I didn't find a real answer to all those...
7
by: PaowZ | last post by:
Hi there! I'm facing an issue concerning tree data structure in php. In others languages, I just need to create a root node which I bind pointers of instances representing others nodes. But I...
4
by: sharan | last post by:
Hello Friends I have a problem in Data Structure (In C) i want to implement a General tree having three child nodes of each parent node ...please send me any simple Example( code) by which i can...
2
by: nomad | last post by:
I am writing a c++ program and will be implementing a console menu driven prompt. The menu will have several options, and sub-menus may also have multiple options. What is the best data structure...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.