Skip to content

Commit 888f309

Browse files
Zainullin DamirZainullin Damir
authored andcommitted
OutputConfigurationParser - Introduce main Parser class
1 parent 53248cf commit 888f309

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @file
3+
* @brief Declaration of OutputFieldConfigurationParser.
4+
* @author Damir Zainullin <[email protected]>
5+
*
6+
* @copyright Copyright (c) 2025 CESNET, z.s.p.o.
7+
*/
8+
9+
#pragma once
10+
11+
#include "../processPlugin/fieldDescriptor.hpp"
12+
13+
#include <vector>
14+
15+
namespace ipxp {
16+
17+
class OutputFieldParser {
18+
public:
19+
static std::vector<const process::FieldDescriptor*> getOutputFields(
20+
const std::vector<process::FieldDescriptor>& availableFields,
21+
std::string_view configurationFilePath);
22+
};
23+
24+
}; // namespace ipxp
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @file
3+
* @brief Implementation of OutputFieldConfigurationParser.
4+
* @author Damir Zainullin <[email protected]>
5+
*
6+
* @copyright Copyright (c) 2025 CESNET, z.s.p.o.
7+
*/
8+
9+
#include "fieldMap.hpp"
10+
#include "outputAction.hpp"
11+
12+
#include <fstream>
13+
#include <regex>
14+
15+
#include <outputFieldConfigurationParser.hpp>
16+
17+
namespace ipxp {
18+
19+
std::vector<const process::FieldDescriptor*> OutputFieldParser::getOutputFields(
20+
const std::vector<process::FieldDescriptor>& availableFields,
21+
std::string_view configurationFilePath)
22+
{
23+
std::ifstream configurationFile(configurationFilePath.data());
24+
if (!configurationFile.is_open()) {
25+
throw std::invalid_argument(
26+
"Could not open configuration file: " + std::string(configurationFilePath));
27+
}
28+
29+
const std::string configurationContent(
30+
(std::istreambuf_iterator<char>(configurationFile)),
31+
std::istreambuf_iterator<char>());
32+
33+
return FieldMap(availableFields).applyActions(parseActions(configurationContent));
34+
}
35+
36+
} // namespace ipxp

0 commit comments

Comments
 (0)