AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
script.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/tree/script.hpp"
16
17#include "auto_apms_behavior_tree_core/exceptions.hpp"
18#include "auto_apms_util/string.hpp"
19#include "behaviortree_cpp/scripting/script_parser.hpp"
20
22{
23
24Script::Script(std::vector<std::string> expressions) : expressions_(expressions)
25{
26 if (const BT::Result res = BT::ValidateScript(str()); !res) {
27 throw exceptions::ScriptError(res.error());
28 }
29}
30
31Script::Script(const std::string & str) : Script(std::vector<std::string>({str})) {}
32
33Script::Script(const char * str) : Script(std::string(str)) {}
34
35Script & Script::operator+=(const Script & rhs)
36{
37 for (const std::string & expr : rhs.expressions_) expressions_.push_back(expr);
38 return *this;
39}
40
41std::string Script::str() const { return auto_apms_util::join(expressions_, "; "); }
42
43Script operator+(Script lhs, const Script & rhs)
44{
45 lhs += rhs; // reuse compound assignment
46 return lhs; // return the result by value (uses move constructor)
47}
48
49} // namespace auto_apms_behavior_tree::core
Class that encapsulates behavior tree script expressions.
Definition script.hpp:30
Script()=default
Create an empty script.
std::string str() const
Concatenate all expressions of this instance to a single string.
Definition script.cpp:41
Core API for AutoAPMS's behavior tree implementation.
Definition builder.hpp:30