Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
widwork.cpp
Go to the documentation of this file.
1
29#include <algorithm>
30#include <examples.h>
31#include <widwork.h>
32
33std::ostream& operator<< ( std::ostream& out, const Widget& w )
34{
35 return out << "Widget " << w.id;
36}
37
38bool operator== (const Widget& lhs, const Widget& rhs) {
39 return lhs.id == rhs.id;
40}
41
42
43bool operator< (const Widget& lhs, const Widget& rhs) {
44 return lhs.id < rhs.id;
45}
46
47
48bool WidgetTester::operator () (const Widget & wid, int testid) const
49{
50 return wid.id == testid;
51}
52
53
54void inventory::order (int wid) {
55
56 std::cout << "Received order for widget type " << wid << std::endl;
57
58 widgetList::iterator
59 wehave = std::find_if (on_hand.begin (), on_hand.end (),
60 std::bind2nd (WidgetTester (), wid));
61 if (wehave != on_hand.end ()) {
62 std::cout << "Ship " << *wehave << std::endl;
63 on_hand.erase (wehave);
64 }
65 else {
66 std::cout << "Back order widget of type " << wid << std::endl;
67 on_order.push_front (wid);
68 }
69}
70
71
72void inventory::receive (int wid) {
73
74 std::cout << "Received shipment of widget type " << wid << std::endl;
75
76 idList::iterator weneed = std::find (on_order.begin (),
77 on_order.end (), wid);
78 if (weneed != on_order.end ()) {
79 std::cout << "Ship " << Widget (wid) << " to fill back order"
80 << std::endl;
81 on_order.erase (weneed);
82 }
83 else
84 on_hand.push_front (Widget (wid));
85}
86
87
88int main ()
89{
90 std::cout << "Widget Works test program" << std::endl;
91
92 inventory stock;
93 stock.receive (1);
94 stock.receive (2);
95 stock.receive (3);
96 stock.order (2);
97 stock.order (2);
98 stock.order (3);
99 stock.receive (2);
100
101 std::cout << "End of widget words test program" << std::endl;
102
103 return 0;
104}
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#define rhs
Definition 17.names.cpp:536
#define w
Definition 17.names.cpp:139
#define lhs
Definition 17.names.cpp:489
const int out
int id
Definition widwork.h:44
void receive(int wid)
Definition widwork.cpp:72
void order(int wid)
Definition widwork.cpp:54
bool operator()(const Widget &wid, int testid) const
Definition widwork.cpp:48
bool operator==(const Widget &lhs, const Widget &rhs)
Definition widwork.cpp:38
std::ostream & operator<<(std::ostream &out, const Widget &w)
Definition widwork.cpp:33
bool operator<(const Widget &lhs, const Widget &rhs)
Definition widwork.cpp:43
int main()
Definition widwork.cpp:88