std::unique_ptr parseReadRegister()

in extensions/standard-processors/modbus/ReadModbusFunctions.cpp [128:189]


std::unique_ptr<ReadModbusFunction> parseReadRegister(const RegisterType register_type,
  const uint16_t transaction_id,
  const uint8_t unit_id,
  const std::string_view address_str,
  const std::string_view type_str,
  const std::string_view length_str) {
  auto start_address = utils::string::parseNumber<uint16_t>(address_str);
  if (!start_address) {
    return nullptr;
  }
  uint16_t length = length_str.empty() ? 1 : utils::string::parseNumber<uint16_t>(length_str).value_or(1);

  if (type_str.empty() || type_str == "UINT" || type_str == "WORD") {
    return std::make_unique<ReadRegisters<uint16_t>>(register_type, transaction_id, unit_id, *start_address, length);
  }

  if (type_str == "BOOL") {
    return std::make_unique<ReadRegisters<bool>>(register_type, transaction_id, unit_id, *start_address, length);
  }

  if (type_str == "SINT") {
    return std::make_unique<ReadRegisters<int8_t>>(register_type, transaction_id, unit_id, *start_address, length);
  }

  if (type_str == "USINT" || type_str == "BYTE") {
    return std::make_unique<ReadRegisters<uint8_t>>(register_type, transaction_id, unit_id, *start_address, length);
  }

  if (type_str == "INT") {
    return std::make_unique<ReadRegisters<int16_t>>(register_type, transaction_id, unit_id, *start_address, length);
  }

  if (type_str == "DINT") {
    return std::make_unique<ReadRegisters<int32_t>>(register_type, transaction_id, unit_id, *start_address, length);
  }

  if (type_str == "UDINT" || type_str == "DWORD") {
    return std::make_unique<ReadRegisters<uint32_t>>(register_type, transaction_id, unit_id, *start_address, length);
  }

  if (type_str == "LINT") {
    return std::make_unique<ReadRegisters<int64_t>>(register_type, transaction_id, unit_id, *start_address, length);
  }

  if (type_str == "ULINT" || type_str == "LWORD") {
    return std::make_unique<ReadRegisters<uint64_t>>(register_type, transaction_id, unit_id, *start_address, length);
  }

  if (type_str == "REAL") {
    return std::make_unique<ReadRegisters<float>>(register_type, transaction_id, unit_id, *start_address, length);
  }

  if (type_str == "LREAL") {
    return std::make_unique<ReadRegisters<double>>(register_type, transaction_id, unit_id, *start_address, length);
  }

  if (type_str == "CHAR") {
    return std::make_unique<ReadRegisters<char>>(register_type, transaction_id, unit_id, *start_address, length);
  }

  return nullptr;
}