Пример #1
0
 void StructuredBuffer::getVariableArray(const std::string& name, size_t count, size_t elementIndex, VarType value[])
 {
     size_t offset;
     const auto* pData = mpReflector->getVariableData(name, offset);
     if ((_LOG_ENABLED == 0) || (pData && checkVariableType<VarType>(pData->type, name, mpReflector->getName())))
     {
         getVariableArray(offset, count, elementIndex, value);
     }
 }
shared_ptr<Variable> VirtualMachine::getItemFromVariableArray(string key, vector<int> indexArray)
{

	auto it = getVariableArray(key);

	if (it)
	{
		int index = 0;
		bool isMulti = (it->arraySizes.size() > 1);
		for (size_t i = 0; i < it->arraySizes.size(); i++)
		{
			if (indexArray.at(i) < it->arraySizes.at(i)) {
				if (isMulti) {
					if (i == it->arraySizes.size() - 1) {
						index += indexArray.at(i);
					}
					else {
						int size = 0;
						for (size_t j = i + 1; j < it->arraySizes.size(); j++)
						{
							if (size == 0) {
								size += it->arraySizes.at(j);
							}
							else {
								size *= it->arraySizes.at(j);
							}
						}
						index += (indexArray.at(i)* size);
					}

				}
				else {
					index += (indexArray.at(i));
				}
			}
			else {
				if (isMulti) {
					if (i == it->arraySizes.size() - 1) {
						index += indexArray.at(i);
					}
					else {
						index += (indexArray.at(i)* it->arraySizes.at(i));
					}

				}
				else {
					auto error = make_shared<Error>("index out of bounds", ".md", -1, -1, ErrorType::ERROR);
					ErrorHandler::getInstance()->addError(error);
					triggerRunFailure();
					return nullptr;
				}
			}
		}
		return it->variableArrayDictionary[index];
	}
	else
	{
        auto error = make_shared<Error>("you want to get an item from an array which doesn't exist", ".md", -1, -1, ErrorType::ERROR);
		ErrorHandler::getInstance()->addError(error);

		return nullptr;
	}
    return nullptr;
}