Exemplo n.º 1
0
MenuComponent* Menu::activate()
{
    MenuComponent* pComponent = _menu_components[_cur_menu_component_num];

    if (pComponent == NULL)
        return NULL;

    return pComponent->select();
}
Exemplo n.º 2
0
 MenuComponent* next() {
     if (hasNext()) {
         Iterator* iterator = m_stack.top();
         MenuComponent* component = iterator->next();
         m_stack.push(component->createIterator());
         return component;
     } else {
         return NULL;
     }
 }
	public: virtual void print() {
		std::cout << std::endl << getName().c_str();
		std::cout << ", " << getDescription().c_str() << std::endl;
		std::cout << "---------------------" << std::endl;
  
		std::vector<MenuComponent*>::iterator itr = menuComponents.begin();
		while (itr != menuComponents.end()) {
			MenuComponent* menuComponent = *itr++;
			menuComponent->print();
		}
	}
Exemplo n.º 4
0
 void print() {
     std::cout << "\n" << getName();
     std::cout << ", " << getDescription() << std::endl;
     std::cout << "---------------------" << std::endl;
     Iterator* iterator = createIterator();
     while (iterator->hasNext()) {
         MenuComponent* menuComponent = iterator->next();
         menuComponent->print();
     }
     delete iterator;
 }
