/*! * \brief Return a handle to the value of the Nth argument of the primitive. * \param inIndex Index of the actual primitive in the primitive tree. * \param inN Number of the argument to get the index. * \param ioContext A reference to the execution context. * \return A handle to the value of the Nth argument of the primitive. */ AnyType::Handle Primitive::getArgument(unsigned int inIndex, unsigned int inN, ExecutionContext& ioContext) const { schnaps_StackTraceBeginM(); unsigned int lNodeIndex = getArgumentIndex(inIndex, inN, ioContext); AnyType::Handle outResult = ioContext.getPrimitiveTree()[lNodeIndex].mPrimitive->execute(lNodeIndex, ioContext); return outResult; schnaps_StackTraceEndM("AnyType::Handle Primitive::getArgument(unsigned int, unsigned int, SCHNAPS::Core::ExecutionContext&) const"); }
/*! * \brief Return the index of the Nth argument of the primitive. * \param inIndex Index of the actual primitive in the primitive tree. * \param inN Number of the argument to get the index. * \param ioContext A reference to the execution context. * \return The index of the Nth argument of the primitive. * \throw SCHNAPS::Core::AssertException if the argument number is out of bounds. */ unsigned int Primitive::getArgumentIndex(unsigned int inIndex, unsigned int inN, ExecutionContext& ioContext) const { schnaps_StackTraceBeginM(); schnaps_UpperBoundCheckAssertM(inN, mNumberArguments-1); const PrimitiveTree& lActualTree = ioContext.getPrimitiveTree(); unsigned int lNodeIndex = inIndex + 1; for (unsigned int i = 0; i < inN; i++) { lNodeIndex += lActualTree[lNodeIndex].mSubTreeSize; } return lNodeIndex; schnaps_StackTraceEndM("unsigned int SCHNAPS::Core::Primitive::getArgumentIndex(unsigned int, unsigned int, SCHNAPS::Core::ExecutionContext&) const"); }
/*! * \brief Validate primitive and children recursively. * \param inIndex Index of the current primitive. * \param ioContext A reference to the execution context. * \return True if valid, false if not. */ bool Primitive::isValid(unsigned int inIndex, ExecutionContext& ioContext) const { schnaps_StackTraceBeginM(); std::string lArgReturn, lArgType; unsigned int lArgIndex; for (unsigned int i = 0; i < mNumberArguments; i++) { lArgType = getArgType(inIndex, i, ioContext); lArgIndex = getArgumentIndex(inIndex, i, ioContext); lArgReturn = ioContext.getPrimitiveTree()[lArgIndex].mPrimitive->getReturnType(inIndex, ioContext); if ((lArgType != lArgReturn) && (!ioContext.getSystem().getTypingManager().typeCast(lArgReturn, lArgType))) { return false; } } return true; schnaps_StackTraceEndM("bool SCHNAPS::Core::Primitive::isValid(unsigned int, SCHNAPS::Core::ExecutionContext&) const"); }