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, NodeStatus prev_status,
21  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",
30  since_epoch, node.name().c_str(),
31  &whitespaces[std::min(ws_count, node.name().size())],
32  toStr(prev_status, true).c_str(),
33  toStr(status, true).c_str() );
34  std::cout << std::endl;
35 }
36 
38 {
39  std::cout << std::flush;
40  ref_count = false;
41 }
42 
43 } // end namespace
const std::string & name() const
Name of the instance, not the type.
Definition: tree_node.cpp:73
std::string toStr(T value)
Definition: basic_types.h:127
static std::atomic< bool > ref_count
Abstract base class for Behavior Tree Nodes.
Definition: tree_node.h:53
StdCoutLogger(const BT::Tree &tree)
static volatile int count
Definition: minitrace.cpp:55
~StdCoutLogger() override
NodeStatus
Definition: basic_types.h:35
virtual void flush() override
Struct used to store a tree. If this object goes out of scope, the tree is destroyed.
Definition: bt_factory.h:78
std::chrono::high_resolution_clock::duration Duration
Definition: basic_types.h:339
virtual void callback(Duration timestamp, const TreeNode &node, NodeStatus prev_status, NodeStatus status) override


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Jun 8 2019 18:04:04