bt_cout_logger.cpp
Go to the documentation of this file.
2 
3 namespace BT
4 {
5 std::atomic<bool> StdCoutLogger::ref_count(false);
6 
8 {
9  bool expected = false;
10  if (!ref_count.compare_exchange_strong(expected, true))
11  {
12  throw LogicError("Only one instance of StdCoutLogger shall be created");
13  }
14 }
16 {
17  ref_count.store(false);
18 }
19 
20 void StdCoutLogger::callback(Duration timestamp, const TreeNode& node,
21  NodeStatus prev_status, NodeStatus status)
22 {
23  using namespace std::chrono;
24 
25  constexpr const char* whitespaces = " ";
26  constexpr const size_t ws_count = 25;
27 
28  double since_epoch = duration<double>(timestamp).count();
29  printf("[%.3f]: %s%s %s -> %s", since_epoch, node.name().c_str(),
30  &whitespaces[std::min(ws_count, node.name().size())],
31  toStr(prev_status, true).c_str(), toStr(status, true).c_str());
32  std::cout << std::endl;
33 }
34 
36 {
37  std::cout << std::flush;
38  ref_count = false;
39 }
40 
41 } // namespace BT
BT
Definition: ex01_wrap_legacy.cpp:29
BT::StdCoutLogger::~StdCoutLogger
~StdCoutLogger() override
Definition: bt_cout_logger.cpp:15
BT::StdCoutLogger::flush
virtual void flush() override
Definition: bt_cout_logger.cpp:35
BT::TreeNode
Abstract base class for Behavior Tree Nodes.
Definition: tree_node.h:55
BT::Tree
Struct used to store a tree. If this object goes out of scope, the tree is destroyed.
Definition: bt_factory.h:125
BT::StdCoutLogger::callback
virtual void callback(Duration timestamp, const TreeNode &node, NodeStatus prev_status, NodeStatus status) override
Definition: bt_cout_logger.cpp:20
BT::LogicError
Definition: exceptions.h:45
BT::StatusChangeLogger
Definition: abstract_logger.h:17
BT::toStr
std::string toStr(T value)
Definition: basic_types.h:141
BT::StdCoutLogger::StdCoutLogger
StdCoutLogger(const BT::Tree &tree)
Definition: bt_cout_logger.cpp:7
BT::Duration
std::chrono::high_resolution_clock::duration Duration
Definition: basic_types.h:371
bt_cout_logger.h
BT::TreeNode::name
const std::string & name() const
Name of the instance, not the type.
Definition: tree_node.cpp:101
BT::StdCoutLogger::ref_count
static std::atomic< bool > ref_count
Definition: bt_cout_logger.h:21
BT::NodeStatus
NodeStatus
Definition: basic_types.h:35


behaviortree_cpp_v3
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Wed Jun 26 2024 02:51:19