better fields access

This commit is contained in:
2025-02-15 12:39:53 +01:00
parent 0b28bde25b
commit e39f8de898
6 changed files with 55 additions and 20 deletions

View File

@@ -13,15 +13,17 @@ using PacketMessage = Message<option::MsgIdType<std::uint8_t>, // add id() opera
option::Handler<PacketHandler> // add dispatch() operation
>;
#define DeclarePacket(packetName) \
class packetName##Packet : public sp::MessageBase<sp::PacketMessage, sp::option::StaticNumIdImpl<packetName>, \
sp::option::DispatchImpl<packetName##Packet>, sp::option::FieldsImpl<packetName##Fields>> { \
public: \
packetName##Packet() {} \
template <typename... Args> \
packetName##Packet(Args... args) { \
Construct(args...); \
} \
#define PacketConstructor(packetName) \
packetName##Packet() {} \
template <typename... Args> \
packetName##Packet(Args... args) { \
Construct(args...); \
}
#define DeclarePacket(packetName) \
class packetName##Packet : public sp::MessageBase<sp::PacketMessage, sp::option::StaticNumIdImpl<packetName>, \
sp::option::DispatchImpl<packetName##Packet>, sp::option::FieldsImpl<packetName##Fields>>
} // namespace sp

View File

@@ -40,6 +40,11 @@ class BitField {
return std::get<FIndex>(this->GetFields()).GetValue();
}
template <std::size_t FIndex>
const auto& GetField() const {
return std::get<FIndex>(this->GetFields()).GetValue();
}
private:
template <int IOffset, typename... T, std::enable_if_t<IOffset >= sizeof...(T), bool> = true>
void Apply(const std::tuple<T...>& args) {}

View File

@@ -114,6 +114,11 @@ class MessageImplFieldsBase : public TBase {
return std::get<FIndex>(GetFields()).GetValue();
}
template <std::size_t FIndex>
const auto& GetField() const {
return std::get<FIndex>(GetFields()).GetValue();
}
private:
AllFields m_Fields;
};