Skip to content

Commit 6c004d0

Browse files
committed
InputValue: Automatically determine type of value pointer
1 parent d8fe75e commit 6c004d0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/scratch/inputvalue.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#include <scratchcpp/inputvalue.h>
44
#include <scratchcpp/compiler.h>
55
#include <scratchcpp/entity.h>
6+
#include <scratchcpp/broadcast.h>
7+
#include <scratchcpp/variable.h>
8+
#include <scratchcpp/list.h>
69
#include <map>
710

811
#include "inputvalue_p.h"
@@ -105,6 +108,17 @@ std::shared_ptr<Entity> InputValue::valuePtr() const
105108
/*! Sets the value pointer. */
106109
void InputValue::setValuePtr(const std::shared_ptr<Entity> &newValuePtr)
107110
{
111+
if (std::dynamic_pointer_cast<Broadcast>(newValuePtr))
112+
setType(Type::Broadcast);
113+
else if (std::dynamic_pointer_cast<Variable>(newValuePtr))
114+
setType(Type::Variable);
115+
else if (std::dynamic_pointer_cast<List>(newValuePtr))
116+
setType(Type::List);
117+
else {
118+
impl->valuePtr = nullptr;
119+
return;
120+
}
121+
108122
impl->valuePtr = newValuePtr;
109123
}
110124

0 commit comments

Comments
 (0)