protected fun constructAccessors()

in code/4diac-integration/src/main/kotlin/org/fbme/ide/integration/fordiac/translator/cpp/AbstractTranslator.kt [472:522]


    protected fun constructAccessors(
        parameters: Iterable<ParameterDeclaration>,
        functionName: String,
        indent: String
    ): String {
        val sb = StringBuilder()

        parameters.forEachIndexed { index, param ->
            val isArray = param.type is ArrayType
            val typeName = param.type!!.stringify()

            sb.append(indent)
                .append("CIEC_")
                .append(typeName)
                .append(" ")
                .append(
                    if (isArray) {
                        "*"
                    } else {
                        "&"
                    }
                )
                .append(EXPORT_PREFIX)
                .append(param.name)
                .appendLine("() {")
                .append(indent)

            if (isArray) {
                sb.append("  return static_cast<CIEC_")
                    .append(typeName)
                    .append("*>((*static_cast<CIEC_ARRAY *>(")
                    .append(functionName)
                    .append("(")
                    .append(index)
                    .appendLine(")))[0]); //the first element marks the start of the array")
            } else {
                sb.append("  return *static_cast<CIEC_")
                    .append(typeName)
                    .append("*>(")
                    .append(functionName)
                    .append("(")
                    .append(index)
                    .appendLine("));")
            }

            sb.append(indent)
                .appendLine("}")
        }

        return sb.toString()
    }