]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/dummy.cpp
Fix a segfault in removing vehicles when creating a new train
[r2c2.git] / source / libmarklin / dummy.cpp
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include "dummy.h"
9
10 using namespace std;
11
12 namespace Marklin {
13
14 Dummy::Dummy():
15         power(true)
16 { }
17
18 void Dummy::set_power(bool p)
19 {
20         power = p;
21         signal_power.emit(power);
22 }
23
24 const char *Dummy::enumerate_protocols(unsigned i) const
25 {
26         if(i==0)
27                 return "dummy";
28         return 0;
29 }
30
31 unsigned Dummy::get_protocol_speed_steps(const string &) const
32 {
33         return 0;
34 }
35
36 void Dummy::add_turnout(unsigned addr)
37 {
38         turnouts[addr];
39 }
40
41 void Dummy::set_turnout(unsigned addr, bool state)
42 {
43         if(turnouts[addr]!=state)
44         {
45                 turnouts[addr] = state;
46                 signal_turnout.emit(addr, state);
47         }
48 }
49
50 bool Dummy::get_turnout(unsigned addr) const
51 {
52         map<unsigned, bool>::const_iterator i = turnouts.find(addr);
53         if(i!=turnouts.end())
54                 return i->second;
55         return false;
56 }
57
58 void Dummy::set_loco_speed(unsigned addr, unsigned speed)
59 {
60         LocoState &loco = locos[addr];
61         loco.speed = speed;
62         signal_loco_speed.emit(addr, speed, loco.reverse);
63 }
64
65 void Dummy::set_loco_reverse(unsigned addr, bool rev)
66 {
67         LocoState &loco = locos[addr];
68         loco.reverse = rev;
69         signal_loco_speed.emit(addr, loco.speed, rev);
70 }
71
72 void Dummy::set_loco_function(unsigned addr, unsigned func, bool state)
73 {
74         signal_loco_function.emit(addr, func, state);
75 }
76
77 void Dummy::set_sensor(unsigned addr, bool state)
78 {
79         if(sensors[addr]!=state)
80         {
81                 sensors[addr] = state;
82                 signal_sensor.emit(addr, state);
83         }
84 }
85
86 bool Dummy::get_sensor(unsigned addr) const
87 {
88         map<unsigned, bool>::const_iterator i = sensors.find(addr);
89         if(i!=sensors.end())
90                 return i->second;
91         return false;
92 }
93
94 } // namespace Marklin