A command-line client for interacting with "book" and "member" servers via XMLRPC calls. Servers were created by other students.

menu.h 3.6KB

    // file: menu.h // Rick // Menu class specification // Last update 1/05 #ifndef __MENU__ #define __MENU__ #include <iostream> #include <ctype.h> #include <string> // The Menu class provides an ADT for constructing, maintaining, and // executing menus. The menu is given a string description to display // and a pointer. The pointer is either to a void function (taking a // void parameter list) which is to be executed when the selection is // chosen by the user, OR to another object of class Menu. The menu // is written to the standard output and the selection is read from the // standard input. // The install_* methods allow for supplying a menu title, menu items // for actions, and menu items for submenus. // The run method presents the menu on the screen, // gets the users input and checks for it being valid, and then // executes the appropriate action. Invalid entries produce // an error message and the user is given the menu again. // A "Quit" menu selection is automatically added to the menu and its // selection will return control to the menu which invoked it or to // the calling function (in the event it is the top level menu). // Good Luck using namespace std; typedef string String; typedef void (*fnptr) (void); const int MAXENTRIES = 7; // maximum number of entries const int MAXENTLEN = 30; // maximum length of line class Menu { String title; // Menu title line int num_entries; // current # of menu choices String entries_str[MAXENTRIES]; // text for menu choices struct calls { // address for either function int fn; // to call or menu object to union fn_or_class { // message fnptr callfn; Menu * msgmenu; } addr; } entries_fn[MAXENTRIES]; public: Menu(); // function: constructor void install_title(char title[]); // function: places title on menu // Postcondition: Passed parameter becomes name of menu, to // be displayed at the top of the menu int install_entry(char entry[], // c-style string - entry text fnptr action); // pointer to action function // function: places menu item in list when a function is provided // as the associated action // Preconditon: entry is a c-style string, second param must be the // name of a void function with a void parameter list // Postcondition: the entry is placed in the menu and the specified // function is the action associated with the item // Returns 1 if successful, 0 if menu is full int install_entry(char entry[], // c-style string - entry text Menu * action); // pointer to action menu // function: places a menu item in list when a Menu object is provided // as the associated action // Precondition: entry is a c-style string, second param is a pointer // to a Menu object // Postconditon: the entry is placed in the menu and the specified // menu becomes the associated action // Returns 1 if successful, 0 if menu is full void run(void); // function: "executes" the menu // Postcondition: menu displays itself and manages execution until // "exit" option is selected private: void cursor(const int, const int); // places cursor on screen void cls(void); // clears screen }; #endif