forked from finos/SymphonyMediaBridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
51 lines (46 loc) · 1.22 KB
/
utils.h
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
#pragma once
#include "transport/dtls/SrtpClient.h"
#include "transport/ice/IceSession.h"
namespace api
{
namespace utils
{
const char* toString(ice::IceSession::State state);
ice::IceSession::State stringToIceState(const std::string& state);
const char* toString(transport::SrtpClient::State state);
transport::SrtpClient::State stringToDtlsState(const std::string& state);
const char* toString(srtp::Profile profile);
srtp::Profile stringToSrtpProfile(const std::string& profile);
template <typename T>
struct EnumRef
{
const char* name;
T value;
};
// make sure dictionary contains default / null value at position 0
template <typename T, size_t N>
T fromString(const std::string& name, const EnumRef<T> (&dictionary)[N])
{
for (size_t i = 0; i < N; ++i)
{
if (name == dictionary[i].name)
{
return dictionary[i].value;
}
}
return dictionary[0].value;
}
template <typename T, size_t N>
const char* toString(T enumValue, const EnumRef<T> (&dictionary)[N])
{
for (size_t i = 0; i < N; ++i)
{
if (enumValue == dictionary[i].value)
{
return dictionary[i].name;
}
}
return dictionary[0].name;
}
} // namespace utils
} // namespace api