Subversion Repositories programming

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
348 ira 1
/*******************************************************************************
2
 * main.cc
3
 *
4
 * Implementation of the main function.
5
 *
6
 * Copyright 2006, Ira W. Snyder (devel@irasnyder.com)
7
 ******************************************************************************/
340 ira 8
 
346 ira 9
#include <iostream>
340 ira 10
#include <gtkmm/main.h>
11
#include "elevator_window.h"
12
 
13
int main (int argc, char *argv[])
14
{
346 ira 15
    int numFloors = -1;
16
    int numElevators = -1;
17
 
18
    std::cout << "Enter the number of floors [2-10]: ";
19
    std::cin >> numFloors;
20
 
21
    std::cout << "Enter the number of elevators [1-5]: ";
22
    std::cin >> numElevators;
23
 
24
    if (numFloors < 2 || numFloors > 10)
25
    {
26
        std::cerr << "Invalid number of floors" << std::endl;
27
        return 1;
28
    }
29
 
30
    if (numElevators < 1 || numElevators > 5)
31
    {
32
        std::cerr << "Invalid number of elevators" << std::endl;
33
        return 2;
34
    }
35
 
340 ira 36
    // Set up the controller
347 ira 37
    Controller c(numFloors, numElevators);
340 ira 38
 
39
    // Start GTK
40
    Gtk::Main kit (argc, argv);
41
 
42
    // Create the window
347 ira 43
    Elevator_Window window (numFloors, numElevators);
340 ira 44
 
45
    // Set associations
46
    window.set_controller (&c);
47
    c.set_gui (&window);
48
 
49
    // Start the backend
50
    c.start_all_elevators ();
51
 
52
    // Start the GUI
53
    Gtk::Main::run (window);
54
 
55
    return 0;
56
}
57