| 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 |
#pragma once |
| 22 |
|
| 23 |
#include <string> |
| 24 |
|
| 25 |
#include "DataTypes.h" |
| 26 |
#include "DataModel/AccessoryBase.h" |
| 27 |
#include "DataModel/HardwareHandle.h" |
| 28 |
#include "DataModel/LayoutItem.h" |
| 29 |
#include "DataModel/LockableItem.h" |
| 30 |
#include "Languages.h" |
| 31 |
|
| 32 |
class Manager; |
| 33 |
|
| 34 |
namespace DataModel |
| 35 |
{ |
| 36 |
class Accessory : public AccessoryBase, public LayoutItem, public LockableItem |
| 37 |
{ |
| 38 |
Accessory() = delete; |
| 39 |
Accessory(const Accessory&) = delete; |
| 40 |
Accessory& operator=(const Accessory&) = delete; |
| 41 |
|
| 42 |
public: |
| 43 |
inline Accessory(const AccessoryID accessoryID) |
| 44 |
: AccessoryBase(), |
| 45 |
LayoutItem(accessoryID), |
| 46 |
LockableItem(), |
| 47 |
port(AddressPortRed) |
| 48 |
{ |
| 49 |
} |
| 50 |
|
| 51 |
inline Accessory(__attribute__((unused)) Manager* manager, const AccessoryID accessoryID) |
| 52 |
: Accessory(accessoryID) |
| 53 |
{ |
| 54 |
} |
| 55 |
|
| 56 |
inline Accessory(const std::string& serialized) |
| 57 |
: Accessory(AccessoryNone) |
| 58 |
{ |
| 59 |
Deserialize(serialized); |
| 60 |
} |
| 61 |
|
| 62 |
virtual ~Accessory() |
| 63 |
{ |
| 64 |
} |
| 65 |
|
| 66 |
virtual ObjectType GetObjectType() const override |
| 67 |
{ |
| 68 |
return ObjectTypeAccessory; |
| 69 |
} |
| 70 |
|
| 71 |
virtual std::string GetLayoutType() const override |
| 72 |
{ |
| 73 |
return Languages::GetText(Languages::TextAccessory); |
| 74 |
} |
| 75 |
|
| 76 |
virtual std::string Serialize() const override; |
| 77 |
|
| 78 |
using HardwareHandle::Deserialize; |
| 79 |
virtual bool Deserialize(const std::string& serialized) override; |
| 80 |
|
| 81 |
Accessory& operator=(const Hardware::AccessoryCacheEntry& accessory); |
| 82 |
|
| 83 |
inline void SetPort(AddressPort port) |
| 84 |
{ |
| 85 |
this->port = port; |
| 86 |
} |
| 87 |
|
| 88 |
inline AddressPort GetPort() const |
| 89 |
{ |
| 90 |
return port; |
| 91 |
} |
| 92 |
|
| 93 |
private: |
| 94 |
AddressPort port; |
| 95 |
}; |
| 96 |
} // namespace DataModel |
| 97 |
|