473,378 Members | 1,383 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,378 software developers and data experts.

menu mechanize with threading

Hi

The program I am trying to make is a basic one, it provides a command
line menu to the user and accepts the choice given by the user
selection from the main menu. it then spawns a new thread to preform
the task chosen while at the same time offers a new sub-menu and a new
prompt according to the selection the user just made.

the program uses composition and inheritance of different types.

the issue I have been pondering about is, how can I set it up so that
by minimum work I can add/remove menu trees as well as firing items
from the main menu as well as the sub-menu.

my thoughts are as follows, "need some guidance":
present each task "menu item" by a Task abstract type.

************************************************** **************
class Task
{
public:
Task()
{
}
virtual void print_item_name()=0;
};
************************************************** **************

for the sake of this discussion, say we have task A and B being the
main menu items.

task A has sub_items "sub_tasks" being A and B, which we will
represent here as AA and AB.

task B has "for now" sub_items "sub_tasks" being A, which we will
represent here as BA,

so we write
************************************************** **************
class A : public Task
{
string item_name;
string sub_list; //A comma separated list (item1,item2,...)
public:
A(string in, string sl): item_name(in), sub_list(sl)
{
}
void print_item_name()
{
cout << item_name << endl;
}
/* fired from main e.g
A a("a", "a,b");
boost::thread thrd( a )
*/
void A::operator()()
{
/* do work */
/* call methods */
}
************************************************** **************
and the same thing for Task B.

now to the main thing
************************************************** **************
int main(){
/* Create the main tasks. */
A a("a", "a,b");
B b("b", "a");

/* Place them in a vector container to use index for selection. */
vector<Task*vTp;
vTp.push_back(a);
vTp.push_back(b);

/* Show menu and thread the task */
for( ;; ) {
for( unsigned short i=0; i<vTp.size(); i++)
cout << "[" << i << "]" << vTp->print_item();

cout << "Select an item from the menu\n:";
unsigned short opt;
cin << opt;
if( opt==9 ) break,
boost::thread thrd( vTp[opt] ); // is this syntax correct?
}
************************************************** **************

now, can I do the same thing
/* Create the SUB tasks. */
/* Place them in a vector container to use index for selection. */
/* Show menu and thread the task */
for the sub menu which has to be placed in each parent menu
operator()() function?
e.g

************************************************** **************
void A::operator()()
{

/* Create the SUB tasks. */
AA aa("aa", "a,b,c,d,e"); //has more sub menus a,b,c,d,e
AB bb("ab", "a,b");

/* Place them in a vector container to use index for selection. */
vector<Task*vTp;
vTp.push_back(aa);
vTp.push_back(ab);

/* Show menu and thread the task */
for( ;; ) {
for( unsigned short i=0; i<vTp.size(); i++)
cout << "[" << i << "]" << vTp->print_item();

cout << "Select an item from the menu\n:";
unsigned short opt;
cin << opt;
if( opt==9 ) break,
boost::thread thrd( vTp[opt] ); // is this syntax correct?
/* do work */
/* call methods */
}
************************************************** **************
now I can just add any item to the main menu or sub items to any sub
menu and write their corresponding operator()() function and I am
done??

thanks

Nov 23 '06 #1
0 1180

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

Similar topics

0
by: zoewu | last post by:
Would anyone help me with this little script that I tried to get some contents from Yahoo Personals by using Perl Mechanize. It doesn't return any results, although I've feed all kinds of browser...
12
by: John | last post by:
I have to write a spyder for a webpage that uses html + javascript. I had it written using mechanize but the authors of the webpage now use a lot of javascript. Mechanize can no longer do the job....
1
by: comeshopcheap | last post by:
Hi I am using this script to access doba.com (I need to download some files) but I keep on being sent back to the login page not the user home page. Any help. I think I may need to use a post...
1
numberwhun
by: numberwhun | last post by:
I am having an issue with understanding something in the WWW::Mechanize module. I have a website which I want to download a whole plethora of pdf files from. It is a site that I have paid to access...
6
by: sureshbup | last post by:
Hi, i am new to perl... i tried this module mechanize. this is the script #!/usr/bin/perl # Include the WWW::Mechanize module use WWW::Mechanize;
0
by: bruce | last post by:
i'm getting the following error: mechanize._response.httperror_seek_wrapper: HTTP Error 500: i'm running python 5.1 and mechanize 0.1.7b I have no idea as to what I have to...
2
by: Rex | last post by:
Hello, I am working on an academic research project where I need to log in to a website (www.lexis.com) over HTTPS and execute a bunch of queries to gather a data set. I just discovered the...
0
by: trihaitran | last post by:
I am trying to write a web scraper and am having trouble accessing pages that require authentication. I am attempting to utilise the mechanize library, but am having difficulties. The site I am...
1
by: tedpottel | last post by:
Hi, I can read the home page using the mechanize lib. Is there a way to load in web pages using filename.html instad of servername/ filename.html. Lots of time the links just have the file...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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.