This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
bundle_impl.h
57 lines (42 loc) · 1.44 KB
/
bundle_impl.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
52
53
54
55
56
57
/*!
* janus-client SDK
*
* bundle_impl.h
* The argument bundle implementation
* This module defines a bundle object you can use to pass arguments to janus commands
*
* Copyright 2019 Pasquale Boemio <[email protected]>
*/
#pragma once
#include "janus/bundle.hpp"
#include <unordered_map>
#include "janus/constraints.hpp"
#define CONSTRAINTS_KEY "SPiUkrMsbd"
namespace Janus {
class BundleImpl : public Bundle {
public:
void setString(const std::string& key, const std::string& value);
std::string getString(const std::string& key, const std::string& fallback);
void setInt(const std::string& key, int64_t value);
int64_t getInt(const std::string& key, int64_t fallback);
void setBool(const std::string& key, bool value);
bool getBool(const std::string& key, bool fallback);
void setConstraints(const Constraints& constraints);
Constraints getConstraints();
private:
template <typename T>
void _set(const std::string& key, T value) {
std::shared_ptr<void> converted = std::make_shared<T>(value);
this->_values[key] = converted;
}
template <typename T>
T _get(const std::string& key, T fallback) {
auto value = this->_values[key];
if(value == nullptr) {
return fallback;
}
return *std::static_pointer_cast<T>(value);
}
std::unordered_map<std::string, std::shared_ptr<void>> _values;
};
}