Author: faridz
Date: Wed Nov 14 09:34:27 2007
New Revision: 594966
URL: http://svn.apache.org/viewvc?rev=594966&view=rev
Log:
20071114 Farid Zaripov <farid_zaripov@epam.com>
STDCXX661
* tutorial/icecream.cpp (class event): Removed unused operator>().
(eventComparator): Defined as separate struct instead of typedef
std::greater<>.
* tutorial/out/icecream.out: Updated .out file to reflect the
changes above.
Modified:
incubator/stdcxx/branches/4.2.x/examples/tutorial/icecream.cpp
incubator/stdcxx/branches/4.2.x/examples/tutorial/out/icecream.out
Modified: incubator/stdcxx/branches/4.2.x/examples/tutorial/icecream.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/branches/4.2.x/examples/tutorial/icecream.cpp?rev=594966&r1=594965&r2=594966&view=diff
==============================================================================
 incubator/stdcxx/branches/4.2.x/examples/tutorial/icecream.cpp (original)
+++ incubator/stdcxx/branches/4.2.x/examples/tutorial/icecream.cpp Wed Nov 14 09:34:27 2007
@@ 41,16 +41,17 @@
event (unsigned int t) : time (t)
{ }
 // Execute event my invoking this method.
+ // Execute event by invoking this method.
virtual void processEvent () = 0;
 bool operator> ( const event* evt_ ) {
 return time > evt_>time;
 }
const unsigned int time;
};
typedef std::greater<event*> eventComparator;
+struct eventComparator {
+ bool operator() (const event * left, const event * right) {
+ return left>time > right>time;
+ }
+};
// Framework for discrete eventdriven simulations.
@@ 66,14 +67,14 @@
protected:
std::priority_queue<event*,
std::vector<event *, std::allocator<event*> >,
 eventComparator > eventQueue;
+ eventComparator> eventQueue;
};
void simulation::run () {

+
while (! eventQueue.empty ()) {

+
event * nextEvent = eventQueue.top ();
eventQueue.pop ();
time = nextEvent>time;
@@ 147,7 +148,7 @@
void arriveEvent::processEvent () {

+
if (theSimulation.canSeat (size))
theSimulation.scheduleEvent
(new orderEvent (time + 1 + irand (4), size));
@@ 155,7 +156,7 @@
void orderEvent::processEvent () {

+
// Each person orders some number of scoops.
for (unsigned int i = 0; i < size; i++)
theSimulation.order (1 + irand (4));
@@ 174,7 +175,7 @@
// If sufficient room then seat customers.
bool storeSimulation::canSeat (unsigned int numberOfPeople) {

+
std::cout << "Time: " << time;
std::cout << " group of " << numberOfPeople << " customers arrives";
@@ 192,7 +193,7 @@
// Service icecream, compute profits.
void storeSimulation::order (unsigned int numberOfScoops) {

+
std::cout << "Time: " << time << " serviced order for "
<< numberOfScoops << '\n';
profit += 0.35 * numberOfScoops;
@@ 201,7 +202,7 @@
// People leave, free up chairs.
void storeSimulation::leave (unsigned int numberOfPeople) {

+
std::cout << "Time: " << time << " group of size "
<< numberOfPeople << " leaves\n";
freeChairs += numberOfPeople;
@@ 209,7 +210,7 @@
int main () {

+
std::cout << "Ice Cream Store simulation from Chapter 9\n";
// Load queue with some number of initial events.
Modified: incubator/stdcxx/branches/4.2.x/examples/tutorial/out/icecream.out
URL: http://svn.apache.org/viewvc/incubator/stdcxx/branches/4.2.x/examples/tutorial/out/icecream.out?rev=594966&r1=594965&r2=594966&view=diff
==============================================================================
 incubator/stdcxx/branches/4.2.x/examples/tutorial/out/icecream.out (original)
+++ incubator/stdcxx/branches/4.2.x/examples/tutorial/out/icecream.out Wed Nov 14 09:34:27
2007
@@ 11,46 +11,46 @@
pumping queue with event 17
Time: 0 group of 2 customers arrives is seated
Time: 0 group of 4 customers arrives is seated
Time: 3 serviced order for 3
+Time: 2 group of 3 customers arrives is seated
Time: 3 serviced order for 4
Time: 3 serviced order for 1
Time: 3 serviced order for 1
Time: 10 group of size 4 leaves
Time: 2 group of 3 customers arrives is seated
Time: 5 serviced order for 4
+Time: 3 serviced order for 3
+Time: 4 serviced order for 4
+Time: 4 serviced order for 1
+Time: 4 group of size 4 leaves
+Time: 5 serviced order for 2
Time: 5 serviced order for 1
Time: 5 serviced order for 3
Time: 13 group of size 3 leaves
Time: 7 group of 1 customers arrives is seated
Time: 8 serviced order for 3
Time: 10 group of size 1 leaves
+Time: 7 group of size 2 leaves
+Time: 7 group of size 3 leaves
Time: 8 group of 3 customers arrives is seated
Time: 11 serviced order for 4
Time: 11 serviced order for 3
Time: 11 serviced order for 1
Time: 19 group of size 3 leaves
Time: 12 group of 3 customers arrives is seated
Time: 16 serviced order for 2
Time: 16 serviced order for 2
Time: 16 serviced order for 4
Time: 25 group of size 3 leaves
+Time: 10 serviced order for 3
Time: 12 group of 2 customers arrives is seated
Time: 15 serviced order for 3
Time: 15 serviced order for 4
Time: 22 group of size 2 leaves
+Time: 12 group of 3 customers arrives is seated
+Time: 12 serviced order for 2
+Time: 12 serviced order for 2
+Time: 12 serviced order for 4
Time: 12 group of 1 customers arrives is seated
Time: 15 serviced order for 4
Time: 18 group of size 1 leaves
+Time: 14 serviced order for 3
+Time: 14 serviced order for 4
Time: 14 group of 2 customers arrives is seated
Time: 15 serviced order for 3
Time: 15 serviced order for 2
Time: 20 group of size 2 leaves
+Time: 15 serviced order for 4
+Time: 16 serviced order for 1
+Time: 16 serviced order for 3
+Time: 16 serviced order for 2
+Time: 17 serviced order for 2
+Time: 17 serviced order for 2
Time: 17 group of 2 customers arrives is seated
Time: 19 serviced order for 2
Time: 19 serviced order for 3
Time: 29 group of size 2 leaves
Time: 4 serviced order for 3
Time: 4 serviced order for 4
Time: 10 group of size 2 leaves
Total profits 22.4
+Time: 18 group of size 1 leaves
+Time: 19 group of size 1 leaves
+Time: 21 group of size 2 leaves
+Time: 21 group of size 3 leaves
+Time: 21 group of size 3 leaves
+Time: 21 serviced order for 3
+Time: 21 serviced order for 4
+Time: 24 group of size 2 leaves
+Time: 27 group of size 2 leaves
+Total profits 20.65
End of ice cream store simulation
