@@ -1409,25 +1409,120 @@ func createSwiftShard<T: IShard>(_: T.Type) -> UnsafeMutablePointer<Shard>? {
1409
1409
return UnsafeMutableRawPointer ( cwrapper) . assumingMemoryBound ( to: Shard . self)
1410
1410
}
1411
1411
1412
- class ParameterInfo {
1413
- init ( name: String , types: SHTypesInfo , index: Int ) {
1414
- self . name = name
1415
- help = " "
1412
+ class TypeInfo {
1413
+ var native = SHTypeInfo ( )
1414
+
1415
+ init ( type: VarType ) {
1416
+ native. basicType = type. asSHType ( )
1417
+ }
1418
+ }
1419
+
1420
+ class Types {
1421
+ var types : [ TypeInfo ] // to keep alive
1422
+ var typesStorage : [ SHTypeInfo ] = [ ]
1423
+
1424
+ init ( types: [ TypeInfo ] ) {
1416
1425
self . types = types
1417
- self . index = index
1426
+ for t in types {
1427
+ typesStorage. append ( t. native)
1428
+ }
1418
1429
}
1419
1430
1420
- init ( name: String , help: String , types: SHTypesInfo , index: Int ) {
1421
- self . name = name
1422
- self . help = help
1431
+ func get( ) -> [ SHTypeInfo ] {
1432
+ typesStorage
1433
+ }
1434
+ }
1435
+
1436
+ class ParameterInfo {
1437
+ var name : ContiguousArray < CChar >
1438
+ var help : ContiguousArray < CChar >
1439
+ var types : [ TypeInfo ] // to keep alive
1440
+ var typesStorage : ContiguousArray < SHTypeInfo > = [ ]
1441
+
1442
+ init ( name: String , help: String , types: [ TypeInfo ] ) {
1443
+ self . name = name. utf8CString
1444
+ self . help = help. utf8CString
1423
1445
self . types = types
1424
- self . index = index
1446
+ for t in types {
1447
+ typesStorage. append ( t. native)
1448
+ }
1425
1449
}
1426
1450
1427
- var name : String
1428
- var help : String
1429
- var types : SHTypesInfo
1430
- var index : Int
1451
+ func toSHParameterInfo( ) -> SHParameterInfo {
1452
+ var result = SHParameterInfo ( )
1453
+
1454
+ name. withUnsafeBufferPointer {
1455
+ result. name = $0. baseAddress
1456
+ }
1457
+ help. withUnsafeBufferPointer {
1458
+ result. help = SHOptionalString ( string: $0. baseAddress, crc: 0 )
1459
+ }
1460
+ withUnsafeMutablePointer ( to: & typesStorage[ 0 ] ) { ptr in
1461
+ result. valueTypes. elements = ptr
1462
+ }
1463
+ result. valueTypes. len = UInt32 ( types. count)
1464
+ result. valueTypes. cap = 0
1465
+
1466
+ return result
1467
+ }
1468
+ }
1469
+
1470
+ class Parameters {
1471
+ // pod C type, so contiguous array is not needed anyway, this is compatible with the IShard interface
1472
+ private var storage : [ SHParameterInfo ] = [ ]
1473
+ private var infos : [ ParameterInfo ] = [ ] // to keep alive
1474
+
1475
+ func add( name: String , help: String , types: [ TypeInfo ] ) {
1476
+ let info = ParameterInfo ( name: name, help: help, types: types)
1477
+ storage. append ( info. toSHParameterInfo ( ) )
1478
+ infos. append ( info)
1479
+ }
1480
+
1481
+ func get( ) -> [ SHParameterInfo ] {
1482
+ storage
1483
+ }
1484
+ }
1485
+
1486
+ class ExposedTypeInfo {
1487
+ var name : ContiguousArray < CChar >
1488
+ var help : ContiguousArray < CChar >
1489
+ var exposedType : TypeInfo
1490
+ var isMutable : Bool
1491
+ var isProtected : Bool
1492
+ var global : Bool
1493
+ var tracked : Bool
1494
+ var declared : Bool
1495
+
1496
+ init ( name: String , help: String , exposedType: TypeInfo , isMutable: Bool = false , isProtected: Bool = false , global: Bool = false , tracked: Bool = false , declared: Bool = false ) {
1497
+ self . name = name. utf8CString
1498
+ self . help = help. utf8CString
1499
+ self . exposedType = exposedType
1500
+ self . isMutable = isMutable
1501
+ self . isProtected = isProtected
1502
+ self . global = global
1503
+ self . tracked = tracked
1504
+ self . declared = declared
1505
+ }
1506
+
1507
+ func toSHExposedTypeInfo( ) -> SHExposedTypeInfo {
1508
+ var result = SHExposedTypeInfo ( )
1509
+
1510
+ name. withUnsafeBufferPointer {
1511
+ result. name = $0. baseAddress
1512
+ }
1513
+ help. withUnsafeBufferPointer {
1514
+ result. help = SHOptionalString ( string: $0. baseAddress, crc: 0 )
1515
+ }
1516
+ result. exposedType = exposedType. native
1517
+
1518
+ result. isMutable = isMutable
1519
+ result. isProtected = isProtected
1520
+ result. global = global
1521
+ result. tracked = tracked
1522
+ result. declared = declared
1523
+
1524
+ return result
1525
+ }
1431
1526
}
1432
1527
1433
1528
class WireController {
0 commit comments