/* file: stripped_typeof.swift 	 generated: Mon Jan  3 16:32:52 2022 */

/* This file was generated by the EXPRESS to Swift translator "exp2swift", 
  derived from STEPcode (formerly NIST's SCL).
 exp2swift version: v.1.0.1, derived from stepcode v0.8 as of 2019/11/23 
 WARNING: You probably don't want to edit it since your modifications 
  will be lost if exp2swift is used to regenerate it.
 */

 
import SwiftSDAIcore

extension AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF {
//MARK: -FUNCTION DEFINITION in EXPRESS
/*

  FUNCTION stripped_typeof(
               arg : GENERIC:g
           ) : SET OF STRING;

    LOCAL
      types  : SET OF STRING := TYPEOF( arg );
      stypes : SET OF STRING := [];
      n      : INTEGER := LENGTH( schema_prefix );
    END_LOCAL;
    REPEAT i := 1 TO SIZEOF( types ) BY 1;
      IF ( LENGTH( types[i] ) > n ) AND ( types[i][1 : n] = schema_prefix ) THEN
        stypes := stypes + [types[i][n + 1 : LENGTH( types[i] )]];
      ELSE
        stypes := stypes + [types[i]];
      END_IF;
    END_REPEAT;
    RETURN( stypes );

  END_FUNCTION; -- stripped_typeof (line:46490 file:ap242ed2_mim_lf_v1.101.TY.exp)

*/

  public static 
  func STRIPPED_TYPEOF<gG: SDAIGenericType>(
    _ ARG: gG? ) -> SDAI.SET<SDAI.STRING>? {

    // CACHE LOOKUP
    let _params = SDAI.ParameterList( ARG )
    if case .available(let _cached_value) = _stripped_typeof__cache.cachedValue(params: _params) {
      return _cached_value as? SDAI.SET<SDAI.STRING>
    }

    var ARG = ARG; SDAI.TOUCH(var: &ARG)

    //LOCAL
    var TYPES: SDAI.SET<SDAI.STRING>?  = SDAI.TYPEOF(ARG); SDAI.TOUCH(var: &TYPES)
    var STYPES: SDAI.SET<SDAI.STRING>?  = SDAI.SET<SDAI.STRING>(SDAI.EMPLY_AGGREGATE); SDAI.TOUCH(var: &STYPES)
    var N: SDAI.INTEGER?  = SDAI.LENGTH(SCHEMA_PREFIX); SDAI.TOUCH(var: &N)
    //END_LOCAL

    if let incrementControl/*SDAI.INTEGER*/ = SDAI.FROM(/*SDAI.INTEGER*/1, TO:/*SDAI.INTEGER*/SDAI.SIZEOF(
      TYPES)) {
      for I in incrementControl {
        
        let _TEMP1 = TYPES?[I]
        let _TEMP2 = SDAI.LENGTH(_TEMP1)
        let _TEMP3 = _TEMP2 > N
        let _TEMP4 = TYPES?[I]
        let _TEMP5 = _TEMP4?[1 ... N]
        let _TEMP6 = _TEMP5 .==. SDAI.FORCE_OPTIONAL(SCHEMA_PREFIX)
        let _TEMP7 = _TEMP3 && _TEMP6
        if SDAI.IS_TRUE( _TEMP7 ) {
          
          let _TEMP8 = TYPES?[I]
          let _TEMP9 = N + SDAI.FORCE_OPTIONAL(SDAI.INTEGER(1))
          let _TEMP10 = TYPES?[I]
          let _TEMP11 = SDAI.LENGTH(_TEMP10)
          let _TEMP12 = _TEMP8?[_TEMP9 ... _TEMP11]
          let _TEMP13 = ([SDAI.AIE(_TEMP12)] as [SDAI.AggregationInitializerElement<SDAI.STRING>])
          let _TEMP14 = STYPES + SDAI.FORCE_OPTIONAL(_TEMP13)
          STYPES = _TEMP14
        }
        else {
          
          let _TEMP15 = TYPES?[I]
          let _TEMP16 = ([SDAI.AIE(_TEMP15)] as [SDAI.AggregationInitializerElement<SDAI.STRING>])
          let _TEMP17 = STYPES + SDAI.FORCE_OPTIONAL(_TEMP16)
          STYPES = _TEMP17
        }
      }
    }
    return _stripped_typeof__cache.updateCache(params: _params, value: STYPES)
  }

}

//MARK: - function result cache
private var _stripped_typeof__cache = SDAI.FunctionResultCache(
  controller: AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF.schemaDefinition)

