-
Notifications
You must be signed in to change notification settings - Fork 6
/
BFIELD.swift
144 lines (106 loc) · 4.4 KB
/
BFIELD.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
Copyright (c) <2020>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import Foundation
/**
Supertype to all Bintable Types
*/
public protocol BField : FIELD where FORM == BFORM, DISP == BDISP {
subscript(_ index: Int) -> BFIELD.VALUE? { get set }
var all : [BFIELD.VALUE] { get }
}
/// internal representation of 'BField'
protocol _BField: _FIELD {
}
//MARK:- PrefixType
/**
THE TFIELD data structure as specified for the Bintable extensions
The TFORMn keywords must be present for all values n = 1, ..., TFIELDS and for no other values of n. The value field of this indexed keyword shall contain a char- acter string of the form rTa. The repeat count r is the ASCII representation of a non-negative integer specifying the number of elements in Field n. The default value of r is 1; the repeat count need not be present if it has the default value. A zero el- ement count, indicating an empty field, is permitted. The data type T specifies the data type of the contents of Field n. Only the data types in Table 18 are permitted. The format codes must be specified in upper case. For fields of type P or Q, the only per- mitted repeat counts are 0 and 1. The additional characters a are optional and are not further defined in this Standard. Table 18 lists the number of bytes each data type occupies in a table row. The first field of a row is numbered 1.
*/
public class BFIELD: BField, _BField {
public typealias FORM = BFORM
public typealias DISP = BDISP
#if DEBUG
var raw : Data?
#endif
public var description: String {
return "BFIELD"
}
public var debugDescription: String {
return "BFIELD"
}
func write(_ form: BFORM) -> String {
fatalError("Not implemented in BFIELD")
}
func format(_ disp: BDISP?, _ form: BFORM?, _ null: String?) -> String {
fatalError("Not implemented in BFIELD")
}
var form: BFORM {
fatalError("Not implemented in BFIELD")
}
public subscript(index: Int) -> BFIELD.VALUE? {
get {
return nil
}
set {
//
}
}
public var all: [VALUE] {
return []
}
public static func == (lhs: BFIELD, rhs: BFIELD) -> Bool {
return lhs.hashValue == rhs.hashValue
}
public func hash(into hasher: inout Hasher) {
hasher.combine(UUID())
}
}
protocol ValueBField : _BField, WritableBField {
associatedtype ValueType : BFIELD.VALUE
associatedtype BaseType : Any
var name : String {get}
var val : [ValueType]? { get set }
func form(_ disp: BDISP?, _ form: BFORM?, _ null: String?) -> String
var debugDesc : String {get}
var desc : String {get}
}
extension ValueBField {
var debugDesc: String {
return "BFIELD.\(name)(\(val?.description ?? "-/-"))"
}
var desc: String {
return val != nil ? "\(val!)" : "-/-"
}
}
extension ValueBField where Self : _Displayable {
func form(_ disp: BDISP?, _ form: BFORM?, _ null: String?) -> String {
var ret = "["
if (val?.forEach({ value in
ret.append(value.string(disp, form) ?? "")
ret.append(",")
})) != nil {
ret.removeLast()
}
ret.append("]")
return ret
}
}
protocol VarArray : ValueBField, WritableVarBField {
associatedtype ArrayType : FixedWidthInteger
}