| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#pragma once |
| 22 |
|
| 23 |
#include <map> |
| 24 |
#include <string> |
| 25 |
|
| 26 |
#include "DataModel/Accessory.h" |
| 27 |
#include "DataModel/LockableItem.h" |
| 28 |
#include "DataModel/ObjectIdentifier.h" |
| 29 |
#include "DataModel/Serializable.h" |
| 30 |
#include "DataTypes.h" |
| 31 |
#include "Logger/Logger.h" |
| 32 |
|
| 33 |
class Manager; |
| 34 |
|
| 35 |
namespace DataModel |
| 36 |
{ |
| 37 |
class Relation : protected Serializable, public LockableItem |
| 38 |
{ |
| 39 |
public: |
| 40 |
enum RelationType : unsigned char |
| 41 |
{ |
| 42 |
RelationTypeCalculate = 0, |
| 43 |
RelationTypeLocoSlave = (ObjectTypeLoco << 3), |
| 44 |
RelationTypeTrackSignal = (ObjectTypeTrack << 3), |
| 45 |
RelationTypeTrackFeedback = (ObjectTypeTrack << 3) + 1, |
| 46 |
RelationTypeFeedbackAtSet = (ObjectTypeFeedback << 3), |
| 47 |
RelationTypeFeedbackAtUnset = (ObjectTypeFeedback << 3) + 1, |
| 48 |
RelationTypeRouteAtLock = (ObjectTypeRoute << 3), |
| 49 |
RelationTypeRouteAtUnlock = (ObjectTypeRoute << 3) + 1, |
| 50 |
RelationTypeClusterTrack = (ObjectTypeCluster << 3), |
| 51 |
RelationTypeMultipleUnitLoco = (ObjectTypeMultipleUnit << 3), |
| 52 |
}; |
| 53 |
|
| 54 |
typedef unsigned short Data; |
| 55 |
static const Data DefaultData = 0; |
| 56 |
|
| 57 |
inline Relation(Manager* manager, |
| 58 |
const ObjectIdentifier& object1, |
| 59 |
const ObjectIdentifier& object2, |
| 60 |
const RelationType type, |
| 61 |
const Priority priority = 0, |
| 62 |
const Data data = 0) |
| 63 |
: manager(manager), |
| 64 |
object1(object1), |
| 65 |
object2(object2), |
| 66 |
type(type), |
| 67 |
priority(priority), |
| 68 |
data(data) |
| 69 |
{ |
| 70 |
} |
| 71 |
|
| 72 |
inline Relation(Manager* manager, |
| 73 |
const std::string& serialized) |
| 74 |
: manager(manager), |
| 75 |
data(0) |
| 76 |
{ |
| 77 |
Deserialize(serialized); |
| 78 |
} |
| 79 |
|
| 80 |
virtual ~Relation() |
| 81 |
{ |
| 82 |
} |
| 83 |
|
| 84 |
virtual std::string Serialize() const override; |
| •85 |
virtual void Deserialize(const std::string& serialized) override; |
| 86 |
|
| 87 |
inline ObjectID ObjectID1() const |
| 88 |
{ |
| 89 |
return object1.GetObjectID(); |
| 90 |
} |
| 91 |
|
| 92 |
inline void ObjectID1(ObjectID objectID1) |
| 93 |
{ |
| 94 |
object1.SetObjectID(objectID1); |
| 95 |
} |
| 96 |
|
| 97 |
inline ObjectType ObjectType2() const |
| 98 |
{ |
| 99 |
return object2.GetObjectType(); |
| 100 |
} |
| 101 |
|
| 102 |
inline ObjectID ObjectID2() const |
| 103 |
{ |
| 104 |
return object2.GetObjectID(); |
| 105 |
} |
| 106 |
|
| 107 |
inline ObjectIdentifier ObjectIdentifier2() const |
| 108 |
{ |
| 109 |
return object2; |
| 110 |
} |
| 111 |
|
| •112 |
Object* GetObject2(); |
| 113 |
|
| 114 |
inline RelationType GetType() const |
| 115 |
{ |
| 116 |
return type; |
| 117 |
} |
| 118 |
|
| 119 |
inline Priority GetPriority() const |
| 120 |
{ |
| 121 |
return priority; |
| 122 |
} |
| 123 |
|
| 124 |
inline Data GetData() const |
| 125 |
{ |
| 126 |
return data; |
| 127 |
} |
| 128 |
|
| 129 |
inline bool CompareObject2(const ObjectIdentifier& identifier) const |
| 130 |
{ |
| 131 |
return object2 == identifier; |
| 132 |
} |
| 133 |
|
| 134 |
bool Reserve(Logger::Logger* logger, const ObjectIdentifier& locoBaseIdentifier) override; |
| 135 |
bool Lock(Logger::Logger* logger, const ObjectIdentifier& locoBaseIdentifier) override; |
| 136 |
bool Release(Logger::Logger* logger, const ObjectIdentifier& locoBaseIdentifier) override; |
| 137 |
bool Execute(Logger::Logger* logger, const ObjectIdentifier& locoBaseIdentifier, const Delay delay); |
| 138 |
|
| 139 |
private: |
| 140 |
inline ObjectType ObjectType1() const |
| 141 |
{ |
| 142 |
return object1.GetObjectType(); |
| 143 |
} |
| 144 |
|
| 145 |
Manager* manager; |
| 146 |
ObjectIdentifier object1; |
| 147 |
ObjectIdentifier object2; |
| 148 |
RelationType type; |
| 149 |
Priority priority; |
| 150 |
Data data; |
| 151 |
}; |
| 152 |
} |
| 153 |
|