convert enum to enum class and provide to_string
This commit is contained in:
parent
249b7d80d8
commit
0c826497f1
2 changed files with 33 additions and 1 deletions
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
|
@ -42,7 +43,13 @@ namespace executor
|
|||
* INTERRUPTED: The future is not complete, spinning was interrupted by Ctrl-C or another error.
|
||||
* TIMEOUT: Spinning timed out.
|
||||
*/
|
||||
enum FutureReturnCode {SUCCESS, INTERRUPTED, TIMEOUT};
|
||||
enum class FutureReturnCode {SUCCESS, INTERRUPTED, TIMEOUT};
|
||||
|
||||
std::ostream &
|
||||
operator << (std::ostream & os, const FutureReturnCode & future_return_code);
|
||||
|
||||
std::string
|
||||
to_string(const FutureReturnCode & future_return_code);
|
||||
|
||||
///
|
||||
/**
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "rclcpp/executor.hpp"
|
||||
#include "rclcpp/scope_exit.hpp"
|
||||
|
||||
|
@ -20,6 +22,7 @@
|
|||
using rclcpp::executor::AnyExecutable;
|
||||
using rclcpp::executor::Executor;
|
||||
using rclcpp::executor::ExecutorArgs;
|
||||
using rclcpp::executor::FutureReturnCode;
|
||||
|
||||
Executor::Executor(const ExecutorArgs & args)
|
||||
: spinning(false),
|
||||
|
@ -569,3 +572,25 @@ Executor::get_next_executable(std::chrono::nanoseconds timeout)
|
|||
}
|
||||
return any_exec;
|
||||
}
|
||||
|
||||
std::ostream &
|
||||
rclcpp::executor::operator << (std::ostream & os, const FutureReturnCode & future_return_code)
|
||||
{
|
||||
return os << to_string(future_return_code);
|
||||
}
|
||||
|
||||
std::string
|
||||
rclcpp::executor::to_string(const FutureReturnCode & future_return_code)
|
||||
{
|
||||
using enum_type = std::underlying_type<FutureReturnCode>::type;
|
||||
using std::string;
|
||||
using std::to_string;
|
||||
switch (future_return_code) {
|
||||
case FutureReturnCode::SUCCESS:
|
||||
return string("SUCCESS (" + to_string(static_cast<enum_type>(future_return_code)) + ")");
|
||||
case FutureReturnCode::INTERRUPTED:
|
||||
return string("INTERRUPTED (" + to_string(static_cast<enum_type>(future_return_code)) + ")");
|
||||
case FutureReturnCode::TIMEOUT:
|
||||
return string("TIMEOUT (" + to_string(static_cast<enum_type>(future_return_code)) + ")");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue