rmw
master
C API providing a middleware abstraction layer which is used to implement the rest of ROS.
include
rmw
impl
cpp
key_value.hpp
Go to the documentation of this file.
1
// Copyright 2017 Open Source Robotics Foundation, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef RMW__IMPL__CPP__KEY_VALUE_HPP_
16
#define RMW__IMPL__CPP__KEY_VALUE_HPP_
17
18
#include <map>
19
#include <string>
20
#include <vector>
21
22
namespace
rmw
23
{
24
namespace
impl
25
{
26
namespace
cpp
27
{
28
29
// TODO(karsten1987): Implement based on
30
// https://github.com/PrismTech/opensplice/blob/master/docs/pdf/OpenSplice_refman_CPP.pdf
31
static
std::map<std::string, std::vector<uint8_t>
>
32
parse_key_value(
std::vector<uint8_t>
kv)
33
{
34
std::map<std::string, std::vector<uint8_t>
> m;
35
36
bool
keyfound =
false
;
37
38
std::string
key;
39
std::vector<uint8_t>
value;
40
uint8_t
prev
=
'\0'
;
41
42
if
(kv.
size
() == 0) {
43
goto
not_valid;
44
}
45
46
for
(uint8_t u8 : kv) {
47
if
(keyfound) {
48
if
((u8 ==
';'
) && (prev !=
';'
)) {
49
prev
= u8;
50
continue
;
51
}
else
if
((u8 !=
';'
) && (prev ==
';'
)) {
52
if
(value.
size
() == 0) {
53
goto
not_valid;
54
}
55
m[key] = value;
56
57
key.
clear
();
58
value.
clear
();
59
keyfound =
false
;
60
}
else
{
61
value.
push_back
(u8);
62
}
63
}
64
if
(!keyfound) {
65
if
(u8 ==
'='
) {
66
if
(key.
size
() == 0) {
67
goto
not_valid;
68
}
69
keyfound =
true
;
70
}
else
if
(
isalnum
(u8)) {
71
key.
push_back
(u8);
72
}
else
if
((u8 ==
'\0'
) && (key.
size
() == 0) && (m.
size
() > 0)) {
73
break
;
// accept trailing '\0' characters
74
}
else
if
((prev !=
';'
) || (key.
size
() > 0)) {
75
goto
not_valid;
76
}
77
}
78
prev
= u8;
79
}
80
if
(keyfound) {
81
if
(value.
size
() == 0) {
82
goto
not_valid;
83
}
84
m[key] = value;
85
}
else
if
(key.
size
() > 0) {
86
goto
not_valid;
87
}
88
return
m;
89
not_valid:
90
// This is not a failure this is something that can happen because the participant_qos userData
91
// is used. Other participants in the system not created by rmw could use userData for something
92
// else.
93
return
std::map<std::string, std::vector<uint8_t>
>();
94
}
95
96
}
// namespace cpp
97
}
// namespace impl
98
}
// namespace rmw
99
100
#endif // RMW__IMPL__CPP__KEY_VALUE_HPP_
std::string
std::vector
std::vector::size
T size(T... args)
std::isalnum
T isalnum(T... args)
std::string::clear
T clear(T... args)
std::vector::push_back
T push_back(T... args)
std::map
std::prev
T prev(T... args)
rmw
Definition:
demangle.hpp:29
Generated by
1.8.17