Exemplo n.º 5
0
Menu* Menu::activate()
{
    if (!_num_components)
        return nullptr;

    MenuComponent* pComponent = _menu_components[_current_component_num];

    if (pComponent == nullptr)
        return nullptr;

    return pComponent->select();
}
MenuComponent* CompositeIterator::next()
{
    if(hasNext())
    {
        Iterator* iterator = m_stack.top();
        MenuComponent *component = iterator->next();
        if(dynamic_cast<Menu*>(component) != NULL)
        {
            m_stack.push(component->createIterator());
        }
        return component;
    }
    else
    {
        return NULL;
    }
}
void Waitress::printVegetarianMenu()
{
    Iterator *iterator = allMenus->createIterator();
    cout << "\nVEGETARIAN MENU\n---------------------------" << endl;
    while(iterator->hasNext())
    {
        MenuComponent *menuComponent = iterator->next();
        try
        {
            if(menuComponent->isVegetarian())
            {
                menuComponent->print();
            }
        }
        catch(UnsupportedOperationException &e)
        {
        }
    }
    delete iterator;
}
int main(int argc, char* argv[]) {
	MenuComponent* pancakeHouseMenu = 
		new Menu("PANCAKE HOUSE MENU", "Breakfast");
	MenuComponent* dinerMenu = 
		new Menu("DINER MENU", "Lunch");
	MenuComponent* cafeMenu = 
		new Menu("CAFE MENU", "Dinner");
	MenuComponent* dessertMenu = 
		new Menu("DESSERT MENU", "Dessert of course!");
	MenuComponent* coffeeMenu = new Menu("COFFEE MENU", "Stuff to go with your afternoon coffee");

	MenuComponent* allMenus = new Menu("ALL MENUS", "All menus combined");

	allMenus->add(pancakeHouseMenu);
	allMenus->add(dinerMenu);
	allMenus->add(cafeMenu);

	pancakeHouseMenu->add(new MenuItem(
		"K&B's Pancake Breakfast", 
		"Pancakes with scrambled eggs, and toast", 
		true,
		2.99));
	pancakeHouseMenu->add(new MenuItem(
		"Regular Pancake Breakfast", 
		"Pancakes with fried eggs, sausage", 
		false,
		2.99));
	pancakeHouseMenu->add(new MenuItem(
		"Blueberry Pancakes",
		"Pancakes made with fresh blueberries, and blueberry syrup",
		true,
		3.49));
	pancakeHouseMenu->add(new MenuItem(
		"Waffles",
		"Waffles, with your choice of blueberries or strawberries",
		true,
		3.59));
	dinerMenu->add(new MenuItem(
		"Vegetarian BLT",
		"(Fakin') Bacon with lettuce & tomato on whole wheat", 
		true, 
		2.99));
	dinerMenu->add(new MenuItem(
		"BLT",
		"Bacon with lettuce & tomato on whole wheat", 
		false, 
		2.99));
	dinerMenu->add(new MenuItem(
		"Soup of the day",
		"A bowl of the soup of the day, with a side of potato salad", 
		false, 
		3.29));
	dinerMenu->add(new MenuItem(
		"Hotdog",
		"A hot dog, with saurkraut, relish, onions, topped with cheese",
		false, 
		3.05));
	dinerMenu->add(new MenuItem(
		"Steamed Veggies and Brown Rice",
		"Steamed vegetables over brown rice", 
		true, 
		3.99));
	dinerMenu->add(new MenuItem(
		"Pasta",
		"Spaghetti with Marinara Sauce, and a slice of sourdough bread",
		true, 
		3.89));

	dinerMenu->add(dessertMenu);

	dessertMenu->add(new MenuItem(
		"Apple Pie",
		"Apple pie with a flakey crust, topped with vanilla icecream",
		true,
		1.59));
	dessertMenu->add(new MenuItem(
		"Cheesecake",
		"Creamy New York cheesecake, with a chocolate graham crust",
		true,
		1.99));
	dessertMenu->add(new MenuItem(
		"Sorbet",
		"A scoop of raspberry and a scoop of lime",
		true,
		1.89));
	cafeMenu->add(new MenuItem(
		"Veggie Burger and Air Fries",
		"Veggie burger on a whole wheat bun, lettuce, tomato, and fries",
		true, 
		3.99));
	cafeMenu->add(new MenuItem(
		"Soup of the day",
		"A cup of the soup of the day, with a side salad",
		false, 
		3.69));
	cafeMenu->add(new MenuItem(
		"Burrito",
		"A large burrito, with whole pinto beans, salsa, guacamole",
		true, 
		4.29));

	cafeMenu->add(coffeeMenu);

	coffeeMenu->add(new MenuItem(
		"Coffee Cake",
		"Crumbly cake topped with cinnamon and walnuts",
		true,
		1.59));
	coffeeMenu->add(new MenuItem(
		"Bagel",
		"Flavors include sesame, poppyseed, cinnamon raisin, pumpkin",
		false,
		0.69));
	coffeeMenu->add(new MenuItem(
		"Biscotti",
		"Three almond or hazelnut biscotti cookies",
		true,
		0.89));

	Waitress* waitress = new Waitress(allMenus);

	waitress->printMenu();

	return 0;
}
Exemplo n.º 9
0
int main() {
    cout << "Test harness for Menu Composite and Iterator" << endl << endl;

    // create a collection of menus to manipulate
    MenuComponent *menus[10] = {0};

    // enable reading of boolean values "true" and "false"
    cin >> boolalpha;

    // get input command
    cout << "Command: ";
    string command;
    cin >> command;

    Op op = convertOp(command);

    //**********************************
    // Populate the Composite Menu
    //**********************************
    while (!cin.eof() && (op != DONE)) {
        try {
            switch (op) {

                // new menu; delete old menu
                case MENU: {
                    int index = readIndex(cin);
                    string name = readName(cin);
                    delete menus[index];
                    menus[index] = new Menu(name);
                    break;
                }

                    // add a new menu item
                case ITEM: {
                    int index = readIndex(cin);
                    string name = readName(cin);

                    float price;
                    int calories;
                    bool veg;
                    cin >> price >> calories >> veg;
                    if (cin.fail()) {
                        sinCleanup(cin);
                        throw SyntaxError();
                    }

                    delete menus[index];
                    menus[index] = new MenuItem(name, price, calories, veg);
                    break;
                }

                    // add a menu/menuitem (index2) to be a child of a menu (index)
                case AddC: {
                    int index = readIndex(cin);
                    int index2 = readIndex(cin);
                    if (!menus[index]) throw NoMenu(index);
                    if (!menus[index2]) throw NoMenu(index2);
                    menus[index]->add(menus[index2]);
                    menus[index2] = NULL;
                    break;
                }

                    // print all elements of a menu
                case Print: {
                    int index = readIndex(cin);
                    if (!menus[index]) throw NoMenu(index);

                    for (auto it = menus[index]->begin(); it != menus[index]->end(); ++it) {
                        cout << *it << endl;
                    }

                    break;
                }

                    // remove a menuitem or submenu (name) from a menu (index)
                case Remove: {
                    int index = readIndex(cin);
                    if (!menus[index]) throw NoMenu(index);

                    string name = readName(cin);
                    menus[index]->remove(name);
                    break;
                }

                default: {
                    cout << "Invalid command." << endl;
                    break;
                }
            }// switch command
        } // try

        catch (NoMenu &e) {
            cout << "Menu Element " << e.index() << " does not exist." << endl;
        }
        catch (BadIndex &) {
            cout << "Invalid name of menu!" << endl;
        }
        catch (SyntaxError &) {
            cout << "Command has syntax errors. No change to menu." << endl;
        }
        catch (MenuComponent::InvalidOp &) {
            cout << "Command is invalid on Menu Items. No change to menus." << endl;
        }

        cout << endl << "Command: ";
        cin >> command;
        op = convertOp(command);


    } // while cin OK

    cout.precision(2);
    cout.setf(ios::fixed, ios::floatfield);

    cout << "\nEnter name of menu element to be printed: ";
    string name = readName(cin);

    MenuComponent *main = menus[0];
    if (main == NULL) {
        cout << "\nMenu Element 0 does not exist." << endl;
    } else {
        // Find the element with the matching name
        auto it = std::find_if(main->begin(), main->end(), [name](const MenuComponent &m) {
            return m.name() == name;
        });
        if (it == main->end()) {
            cout << "\nMenu " << name << " does not exist.\n";
        } else {
            // Keep track of the depth
            int depth = (int) it->menuDepth().length();
            cout << endl;

            while (it != main->end()) {
                cout << *it << endl;
                ++it;

                // If the depth is equal to or less than the element we searched for
                // it's not a subelement so break out.
                if (it == NULL || it->menuDepth().length() <= depth) {
                    break;
                }
            }
        }
    }

    for (int i = 0; i < 10; i++) {
        if (menus[i])
            delete menus[i];
    }
}
Exemplo n.º 10
0
 	public: virtual void printMenu() {
		allMenus->print();
	}
