My doubt this: are the values in the blackboard always stored as strings? If so, is there a way to guarantee type safety?
\neg: Image a key:value pair with std:int type and value 3. In another action node, later on in the tree, would I be able to save an std:float into the same key?
\nThank you for your time.
","upvoteCount":1,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"great question!
\nStorage is done with a variant of std::any. if you are unfamiliar with it, I strongly recommend you learn how that works.
\nstd::any implements type erasure (store any type), but preserving the original object AND its type.
NOW, in addition to any, we do:
\nstd::any
would complain if you try to cast uint16_t
to int32_t
, but instead I check if there is any numberical error in the casting, and if there isn't, it is allowed.But wait, there is more.
\nIf you DO KNOW the type of a blackboard entry / port, we will automatically TRY to convert the string to that type.
\nI am assuming you will use the provided getInput
and setOutput
interfaces (as you should).
You can not connect a OutputPort<float>
to InputPort<int>
because they haven't the same type.
If everything works as intended, you should get an exception during the creation of the tree.
\nYou can do, anyway getInput<float>()
of an integer port, if that is not causing numerical cancellation.
-
Hi, From the documentation I learned that the values in the blackboard are type-safe. Further reading I saw this section
My doubt this: are the values in the blackboard always stored as strings? If so, is there a way to guarantee type safety? eg: Image a key:value pair with std:int type and value 3. In another action node, later on in the tree, would I be able to save an std:float into the same key? Thank you for your time. |
Beta Was this translation helpful? Give feedback.
-
great question! BB storageStorage is done with a variant of std::any. if you are unfamiliar with it, I strongly recommend you learn how that works. NOW, in addition to any, we do:
But wait, there is more. If you DO KNOW the type of a blackboard entry / port, we will automatically TRY to convert the string to that type. AnswerI am assuming you will use the provided You can not connect a If everything works as intended, you should get an exception during the creation of the tree. You can do, anyway |
Beta Was this translation helpful? Give feedback.
-
@facontidavide Great, thanks a lot for clearing that up. |
Beta Was this translation helpful? Give feedback.
great question!
BB storage
Storage is done with a variant of std::any. if you are unfamiliar with it, I strongly recommend you learn how that works.
std::any implements type erasure (store any type), but preserving the original object AND its type.
NOW, in addition to any, we do:
std::any
would complain if you try to castuint16_t
toint32_t
, but instead I check if there is any numberical error in the casting, and if there isn't, it is allowed.But wait, there is more.
If you DO KNOW the type of a blackboard entry / port, we will automatically TRY …