CCSDSPack
C++ Library for CCSDS Space Packet manipulation. i.e. generation, extraction, analisys and more
Loading...
Searching...
No Matches
inc
CCSDSSecondaryHeaderFactory.h
Go to the documentation of this file.
1
#ifndef CCSDS_SECONDARY_HEADER_FACTORY_H
2
#define CCSDS_SECONDARY_HEADER_FACTORY_H
3
4
#include <memory>
5
#include <unordered_map>
6
#include <functional>
7
#include <string>
8
#include "
CCSDSSecondaryHeaderAbstract.h
"
// Base class header
9
10
namespace
CCSDS
{
11
18
class
SecondaryHeaderFactory
{
19
public
:
23
SecondaryHeaderFactory
() =
default
;
24
29
using
CreatorFunc
= std::function<std::shared_ptr<SecondaryHeaderAbstract>()>;
30
38
void
registerType
(std::shared_ptr<SecondaryHeaderAbstract> header) {
39
m_creators
[header->getType()] = std::move(header);
40
}
41
50
std::shared_ptr<SecondaryHeaderAbstract>
create
(
const
std::string& type) {
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
}
56
65
bool
typeIsRegistered
(
const
std::string& type) {
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
}
71
72
private
:
78
std::unordered_map<std::string, std::shared_ptr<SecondaryHeaderAbstract> >
m_creators
;
79
};
80
81
}
// namespace CCSDS
82
83
#endif
// CCSDS_SECONDARY_HEADER_FACTORY_H
CCSDSSecondaryHeaderAbstract.h
CCSDS::SecondaryHeaderFactory
A singleton factory class responsible for registering and creating instances of SecondaryHeaderAbstra...
Definition
CCSDSSecondaryHeaderFactory.h:18
CCSDS::SecondaryHeaderFactory::CreatorFunc
std::function< std::shared_ptr< SecondaryHeaderAbstract >()> CreatorFunc
Type alias for a function that creates an instance of SecondaryHeaderAbstract.
Definition
CCSDSSecondaryHeaderFactory.h:29
CCSDS::SecondaryHeaderFactory::create
std::shared_ptr< SecondaryHeaderAbstract > create(const std::string &type)
Creates an instance of a registered header type.
Definition
CCSDSSecondaryHeaderFactory.h:50
CCSDS::SecondaryHeaderFactory::m_creators
std::unordered_map< std::string, std::shared_ptr< SecondaryHeaderAbstract > > m_creators
A map of header types to their corresponding SecondaryHeaderAbstract objects.
Definition
CCSDSSecondaryHeaderFactory.h:78
CCSDS::SecondaryHeaderFactory::typeIsRegistered
bool typeIsRegistered(const std::string &type)
Checks if a header type is registered.
Definition
CCSDSSecondaryHeaderFactory.h:65
CCSDS::SecondaryHeaderFactory::registerType
void registerType(std::shared_ptr< SecondaryHeaderAbstract > header)
Registers a new header type with its creation function.
Definition
CCSDSSecondaryHeaderFactory.h:38
CCSDS::SecondaryHeaderFactory::SecondaryHeaderFactory
SecondaryHeaderFactory()=default
Default constructor for the factory.
CCSDS
Contains definitions and classes for handling CCSDS headers.
Definition
CCSDSDataField.h:12
Generated by
1.9.8