Go to the documentation of this file.00001 #include "behaviortree_cpp/loggers/bt_cout_logger.h"
00002
00003 namespace BT
00004 {
00005 std::atomic<bool> StdCoutLogger::ref_count(false);
00006
00007 StdCoutLogger::StdCoutLogger(const BT::Tree& tree) : StatusChangeLogger(tree.root_node)
00008 {
00009 bool expected = false;
00010 if (!ref_count.compare_exchange_strong(expected, true))
00011 {
00012 throw LogicError("Only one instance of StdCoutLogger shall be created");
00013 }
00014 }
00015 StdCoutLogger::~StdCoutLogger()
00016 {
00017 ref_count.store(false);
00018 }
00019
00020 void StdCoutLogger::callback(Duration timestamp, const TreeNode& node, NodeStatus prev_status,
00021 NodeStatus status)
00022 {
00023 using namespace std::chrono;
00024
00025 constexpr const char* whitespaces = " ";
00026 constexpr const size_t ws_count = 25;
00027
00028 double since_epoch = duration<double>(timestamp).count();
00029 printf("[%.3f]: %s%s %s -> %s",
00030 since_epoch, node.name().c_str(),
00031 &whitespaces[std::min(ws_count, node.name().size())],
00032 toStr(prev_status, true).c_str(),
00033 toStr(status, true).c_str() );
00034 std::cout << std::endl;
00035 }
00036
00037 void StdCoutLogger::flush()
00038 {
00039 std::cout << std::flush;
00040 ref_count = false;
00041 }
00042
00043 }