![]() |
Botcraft 1.21.4
|
A map wrapper to store arbitrary data. More...
#include <Blackboard.hpp>
Public Member Functions | |
Blackboard () | |
~Blackboard () | |
template<class T > | |
const T & | Get (const std::string &key) |
Get the map value at key, casting it to T. | |
template<class T > | |
const T & | Get (const std::string &key, const T &default_value) |
Get the map value at key, casting it to T. | |
template<class T > | |
NotifyOnEndUseRef< T > | GetRef (const std::string &key) |
Get a ref to the map value at key, casting it to T&. | |
template<class T > | |
NotifyOnEndUseRef< T > | GetRef (const std::string &key, const T &default_value) |
Get a ref to the map value at key, casting it to T&. | |
template<class T > | |
void | Set (const std::string &key, const T &value) |
Set map entry at key to value. | |
void | Copy (const std::string &src, const std::string &dst) |
Copy a blackboard value. | |
void | Erase (const std::string &key) |
Remove a map entry if present. | |
void | Reset (const std::map< std::string, std::any > &values={}) |
Clear all the entries in the blackboard and load new ones. | |
void | Subscribe (BlackboardObserver *observer) |
void | Unsubscribe (BlackboardObserver *observer) |
Private Member Functions | |
void | NotifyCleared () const |
void | NotifyKeyRemoved (const std::string &key) const |
void | NotifyKeyChanged (const std::string &key, const std::any &value) const |
Private Attributes | |
std::map< std::string, std::any > | blackboard |
std::vector< BlackboardObserver * > | observers |
A map wrapper to store arbitrary data.
Definition at line 46 of file Blackboard.hpp.
Botcraft::Blackboard::Blackboard | ( | ) |
Definition at line 5 of file Blackboard.cpp.
Botcraft::Blackboard::~Blackboard | ( | ) |
Definition at line 10 of file Blackboard.cpp.
void Botcraft::Blackboard::Copy | ( | const std::string & | src, |
const std::string & | dst | ||
) |
Copy a blackboard value.
src | Source key, must exist in the blackboard |
dst | Destination key |
Definition at line 15 of file Blackboard.cpp.
References blackboard, and NotifyKeyChanged().
Referenced by Botcraft::CopyBlackboardDataImpl().
void Botcraft::Blackboard::Erase | ( | const std::string & | key | ) |
Remove a map entry if present.
key | key we want to remove |
Definition at line 22 of file Blackboard.cpp.
References blackboard, and NotifyKeyRemoved().
Referenced by Botcraft::RemoveBlackboardDataImpl().
|
inline |
Get the map value at key, casting it to T.
The map has to contains key and it has to be a T.
T | Any type, must match the type stored at key |
key | key to retrieve the value from |
Definition at line 58 of file Blackboard.hpp.
Referenced by Botcraft::CheckBlackboardBoolDataBlackboard(), Botcraft::CheckBlackboardBoolDataImpl(), Botcraft::ClickSlotInContainerBlackboard(), Botcraft::CloseContainerBlackboard(), Botcraft::CopyBlackboardDataBlackboard(), Botcraft::CraftBlackboard(), Botcraft::CraftNamedBlackboard(), Botcraft::DigBlackboard(), Botcraft::DropItemsFromContainerBlackboard(), Botcraft::EatBlackboard(), Botcraft::GoToBlackboard(), Botcraft::GoToDoubleBlackboard(), Botcraft::HasItemIdInInventoryBlackboard(), Botcraft::HasItemInInventoryBlackboard(), Botcraft::InteractEntityBlackboard(), Botcraft::InteractWithBlockBlackboard(), Botcraft::IsHungryBlackboard(), Botcraft::LogInventoryContentBlackboard(), Botcraft::LookAtBlackboard(), Botcraft::OpenContainerBlackboard(), Botcraft::PlaceBlockBlackboard(), Botcraft::PutOneItemInContainerSlotBlackboard(), Botcraft::RemoveBlackboardDataBlackboard(), Botcraft::SayBlackboard(), Botcraft::SetBlackboardDataBlackboard(), Botcraft::SetItemIdInHandBlackboard(), Botcraft::SetItemInHandBlackboard(), Botcraft::SwapItemsInContainerBlackboard(), Botcraft::TradeBlackboard(), and Botcraft::TradeNameBlackboard().
|
inline |
Get the map value at key, casting it to T.
If the key is not present in the map, add it with default_value, and returns it.
T | Any type, must match the type stored at key |
key | key to retrieve the value from |
default_value | The default value to return if key is not found |
Definition at line 78 of file Blackboard.hpp.
|
inline |
Get a ref to the map value at key, casting it to T&.
key must exist in the blackboard. Usage example:
T | Any type, must match the type stored at key |
key | key to retrieve the value from |
Definition at line 102 of file Blackboard.hpp.
|
inline |
Get a ref to the map value at key, casting it to T&.
If the key is not present in the map, add it with default_value, and returns it. Usage example:
T | Any type, must match the type stored at key |
key | key to retrieve the value from |
default_value | The default value to return if key is not found |
Definition at line 129 of file Blackboard.hpp.
|
private |
|
private |
Definition at line 81 of file Blackboard.cpp.
References observers.
|
private |
void Botcraft::Blackboard::Reset | ( | const std::map< std::string, std::any > & | values = {} | ) |
Clear all the entries in the blackboard and load new ones.
values | Values to load into the blackboard after clearing |
Definition at line 28 of file Blackboard.cpp.
References blackboard, NotifyCleared(), and NotifyKeyChanged().
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::TreeLoop().
|
inline |
Set map entry at key to value.
T | Any type, be careful to be explicit with strings because "foo" is not a std::string but a C-style char* |
key | key to store the value at |
value | value to store at key |
Definition at line 144 of file Blackboard.hpp.
Referenced by Botcraft::CheckBlackboardBoolData(), Botcraft::ClickSlotInContainer(), Botcraft::CloseContainer(), Botcraft::CopyBlackboardData(), Botcraft::Craft(), Botcraft::CraftNamed(), Botcraft::Dig(), Botcraft::DropItemsFromContainer(), Botcraft::Eat(), Botcraft::GoTo(), Botcraft::GoToDouble(), Botcraft::HasItemIdInInventory(), Botcraft::HasItemInInventory(), Botcraft::InteractEntity(), Botcraft::InteractWithBlock(), Botcraft::IsHungry(), Botcraft::LogInventoryContent(), Botcraft::LookAt(), Botcraft::OpenContainer(), Botcraft::PlaceBlock(), Botcraft::PutOneItemInContainerSlot(), Botcraft::RemoveBlackboardData(), Botcraft::Say(), Botcraft::SetBlackboardData(), Botcraft::Internal::SetBlackboardDataImpl(), Botcraft::SetItemIdInHand(), Botcraft::SetItemInHand(), Botcraft::SwapItemsInContainer(), Botcraft::Trade(), and Botcraft::TradeName().
void Botcraft::Blackboard::Subscribe | ( | BlackboardObserver * | observer | ) |
Definition at line 39 of file Blackboard.cpp.
References observers.
Referenced by Botcraft::BehaviourClient::BehaviourClient().
void Botcraft::Blackboard::Unsubscribe | ( | BlackboardObserver * | observer | ) |
Definition at line 44 of file Blackboard.cpp.
References observers.
Referenced by Botcraft::BehaviourClient::~BehaviourClient().
|
private |
Definition at line 173 of file Blackboard.hpp.
|
private |
Definition at line 174 of file Blackboard.hpp.
Referenced by NotifyCleared(), NotifyKeyChanged(), NotifyKeyRemoved(), Subscribe(), and Unsubscribe().