src
util.h
Go to the documentation of this file.
1
/*
2
* Copyright 2021, Rein Appeldoorn
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*
16
*/
17
18
#pragma once
19
20
#include <map>
21
#include <sstream>
22
#include <string>
23
#include <vector>
24
25
namespace
picovoice_driver
26
{
27
template
<
typename
T>
28
std::string
toString
(
const
T& v)
29
{
30
std::stringstream ss;
31
ss << v;
32
return
ss.str();
33
}
34
35
template
<
typename
T>
36
std::string
toString
(
const
std::vector<T>& v)
37
{
38
std::stringstream ss;
39
ss <<
"{"
;
40
for
(
size_t
i = 0; i < v.size(); ++i)
41
{
42
if
(i != 0)
43
{
44
ss <<
", "
;
45
}
46
ss << v[i];
47
}
48
ss <<
"}"
;
49
return
ss.str();
50
}
51
52
template
<
typename
T1,
typename
T2>
53
std::string
toString
(
const
std::map<T1, T2>& v)
54
{
55
std::stringstream ss;
56
ss <<
"{"
;
57
bool
first =
true
;
58
for
(
const
auto
& kv : v)
59
{
60
if
(first)
61
{
62
first =
false
;
63
}
64
else
65
{
66
ss <<
", "
;
67
}
68
ss << kv.first <<
"="
<< kv.second;
69
}
70
ss <<
"}"
;
71
return
ss.str();
72
}
73
}
// namespace picovoice_driver
picovoice_driver
Definition:
porcupine_node.cpp:24
picovoice_driver::toString
std::string toString(const T &v)
Definition:
util.h:28
picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:55