toaster to fry eggs was RE: [wellylug] Aims or Objectives
Jonathan Harker
jharker at massey.ac.nz
Tue Apr 20 15:02:29 NZST 2004
Damon Lynch wrote:
> Chris Harris wrote:
> >> I also can't get my toaster to fry eggs - damn. I must have bought the
> >> wrong type of toaster. Perhaps if I upgrade the firmware??
> >
> > #include <toaster>
> > #define PLATE = "aluminium foil plate"
> >
> > main(){
> > cooker toaster;
> > extern food eggs, oil;
> >
> > toaster.brownness = toaster.brownness.max();
> > PLATE += toaster;
> > PLATE += oil;
> > PLATE += eggs;
> > toaster.state = on;
> > while(eggs != cooked){
> > wait();
> > }
> > toaster.state = off;
> > eggs.serve();
> > }
>
> Dude, problem -- you coded it in C, with no error checking! What
> happens when the oil catches fire, you'll more than dump core and spill
> the yoke, you'll burn your whole house down ;-)
// Let's do it in C++ then (too much spare time today...!)
#include <toaster>
#include <food>
#include <crockery>
#include <memory>
#include <threads>
using namespace std;
using namespace threads;
using namespace kitchen;
main()
{
try {
auto_ptr<Eggs*> eggs(new FreeRangeEggs());
auto_ptr<Oil*> oil(new OliveOil());
auto_ptr<Bread*> slice(Vogels::getSlice());
auto_ptr<Toaster*> toaster(new Toaster());
auto_ptr<Pan*> pan(new Pan());
auto_ptr<Plate*> plate(new Plate(PlateType.Aluminium));
thread t(toaster->toast(slice, Toaster::MAX_BROWNNESS));
t.join();
// heat the oil at 80% heat, checking every 5 seconds
pan->add(oil);
while (! oil->hot) pan->heat(0.8, 5);
pan->add(eggs);
while (! eggs->done()) pan->heat(0.6, 10);
// wait for toast if necessary
pan->keepwarm();
if (thread.running(t)) thread.wait_for(t);
plate->add(slice);
pan->transfer(eggs, plate);
}
catch (KitchenOnFireException& ex) {
cout << "The kitchen is on fire." << endl;
try {
if (! deployFireExtinguisher()) {
dialFireService();
escape();
}
}
catch (...) {
panic();
}
return 1;
}
catch (BurntToastException& ex) {
cout << "Sorry, your toast is burnt." << endl;
openKitchenWindow();
return 1;
}
catch (...) {
cout << "Sorry, something unexpected happened." << endl;
return 1;
}
return 0;
}
More information about the wellylug
mailing list