-
Notifications
You must be signed in to change notification settings - Fork 5
/
codePair.go
159 lines (132 loc) · 3.77 KB
/
codePair.go
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package dxf
import (
"fmt"
)
// CodePair represents a code and value pair from a DXF drawing.
type CodePair struct {
Code int
Value CodePairValue
}
func (pair *CodePair) String() string {
return fmt.Sprintf("%d/%s", pair.Code, pair.Value)
}
func (pair *CodePair) isStartSection() bool {
return pair.Code == 0 && pair.Value.(StringCodePairValue).Value == "SECTION"
}
func (pair *CodePair) isEndSection() bool {
return pair.Code == 0 && pair.Value.(StringCodePairValue).Value == "ENDSEC"
}
func (pair *CodePair) isStartTable() bool {
return pair.Code == 0 && pair.Value.(StringCodePairValue).Value == "TABLE"
}
func (pair *CodePair) isEndTable() bool {
return pair.Code == 0 && pair.Value.(StringCodePairValue).Value == "ENDTAB"
}
func (pair *CodePair) isEOF() bool {
return pair.Code == 0 && pair.Value.(StringCodePairValue).Value == "EOF"
}
// NewBoolCodePair creates a code pair representing a boolean value.
func NewBoolCodePair(code int, value bool) CodePair {
return CodePair{
Code: code,
Value: NewBoolCodePairValue(value),
}
}
// NewDoubleCodePair creates a code pair representing a floating point value.
func NewDoubleCodePair(code int, value float64) CodePair {
return CodePair{
Code: code,
Value: NewDoubleCodePairValue(value),
}
}
// NewIntCodePair creates a code pair representing an integer value.
func NewIntCodePair(code int, value int) CodePair {
return CodePair{
Code: code,
Value: NewIntCodePairValue(value),
}
}
// NewLongCodePair creates a code pair representing a long integer value.
func NewLongCodePair(code int, value int64) CodePair {
return CodePair{
Code: code,
Value: NewLongCodePairValue(value),
}
}
// NewShortCodePair creates a code pair representing a short integer value.
func NewShortCodePair(code int, value int16) CodePair {
return CodePair{
Code: code,
Value: NewShortCodePairValue(value),
}
}
// NewStringCodePair creates a code pair representing a string value.
func NewStringCodePair(code int, value string) CodePair {
return CodePair{
Code: code,
Value: NewStringCodePairValue(value),
}
}
// CodePairValue represents a value in a single code pair.
type CodePairValue interface {
}
// BoolCodePairValue represents a boolean code pair value.
type BoolCodePairValue struct {
Value bool
}
// NewBoolCodePairValue creates a boolean code pair value.
func NewBoolCodePairValue(value bool) CodePairValue {
return BoolCodePairValue{
Value: value,
}
}
// DoubleCodePairValue represents a floating point code pair value.
type DoubleCodePairValue struct {
Value float64
}
// NewDoubleCodePairValue creates a floating point code pair value.
func NewDoubleCodePairValue(value float64) CodePairValue {
return DoubleCodePairValue{
Value: value,
}
}
// IntCodePairValue represents an integer code pair value.
type IntCodePairValue struct {
Value int
}
// NewIntCodePairValue creates an integer code pair value.
func NewIntCodePairValue(value int) CodePairValue {
return IntCodePairValue{
Value: value,
}
}
// LongCodePairValue represents a long integer code pair value.
type LongCodePairValue struct {
Value int64
}
// NewLongCodePairValue creates a long integer code pair value.
func NewLongCodePairValue(value int64) CodePairValue {
return LongCodePairValue{
Value: value,
}
}
// ShortCodePairValue represents a short integer code pair value.
type ShortCodePairValue struct {
Value int16
}
// NewShortCodePairValue creates a short integer code pair value.
func NewShortCodePairValue(value int16) CodePairValue {
return ShortCodePairValue{
Value: value,
}
}
// StringCodePairValue represents a string code pair value.
type StringCodePairValue struct {
Value string
}
// NewStringCodePairValue creates a string code pair value.
func NewStringCodePairValue(value string) CodePairValue {
return StringCodePairValue{
Value: value,
}
}