Subversion Repositories programming

Rev

Rev 334 | Rev 337 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 334 Rev 335
Line 51... Line 51...
51
{
51
{
52
    int i = ((int)current_floor) + 1;
52
    int i = ((int)current_floor) + 1;
53
    int count = 0;
53
    int count = 0;
54
 
54
 
55
    for (/* see above */; i<num_floors; i++)
55
    for (/* see above */; i<num_floors; i++)
56
        if (stop_at_floors[i])
56
        if (stop_at_floors.at(i))
57
            count++;
57
            count++;
58
 
58
 
59
    return count;
59
    return count;
60
}
60
}
61
 
61
 
Line 71... Line 71...
71
    if (near_a_floor ())
71
    if (near_a_floor ())
72
        i = (int)current_floor - 1;
72
        i = (int)current_floor - 1;
73
    else
73
    else
74
        i = (int)current_floor;
74
        i = (int)current_floor;
75
 
75
 
76
    for (/* see above */; i>0; i--)
76
    for (/* see above */; i>=0; i--)
77
        if (stop_at_floors[i])
77
        if (stop_at_floors.at(i))
78
            count++;
78
            count++;
79
 
79
 
80
    return count;
80
    return count;
81
}
81
}
82
 
82
 
83
void Elevator::push_button (int floor)
83
void Elevator::push_button (int floor)
84
{
84
{
85
    assert (floor < num_floors);
85
    assert (floor < num_floors);
86
    assert (floor >= 0);
86
    assert (floor >= 0);
87
 
87
 
88
    this->stop_at_floors[floor] = true;
88
    this->stop_at_floors.at(floor) = true;
89
}
89
}
90
 
90
 
91
/**
91
/**
92
 * This function is the entry point for a thread.
92
 * This function is the entry point for a thread.
93
 *
93
 *
Line 148... Line 148...
148
            if (should_stop_at_current_floor ())
148
            if (should_stop_at_current_floor ())
149
            {
149
            {
150
#ifndef QUIET
150
#ifndef QUIET
151
                printf ("stop at floor %d -- while going up\n", (int)(current_floor+0.5));
151
                printf ("stop at floor %d -- while going up\n", (int)(current_floor+0.5));
152
#endif
152
#endif
153
                stop_at_floors[(int)(current_floor+0.5)] = false;
153
                stop_at_floors.at((int)(current_floor+0.5)) = false;
154
                have_user_enter_buttons ();
154
                have_user_enter_buttons ();
155
            }
155
            }
156
 
156
 
157
            /* Decide to sit idle if we have no more floors to stop at */
157
            /* Decide to sit idle if we have no more floors to stop at */
158
            if (!has_floors_to_stop_at ())
158
            if (!has_floors_to_stop_at ())
Line 187... Line 187...
187
            if (should_stop_at_current_floor ())
187
            if (should_stop_at_current_floor ())
188
            {
188
            {
189
#ifndef QUIET
189
#ifndef QUIET
190
                printf ("stop at floor %d -- while going down\n", (int)(current_floor+0.5));
190
                printf ("stop at floor %d -- while going down\n", (int)(current_floor+0.5));
191
#endif
191
#endif
192
                stop_at_floors[(int)(current_floor+0.5)] = false;
192
                stop_at_floors.at((int)(current_floor+0.5)) = false;
193
                have_user_enter_buttons ();
193
                have_user_enter_buttons ();
194
            }
194
            }
195
 
195
 
196
            /* Decide to sit idle if we have no more floors to stop at */
196
            /* Decide to sit idle if we have no more floors to stop at */
197
            if (!has_floors_to_stop_at ())
197
            if (!has_floors_to_stop_at ())
Line 277... Line 277...
277
bool Elevator::has_floors_to_stop_at ()
277
bool Elevator::has_floors_to_stop_at ()
278
{
278
{
279
    int i;
279
    int i;
280
 
280
 
281
    for (i=0; i<num_floors; i++)
281
    for (i=0; i<num_floors; i++)
282
        if (stop_at_floors[i])
282
        if (stop_at_floors.at(i))
283
            return true;
283
            return true;
284
 
284
 
285
    return false;
285
    return false;
286
}
286
}
287
 
287
 
288
bool Elevator::should_stop_at_current_floor ()
288
bool Elevator::should_stop_at_current_floor ()
289
{
289
{
290
    int i;
290
    int i;
291
 
291
 
292
    for (i=0; i<num_floors; i++)
292
    for (i=0; i<num_floors; i++)
293
        if (near_floor (i) && stop_at_floors[i] == true)
293
        if (near_floor (i) && stop_at_floors.at(i) == true)
294
            return true;
294
            return true;
295
 
295
 
296
    return false;
296
    return false;
297
}
297
}
298
 
298
 
299
bool Elevator::button_is_pushed (int floor)
299
bool Elevator::button_is_pushed (int floor)
300
{
300
{
301
    assert (floor < num_floors);
301
    assert (floor < num_floors);
302
    assert (floor >= 0);
302
    assert (floor >= 0);
303
 
303
 
304
    return stop_at_floors[floor];
304
    return stop_at_floors.at(floor);
305
}
305
}
306
 
306
 
307
float Elevator::get_current_floor ()
307
float Elevator::get_current_floor ()
308
{
308
{
309
    return current_floor;
309
    return current_floor;