blackboard.cpp
Go to the documentation of this file.
00001 #include "behaviortree_cpp/blackboard.h"
00002 
00003 namespace BT{
00004 
00005 void Blackboard::setPortInfo(std::string key, const PortInfo& info)
00006 {
00007     std::unique_lock<std::mutex> lock(mutex_);
00008 
00009     if( auto parent = parent_bb_.lock())
00010     {
00011         auto remapping_it = internal_to_external_.find(key);
00012         if( remapping_it != internal_to_external_.end())
00013         {
00014             parent->setPortInfo( remapping_it->second, info );
00015         }
00016     }
00017 
00018     auto it = storage_.find(key);
00019     if( it == storage_.end() )
00020     {
00021         storage_.insert( { std::move(key), Entry(info) } );
00022     }
00023     else{
00024         auto old_type = it->second.port_info.type();
00025         if( old_type && old_type != info.type() )
00026         {
00027             throw LogicError( "Blackboard::set() failed: once declared, the type of a port shall not change. "
00028                              "Declared type [",     BT::demangle( old_type ),
00029                              "] != current type [", BT::demangle( info.type() ), "]" );
00030         }
00031     }
00032 }
00033 
00034 const PortInfo* Blackboard::portInfo(const std::string &key)
00035 {
00036     std::unique_lock<std::mutex> lock(mutex_);
00037     auto it = storage_.find(key);
00038     if( it == storage_.end() )
00039     {
00040         return nullptr;
00041     }
00042     return &(it->second.port_info);
00043 }
00044 
00045 void Blackboard::addSubtreeRemapping(std::string internal, std::string external)
00046 {
00047     internal_to_external_.insert( {std::move(internal), std::move(external)} );
00048 }
00049 
00050 void Blackboard::debugMessage() const
00051 {
00052     for(const auto& entry_it: storage_)
00053     {
00054         auto port_type = entry_it.second.port_info.type();
00055         if( !port_type )
00056         {
00057             port_type = &( entry_it.second.value.type() );
00058         }
00059 
00060         std::cout <<  entry_it.first << " (" << demangle( port_type ) << ") -> ";
00061 
00062         if( auto parent = parent_bb_.lock())
00063         {
00064             auto remapping_it = internal_to_external_.find( entry_it.first );
00065             if( remapping_it != internal_to_external_.end())
00066             {
00067                 std::cout << "remapped to parent [" << remapping_it->second << "]" <<std::endl;
00068                 continue;
00069             }
00070         }
00071         std::cout << ((entry_it.second.value.empty()) ? "empty" : "full") <<  std::endl;
00072     }
00073 }
00074 
00075 }


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Jun 8 2019 20:17:15