-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathParameterProvider.hpp
More file actions
72 lines (53 loc) · 1.78 KB
/
ParameterProvider.hpp
File metadata and controls
72 lines (53 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// SPDX-FileCopyrightText: 2024 Vector Informatik GmbH
//
// SPDX-License-Identifier: MIT
#pragma once
#include <string>
#include "silkit/capi/Parameters.h"
namespace SilKit {
DETAIL_SILKIT_DETAIL_VN_NAMESPACE_BEGIN
namespace Impl {
class ParameterProvider
{
public:
inline ParameterProvider();
inline ~ParameterProvider() = default;
inline auto GetParameter(SilKit_Participant* participant, Parameter parameter) -> std::string;
};
} // namespace Impl
DETAIL_SILKIT_DETAIL_VN_NAMESPACE_CLOSE
} // namespace SilKit
// ================================================================================
// Inline Implementations
// ================================================================================
#include "silkit/detail/impl/ThrowOnError.hpp"
namespace SilKit {
DETAIL_SILKIT_DETAIL_VN_NAMESPACE_BEGIN
namespace Impl {
ParameterProvider::ParameterProvider()
{
}
auto ParameterProvider::GetParameter(SilKit_Participant* participant, Parameter parameter) -> std::string
{
std::vector<char> buffer;
size_t size = 0;
SilKit_Parameter cParameter = static_cast<SilKit_Parameter>(parameter);
// Query the size by passing nullptr for the outParameterValue
{
const auto returnCode = SilKit_Participant_GetParameter(nullptr, &size, cParameter, participant);
ThrowOnError(returnCode);
}
// Loop as the size might changed intermediately
while (size > buffer.size())
{
buffer.resize(size);
const auto returnCode = SilKit_Participant_GetParameter(buffer.data(), &size, cParameter, participant);
ThrowOnError(returnCode);
}
// Value-initialized to nul
buffer.resize(size + 1);
return std::string{buffer.data()};
}
} // namespace Impl
DETAIL_SILKIT_DETAIL_VN_NAMESPACE_CLOSE
} // namespace SilKit