bt_cout_logger.cpp
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(TreeNode* root_node) : StatusChangeLogger(root_node)
00008 {
00009     bool expected = false;
00010     if (!ref_count.compare_exchange_strong(expected, true))
00011     {
00012         throw std::logic_error("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", since_epoch, node.name().c_str(),
00030            &whitespaces[std::min(ws_count, node.name().size())], toStr(prev_status, true),
00031            toStr(status, true));
00032     std::cout << std::endl;
00033 }
00034 
00035 void StdCoutLogger::flush()
00036 {
00037     std::cout << std::flush;
00038         ref_count = false;
00039 }
00040 
00041 }   // end namespace


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Feb 2 2019 03:50:09