CCSDSPack
C++ Library for CCSDS Space Packet manipulation. i.e. generation, extraction, analisys and more
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | List of all members
CCSDS::SecondaryHeaderFactory Class Reference

A singleton factory class responsible for registering and creating instances of SecondaryHeaderAbstract objects. More...

#include <CCSDSSecondaryHeaderFactory.h>

Public Types

using CreatorFunc = std::function< std::shared_ptr< SecondaryHeaderAbstract >()>
 Type alias for a function that creates an instance of SecondaryHeaderAbstract.
 

Public Member Functions

 SecondaryHeaderFactory ()=default
 Default constructor for the factory.
 
void registerType (std::shared_ptr< SecondaryHeaderAbstract > header)
 Registers a new header type with its creation function.
 
std::shared_ptr< SecondaryHeaderAbstractcreate (const std::string &type)
 Creates an instance of a registered header type.
 
bool typeIsRegistered (const std::string &type)
 Checks if a header type is registered.
 

Private Attributes

std::unordered_map< std::string, std::shared_ptr< SecondaryHeaderAbstract > > m_creators
 A map of header types to their corresponding SecondaryHeaderAbstract objects.
 

Detailed Description

A singleton factory class responsible for registering and creating instances of SecondaryHeaderAbstract objects.

This factory allows clients to register new types of headers, check if a header type is registered, and create instances of registered header types.

Definition at line 18 of file CCSDSSecondaryHeaderFactory.h.

Member Typedef Documentation

◆ CreatorFunc

Type alias for a function that creates an instance of SecondaryHeaderAbstract.

Definition at line 29 of file CCSDSSecondaryHeaderFactory.h.

Constructor & Destructor Documentation

◆ SecondaryHeaderFactory()

CCSDS::SecondaryHeaderFactory::SecondaryHeaderFactory ( )
default

Default constructor for the factory.

Member Function Documentation

◆ create()

std::shared_ptr< SecondaryHeaderAbstract > CCSDS::SecondaryHeaderFactory::create ( const std::string &  type)
inline

Creates an instance of a registered header type.

This function searches for the header type by its string identifier and returns a new instance of the registered header.

Parameters
typeA string representing the header type to create.
Returns
A shared pointer to a SecondaryHeaderAbstract object, or nullptr if the type is not registered.

Definition at line 50 of file CCSDSSecondaryHeaderFactory.h.

50 {
51 if (const auto it = m_creators.find(type); it != m_creators.end()) {
52 return it->second; // Call the stored creation function
53 }
54 return nullptr; // Return nullptr if type not found
55 }
std::unordered_map< std::string, std::shared_ptr< SecondaryHeaderAbstract > > m_creators
A map of header types to their corresponding SecondaryHeaderAbstract objects.

◆ registerType()

void CCSDS::SecondaryHeaderFactory::registerType ( std::shared_ptr< SecondaryHeaderAbstract header)
inline

Registers a new header type with its creation function.

This function adds a new header type to the factory by associating the header's type string with a shared pointer to the header.

Parameters
headerA shared pointer to a SecondaryHeaderAbstract object to register.

Definition at line 38 of file CCSDSSecondaryHeaderFactory.h.

38 {
39 m_creators[header->getType()] = std::move(header);
40 }
Here is the caller graph for this function:

◆ typeIsRegistered()

bool CCSDS::SecondaryHeaderFactory::typeIsRegistered ( const std::string &  type)
inline

Checks if a header type is registered.

This function checks if a given header type is already registered with the factory.

Parameters
typeA string representing the header type to check.
Returns
true if the type is registered, false otherwise.

Definition at line 65 of file CCSDSSecondaryHeaderFactory.h.

65 {
66 if (const auto it = m_creators.find(type); it != m_creators.end()) {
67 return true; // return true if found
68 }
69 return false; // Return false if type not found
70 }

Member Data Documentation

◆ m_creators

std::unordered_map<std::string, std::shared_ptr<SecondaryHeaderAbstract> > CCSDS::SecondaryHeaderFactory::m_creators
private

A map of header types to their corresponding SecondaryHeaderAbstract objects.

This private member stores the registered header types along with their corresponding shared pointers.

Definition at line 78 of file CCSDSSecondaryHeaderFactory.h.


The documentation for this class was generated from the following file: