blackboard.cpp
Go to the documentation of this file.
2 
3 namespace BT{
4 
5 void Blackboard::setPortInfo(std::string key, const PortInfo& info)
6 {
7  std::unique_lock<std::mutex> lock(mutex_);
8 
9  if( auto parent = parent_bb_.lock())
10  {
11  auto remapping_it = internal_to_external_.find(key);
12  if( remapping_it != internal_to_external_.end())
13  {
14  parent->setPortInfo( remapping_it->second, info );
15  }
16  }
17 
18  auto it = storage_.find(key);
19  if( it == storage_.end() )
20  {
21  storage_.insert( { std::move(key), Entry(info) } );
22  }
23  else{
24  auto old_type = it->second.port_info.type();
25  if( old_type && old_type != info.type() )
26  {
27  throw LogicError( "Blackboard::set() failed: once declared, the type of a port shall not change. "
28  "Declared type [", BT::demangle( old_type ),
29  "] != current type [", BT::demangle( info.type() ), "]" );
30  }
31  }
32 }
33 
34 const PortInfo* Blackboard::portInfo(const std::string &key)
35 {
36  std::unique_lock<std::mutex> lock(mutex_);
37  auto it = storage_.find(key);
38  if( it == storage_.end() )
39  {
40  return nullptr;
41  }
42  return &(it->second.port_info);
43 }
44 
45 void Blackboard::addSubtreeRemapping(std::string internal, std::string external)
46 {
47  internal_to_external_.insert( {std::move(internal), std::move(external)} );
48 }
49 
51 {
52  for(const auto& entry_it: storage_)
53  {
54  auto port_type = entry_it.second.port_info.type();
55  if( !port_type )
56  {
57  port_type = &( entry_it.second.value.type() );
58  }
59 
60  std::cout << entry_it.first << " (" << demangle( port_type ) << ") -> ";
61 
62  if( auto parent = parent_bb_.lock())
63  {
64  auto remapping_it = internal_to_external_.find( entry_it.first );
65  if( remapping_it != internal_to_external_.end())
66  {
67  std::cout << "remapped to parent [" << remapping_it->second << "]" <<std::endl;
68  continue;
69  }
70  }
71  std::cout << ((entry_it.second.value.empty()) ? "empty" : "full") << std::endl;
72  }
73 }
74 
75 }
void debugMessage() const
Definition: blackboard.cpp:50
const PortInfo * portInfo(const std::string &key)
Definition: blackboard.cpp:34
const std::type_info * type() const
std::string demangle(char const *name)
Definition: demangle_util.h:78
std::weak_ptr< Blackboard > parent_bb_
Definition: blackboard.h:208
void addSubtreeRemapping(std::string internal, std::string external)
Definition: blackboard.cpp:45
std::mutex mutex_
Definition: blackboard.h:206
std::unordered_map< std::string, Entry > storage_
Definition: blackboard.h:207
void setPortInfo(std::string key, const PortInfo &info)
Definition: blackboard.cpp:5
std::unordered_map< std::string, std::string > internal_to_external_
Definition: blackboard.h:209


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