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
// Copyright 2025-2026 ExoSpaceLabs
2
// SPDX-License-Identifier: Apache-2.0
3
4
#ifndef CCSDS_SECONDARY_HEADER_FACTORY_H
5
#define CCSDS_SECONDARY_HEADER_FACTORY_H
6
7
#include <memory>
8
#include <unordered_map>
9
#include <functional>
10
#include <string>
11
#include "
CCSDSSecondaryHeaderAbstract.h
"
// Base class header
12
13
namespace
CCSDS
{
14
21
class
SecondaryHeaderFactory
{
22
public
:
26
SecondaryHeaderFactory
() =
default
;
27
32
using
CreatorFunc
= std::function<std::shared_ptr<SecondaryHeaderAbstract>()>;
33
42
ResultBool
registerType
(std::shared_ptr<SecondaryHeaderAbstract> header) {
43
RET_IF_ERR_MSG
(!header,
INVALID_HEADER_DATA
,
"Cannot register, invalid Header provided."
);
44
m_creators
[header->getType()] = std::move(header);
45
return
true
;
46
}
47
56
std::shared_ptr<SecondaryHeaderAbstract>
create
(
const
std::string& type) {
57
if
(
const
auto
it =
m_creators
.find(type); it !=
m_creators
.end()) {
58
return
it->second;
// Call the stored creation function
59
}
60
return
nullptr
;
// Return nullptr if type not found
61
}
62
71
bool
typeIsRegistered
(
const
std::string& type) {
72
if
(
const
auto
it =
m_creators
.find(type); it !=
m_creators
.end()) {
73
return
true
;
// return true if found
74
}
75
return
false
;
// Return false if type not found
76
}
77
78
private
:
84
std::unordered_map<std::string, std::shared_ptr<SecondaryHeaderAbstract> >
m_creators
;
85
};
86
87
}
// namespace CCSDS
88
89
#endif
// CCSDS_SECONDARY_HEADER_FACTORY_H
RET_IF_ERR_MSG
#define RET_IF_ERR_MSG(condition, errorCode, message)
Macro to return an error with an error message if a condition is met.
Definition
CCSDSResult.h:152
CCSDSSecondaryHeaderAbstract.h
CCSDS::Result
Encapsulates a result that can hold either a value or an Error.
Definition
CCSDSResult.h:85
CCSDS::SecondaryHeaderFactory
A singleton factory class responsible for registering and creating instances of SecondaryHeaderAbstra...
Definition
CCSDSSecondaryHeaderFactory.h:21
CCSDS::SecondaryHeaderFactory::CreatorFunc
std::function< std::shared_ptr< SecondaryHeaderAbstract >()> CreatorFunc
Type alias for a function that creates an instance of SecondaryHeaderAbstract.
Definition
CCSDSSecondaryHeaderFactory.h:32
CCSDS::SecondaryHeaderFactory::registerType
ResultBool registerType(std::shared_ptr< SecondaryHeaderAbstract > header)
Registers a new header type with its creation function.
Definition
CCSDSSecondaryHeaderFactory.h:42
CCSDS::SecondaryHeaderFactory::create
std::shared_ptr< SecondaryHeaderAbstract > create(const std::string &type)
Creates an instance of a registered header type.
Definition
CCSDSSecondaryHeaderFactory.h:56
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:84
CCSDS::SecondaryHeaderFactory::typeIsRegistered
bool typeIsRegistered(const std::string &type)
Checks if a header type is registered.
Definition
CCSDSSecondaryHeaderFactory.h:71
CCSDS::SecondaryHeaderFactory::SecondaryHeaderFactory
SecondaryHeaderFactory()=default
Default constructor for the factory.
CCSDS
Contains definitions and classes for handling CCSDS headers.
Definition
CCSDSDataField.h:14
CCSDS::INVALID_HEADER_DATA
@ INVALID_HEADER_DATA
Header data is invalid.
Definition
CCSDSResult.h:28
Generated by
1.9.8