• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

traintastic / traintastic / 24288605255

11 Apr 2026 06:17PM UTC coverage: 25.599% (-2.4%) from 27.99%
24288605255

push

github

web-flow
Merge pull request #222 from traintastic/cbus

Added CBUS/VLCB hardware support

169 of 3369 new or added lines in 99 files covered. (5.02%)

5 existing lines in 4 files now uncovered.

8300 of 32423 relevant lines covered (25.6%)

178.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/server/src/hardware/input/inputlocation.hpp
1
/**
2
 * This file is part of Traintastic,
3
 * see <https://github.com/traintastic/traintastic>.
4
 *
5
 * Copyright (C) 2026 Reinder Feenstra
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 */
21

22
#ifndef TRAINTASTIC_SERVER_HARDWARE_INPUT_INPUTLOCATION_HPP
23
#define TRAINTASTIC_SERVER_HARDWARE_INPUT_INPUTLOCATION_HPP
24

25
#include <variant>
26
#include <cstdint>
27
#include <traintastic/enum/inputchannel.hpp>
28
#include "../../utils/unreachable.hpp"
29

30
struct InputAddress
31
{
32
  uint32_t address;
33
};
34

35
struct InputNodeAddress
36
{
37
  uint32_t node;
38
  uint32_t address;
39
};
40

41
using InputLocation = std::variant<InputAddress, InputNodeAddress>;
42

NEW
43
constexpr bool hasAddressLocation(InputChannel channel) noexcept
×
44
{
NEW
45
  switch(channel)
×
46
  {
47
    using enum InputChannel;
48

NEW
49
    case Input:
×
50
    case LocoNet:
51
    case RBus:
52
    case S88:
53
    case S88_Left:
54
    case S88_Middle:
55
    case S88_Right:
56
    case ECoSDetector:
57
    case ShortEvent:
NEW
58
      return true;
×
59

NEW
60
    case LongEvent:
×
NEW
61
      return false;
×
62
  }
NEW
63
  return false; // this should never happen
×
64
}
65

NEW
66
constexpr bool hasNodeAddressLocation(InputChannel channel) noexcept
×
67
{
NEW
68
  switch(channel)
×
69
  {
70
    using enum InputChannel;
71

NEW
72
    case LongEvent:
×
NEW
73
      return true;
×
74

NEW
75
    case Input:
×
76
    case LocoNet:
77
    case RBus:
78
    case S88:
79
    case S88_Left:
80
    case S88_Middle:
81
    case S88_Right:
82
    case ECoSDetector:
83
    case ShortEvent:
NEW
84
      return false;
×
85
  }
NEW
86
  return false; // this should never happen
×
87
}
88

NEW
89
constexpr InputLocation inputLocation(InputChannel channel, uint32_t node, uint32_t address) noexcept
×
90
{
NEW
91
  if(hasAddressLocation(channel))
×
92
  {
NEW
93
    return InputAddress(address);
×
94
  }
NEW
95
  if(hasNodeAddressLocation(channel))
×
96
  {
NEW
97
    return InputNodeAddress(node, address);
×
98
  }
NEW
99
  unreachable();
×
100
}
101

102
template<>
103
struct std::hash<InputAddress>
104
{
NEW
105
  size_t operator()(InputAddress const& value) const noexcept
×
106
  {
NEW
107
    return std::hash<decltype(value.address)>{}(value.address);
×
108
  }
109
};
110

111
template<>
112
struct std::hash<InputNodeAddress>
113
{
NEW
114
  size_t operator()(InputNodeAddress const& value) const noexcept
×
115
  {
NEW
116
    return std::hash<decltype(value.node)>{}(value.node) ^ std::hash<decltype(value.address)>{}(value.address);
×
117
  }
118
};
119

NEW
120
constexpr bool operator ==(const InputAddress& lhs, const InputAddress& rhs) noexcept
×
121
{
NEW
122
  return lhs.address == rhs.address;
×
123
}
124

NEW
125
constexpr bool operator ==(const InputNodeAddress lhs, const InputNodeAddress& rhs) noexcept
×
126
{
NEW
127
  return lhs.node == rhs.node && lhs.address == rhs.address;
×
128
}
129

NEW
130
constexpr bool operator ==(const InputLocation& lhs, const InputLocation& rhs) noexcept
×
131
{
NEW
132
  if(lhs.index() == rhs.index())
×
133
  {
NEW
134
    return std::visit(
×
NEW
135
      [](auto const& l, auto const& r) noexcept -> bool
×
136
      {
NEW
137
        return l == r;
×
138
      },
NEW
139
      lhs, rhs);
×
140
  }
NEW
141
  return false;
×
142
}
143

144
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc