Debian Codegraph @

DataModel/AccessoryBase.cpp

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 RailControl - Model Railway Control Software
3
4 Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org
5
6 RailControl is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 RailControl is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with RailControl; see the file LICENCE. If not see
18 <http://www.gnu.org/licenses/>.
19 */
20
21 #include <map>
22 #include <sstream>
23
24 #include "DataModel/AccessoryBase.h"
25 #include "Utils/Utils.h"
26
27 using std::map;
28 using std::string;
29
30 namespace DataModel
31 {
32 std::string AccessoryBase::Serialize() const
33 {
34 string str = HardwareHandle::Serialize();
35 str += ";type=" + std::to_string(accessoryType);
36 str += ";state=" + std::to_string(accessoryState);
37 str += ";duration=" + std::to_string(duration);
38 str += ";inverted=" + std::to_string(inverted);
39 str += ";lastused=" + std::to_string(lastUsed);
40 str += ";counter=" + std::to_string(counter);
41 str += ";matchkey=" + matchKey;
42 return str;
43 }
44
45 bool AccessoryBase::Deserialize(const map<string,string>& arguments)
46 {
47 HardwareHandle::Deserialize(arguments);
48 accessoryType = static_cast<AccessoryType>(Utils::Utils::GetIntegerMapEntry(arguments, "type"));
49 accessoryState = static_cast<AccessoryState>(Utils::Utils::GetIntegerMapEntry(arguments, "state", AccessoryStateOff));
50 duration = static_cast<AccessoryPulseDuration>(Utils::Utils::GetIntegerMapEntry(arguments, "duration", DefaultAccessoryPulseDuration));
51 inverted = Utils::Utils::GetBoolMapEntry(arguments, "inverted");
52 lastUsed = Utils::Utils::GetIntegerMapEntry(arguments, "lastused", 0);
53 counter = Utils::Utils::GetIntegerMapEntry(arguments, "counter", 0);
54 matchKey = Utils::Utils::GetStringMapEntry(arguments, "matchkey");
55 return true;
56 }
57
58 AccessoryState AccessoryBase::CalculateInvertedAccessoryState(const AccessoryState state) const
59 {
60 if (inverted == false)
61 {
62 return state;
63 }
64
65 switch(state)
66 {
67 case AccessoryStateOff:
68 return AccessoryStateOn;
69
70 case AccessoryStateOn:
71 return AccessoryStateOff;
72
73 default:
74 return state;
75 }
76 }
77 } // namespace DataModel