-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrocerylist.h
65 lines (53 loc) · 1.81 KB
/
grocerylist.h
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
57
58
59
60
61
62
63
64
65
#ifndef GROCERYLIST_H
#define GROCERYLIST_H
#include "recipe.h"
#include <vector>
#include <filesystem>
#include "mylib.h"
/** A grocery list has a list of Alternatives */
class GroceryList {
public:
typedef Recipe::Ingredient::Alternative Alternative;
/** Combine like ingredients into 1 ingredient */
void merge();
/** Add the ingredients of the recipe specified by fullPath to this grocery list */
void addIngredientsOf(Recipe& recipe, bool allRecipes);
void add(Recipe::Ingredient::Alternative& ingredient) { ingredients.push_back(ingredient); }
friend std::ostream& operator<<(std::ostream& os, GroceryList const& list) {
for (std::vector<Recipe::Ingredient::Alternative>::const_iterator i = list.ingredients.begin();
i < list.ingredients.end(); ++i)
{
if (i->amt != 0) //If it hasn't been marked for "deletion"
{
os << *i;
for (std::vector<Recipe::Ingredient::Alternative>::const_iterator itr = list.ownedIngredients.begin();
itr != list.ownedIngredients.end(); ++itr)
{
if (itr->sameType(*i) && itr->isAtLeast(*i))
os << " [owned]";
}
os << std::endl;
}
}
return os;
}
friend std::istream& operator>>(std::istream& is, GroceryList& list) {
while (!is.fail() && !is.eof()) {
Recipe::Ingredient::Alternative ingInput;
is >> ingInput;
if (ingInput.amt != 0)
//if the ingredient wasn't a blank line
{
list.add(ingInput);
}
}
return is;
}
void setOwnedIngreds(std::vector<Recipe::Ingredient::Alternative> const& owned)
{
ownedIngredients = owned;
}
std::vector<Recipe::Ingredient::Alternative> ingredients;
std::vector<Recipe::Ingredient::Alternative> ownedIngredients;
};
#endif