Exemplo n.º 11
0
		vec3<float> recursivePosition() const {
			if (m_pParent) {
				return m_pParent->recursivePosition() + m_worldPosition;
			}
			return m_worldPosition;
		}
Exemplo n.º 12
0
 bool operator()(const MenuComponent& m) { return m.name() == item_ && m.isLeaf(); }
Exemplo n.º 13
0
int main() {
    cout << "Test harness for Menu Composite and Iterator" << endl << endl;

    // create a collection of menus to manipulate
    MenuComponent *menus[10] = {0};

    // enable reading of boolean values "true" and "false"
    cin >> boolalpha;

    // get input command
    cout << "Command: ";
    string command;
    cin >> command;

    Op op = convertOp(command);

    //**********************************
    // Populate the Composite Menu
    //**********************************
    while (!cin.eof() && (op != DONE)) {
        try {
            switch (op) {

                // new menu; delete old menu
                case MENU: {
                    int index = readIndex(cin);
                    string name = readName(cin);
                    delete menus[index];
                    menus[index] = new Menu(name);
                    break;
                }

                    // add a new menu item
                case ITEM: {
                    int index = readIndex(cin);
                    string name = readName(cin);

                    float price;
                    int calories;
                    bool veg;
                    cin >> price >> calories >> veg;
                    if (cin.fail()) {
                        sinCleanup(cin);
                        throw SyntaxError();
                    }

                    delete menus[index];
                    menus[index] = new MenuItem(name, price, calories, veg);
                    break;
                }

                    // add a menu/menuitem (index2) to be a child of a menu (index)
                case AddC: {
                    int index = readIndex(cin);
                    int index2 = readIndex(cin);
                    if (!menus[index]) throw NoMenu(index);
                    if (!menus[index2]) throw NoMenu(index2);
                    menus[index]->add(menus[index2]);
                    menus[index2] = NULL;
                    break;
                }

                    // print all elements of a menu
                case Print: {
                    int index = readIndex(cin);
                    if (!menus[index]) throw NoMenu(index);

                    for (auto it = menus[index]->begin(); it != menus[index]->end(); ++it) {
                        cout << *it << endl;
                    }

                    break;
                }

                    // remove a menuitem or submenu (name) from a menu (index)
                case Remove: {
                    int index = readIndex(cin);
                    if (!menus[index]) throw NoMenu(index);

                    string name = readName(cin);
                    menus[index]->remove(name);
                    break;
                }

                default: {
                    cout << "Invalid command." << endl;
                    break;
                }
            }// switch command
        } // try

        catch (NoMenu &e) {
            cout << "Menu Element " << e.index() << " does not exist." << endl;
        }
        catch (BadIndex &) {
            cout << "Invalid name of menu!" << endl;
        }
        catch (SyntaxError &) {
            cout << "Command has syntax errors. No change to menu." << endl;
        }
        catch (MenuComponent::InvalidOp &) {
            cout << "Command is invalid on Menu Items. No change to menus." << endl;
        }

        cout << endl << "Command: ";
        cin >> command;
        op = convertOp(command);


    } // while cin OK

    cout.precision(2);
    cout.setf(ios::fixed, ios::floatfield);

    MenuComponent *main = menus[0];
    vector<Order *> orders;
    command = "";
    string name;

    cout << "\nMay I take your order?\n> ";
    if (main == NULL) {
        cout << "\nMenu Element 0 does not exist." << endl;
    } else {
        while (true) {
            cin >> command;
            if (command == "t") {
                break;
            } else if (command == "o") {
                name = readName(cin);

                // Find the menu item matching the name
                auto it = std::find_if(main->begin(), main->end(), is_item(name));

                // Make sure the item exists
                if (it != main->end()) {

                    // Check our vector of orders for the menu item, and if it exists increment the number of the order
                    // Else create a new order and add it to our orders vector
                    auto it_order = std::find_if(orders.begin(), orders.end(), order_exists(name));
                    if (it_order != orders.end()) {
                        (*it_order)->num++;
                    } else {
                        orders.push_back(new Order(it.operator->()));
                    }
                }
            } else {
                cout << "Invalid order." << endl;
            }
            cout << "> ";
        }

        // Print out all the orders
        std::for_each(orders.begin(), orders.end(), printOrder);

        // Sum up the orders and print a total
        float init = 0;
        float total = std::accumulate(orders.begin(), orders.end(), init, sum);
        cout << "TOTAL = $" << total << endl;

        // Remove allocated memory
        for (auto it = orders.begin(); it != orders.end(); ++it) {
            delete *it;
        }
    }


    for (int i = 0; i < 10; i++) {
        if (menus[i])
            delete menus[i];
    }
}
Exemplo n.º 14
0
bool operator==(const MenuComponent &a, const MenuComponent &b) {
    return a.name() == b.name() && a.menuDepth() == b.menuDepth();
}
Exemplo n.º 15
0
 void printMenu() const {
     _allMenus->print();
 }