AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
convert.cpp
1// Copyright 2024 Robin Müller
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// https://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#include "auto_apms_behavior_tree_core/convert.hpp"
16
17#include "auto_apms_util/string.hpp"
18
20namespace BT
21{
22
23template <>
24std::vector<uint8_t> convertFromString<std::vector<uint8_t>>(StringView str)
25{
26 auto parts = BT::splitString(str, ';');
27 std::vector<uint8_t> output;
28 output.reserve(parts.size());
29 for (const StringView & part : parts) {
30 output.push_back(convertFromString<uint8_t>(part));
31 }
32 return output;
33}
34
35template <>
36std::vector<bool> convertFromString<std::vector<bool>>(StringView str)
37{
38 auto parts = BT::splitString(str, ';');
39 std::vector<bool> output;
40 output.reserve(parts.size());
41 for (const StringView & part : parts) {
42 output.push_back(convertFromString<bool>(part));
43 }
44 return output;
45}
46
47template <>
48std::vector<int64_t> convertFromString<std::vector<int64_t>>(StringView str)
49{
50 auto parts = BT::splitString(str, ';');
51 std::vector<int64_t, std::allocator<int64_t>> output;
52 output.reserve(parts.size());
53 for (const StringView & part : parts) {
54 output.push_back(convertFromString<int64_t>(part));
55 }
56 return output;
57}
58
59template <>
60std::string toStr(const std::vector<uint8_t> & value)
61{
62 return auto_apms_util::join(value, ";");
63}
64
65template <>
66std::string toStr<std::vector<bool>>(const std::vector<bool> & value)
67{
68 return auto_apms_util::join(value, ";");
69}
70
71template <>
72std::string toStr<std::vector<int64_t>>(const std::vector<int64_t> & value)
73{
74 return auto_apms_util::join(value, ";");
75}
76
77template <>
78std::string toStr<std::vector<double>>(const std::vector<double> & value)
79{
80 return auto_apms_util::join(value, ";");
81}
82
83template <>
84std::string toStr<std::vector<std::string>>(const std::vector<std::string> & value)
85{
86 return auto_apms_util::join(value, ";");
87}
88
89} // namespace BT
const char * toStr(const ActionNodeErrorCode &err)
Convert the action error code to string.