-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeal.hpp
56 lines (44 loc) · 1.42 KB
/
meal.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef MEAL_HPP
#define MEAL_HPP
#include "recipe.h"
#include <vector>
/** A meal is a list of recipes which are eaten in one meal.
It should have 2 vegetable servings and 1 meat serving. */
class Meal {
public:
friend class MealSchedule;
const static unsigned MEAT_SERVINGS = 1;
const static unsigned VEG_SERVINGS = 2;
Meal() : meat(0), veg(0), _out(0) {}
/** Returns whether it has the right amount of food for a meal */
bool isFull();
/** Check whether a recipe will "fit" in this meal */
bool canBeAdded(Recipe& recipe);
/** Tries to add a recipe to the meal. If it won't "fit", returns false;
otherwise, returns true. */
bool add(Recipe& recipe);
friend std::ostream& operator<<(std::ostream& os, Meal& meal)
{
if (meal.isOut()) os << "OUT";
else
{
std::vector<Recipe>& r = meal.recipes;
for (std::vector<Recipe>::iterator recipe = r.begin(); recipe != r.end(); )
{
os << *recipe;
if (++recipe != r.end()) os << ", ";
}
}
return os;
}
void out() { _out = true; }
bool isOut() const { return _out; }
private:
std::vector<Recipe> recipes; //A list might be better, but it won't let me
//get the next element given a pointer to an element (which is strange
//because that's what lists are supposed to do)
unsigned meat, veg;
bool _out; //Stores whether the meal is "out" - i.e. if true means I'm going to a
//restaurant or otherwise don't have to cook
};
#endif