PacketFactory
PacketFactory
#include <icy/packetfactory.h>Priority-ordered factory that creates typed packets from raw buffers using registered strategies.
Public Methods
| Return | Name | Description |
|---|---|---|
PacketFactory | Defaulted constructor. | |
PacketFactory | Deleted constructor. | |
PacketFactory | Defaulted constructor. | |
void | registerPacketType inline | Registers a [PacketCreationStrategy](icy-PacketCreationStrategy.html#packetcreationstrategy)<PacketT> at the given priority. Any previously registered strategy for PacketT is replaced. |
void | unregisterPacketType inline | Removes the [PacketCreationStrategy](icy-PacketCreationStrategy.html#packetcreationstrategy)<PacketT> from the factory, if present. |
void | registerStrategy inline | Registers an arbitrary [IPacketCreationStrategy](icy-IPacketCreationStrategy.html#ipacketcreationstrategy) subclass at the given priority. Any previously registered instance of the same type is replaced. |
void | unregisterStrategy inline | Removes the StrategyT instance from the factory, if present. |
PacketCreationStrategyList & | types inline | #### Returns |
const PacketCreationStrategyList & | types const inline | #### Returns |
bool | onPacketCreated virtual inline | Called after a packet is successfully created by a strategy. Override to apply filtering; return false to reject the packet (it will be deleted). |
IPacket * | createPacket virtual inline | Iterates registered strategies in priority order and returns the first successfully created packet. |
PacketFactory
PacketFactory() = defaultDefaulted constructor.
PacketFactory
PacketFactory(const PacketFactory &) = deleteDeleted constructor.
PacketFactory
PacketFactory(PacketFactory &&) = defaultDefaulted constructor.
registerPacketType
inline
template<class PacketT> inline void registerPacketType(int priority)Registers a [PacketCreationStrategy](icy-PacketCreationStrategy.html#packetcreationstrategy)<PacketT> at the given priority. Any previously registered strategy for PacketT is replaced.
Parameters
PacketTPacket type to register; must default-constructible with aread()method.
Parameters
priorityDispatch priority (0–100; higher runs first).
unregisterPacketType
inline
template<class PacketT> inline void unregisterPacketType()Removes the [PacketCreationStrategy](icy-PacketCreationStrategy.html#packetcreationstrategy)<PacketT> from the factory, if present.
Parameters
PacketTPacket type whose strategy should be removed.
registerStrategy
inline
template<class StrategyT> inline void registerStrategy(int priority)Registers an arbitrary [IPacketCreationStrategy](icy-IPacketCreationStrategy.html#ipacketcreationstrategy) subclass at the given priority. Any previously registered instance of the same type is replaced.
Parameters
StrategyTStrategy type to instantiate; must accept a priority int in its constructor.
Parameters
priorityDispatch priority (0–100; higher runs first).
unregisterStrategy
inline
template<class StrategyT> inline void unregisterStrategy()Removes the StrategyT instance from the factory, if present.
Parameters
StrategyTStrategy type to remove.
types
inline
inline PacketCreationStrategyList & types()Returns
Mutable reference to the ordered list of registered strategies.
types
const inline
inline const PacketCreationStrategyList & types() constReturns
Const reference to the ordered list of registered strategies.
onPacketCreated
virtual inline
virtual inline bool onPacketCreated(IPacket * packet)Called after a packet is successfully created by a strategy. Override to apply filtering; return false to reject the packet (it will be deleted).
Parameters
packetNewly created packet.
Returns
True to accept the packet, false to discard it and try the next strategy.
createPacket
virtual inline
virtual inline IPacket * createPacket(const ConstBuffer & buffer, size_t & nread)Iterates registered strategies in priority order and returns the first successfully created packet.
Parameters
bufferRaw input data.nreadSet to the number of bytes consumed on success.
Returns
Newly allocated packet, or nullptr if no strategy matched.
Exceptions
std::logic_errorif no packet types have been registered.
Protected Attributes
| Return | Name | Description |
|---|---|---|
PacketCreationStrategyList | _types |
_types
PacketCreationStrategyList _typesPrivate Methods
| Return | Name | Description |
|---|---|---|
void | sortTypes inline |
sortTypes
inline
inline void sortTypes()